Пример #1
0
 public static unsafe JSFunctionPtr DefineFunction(
     JSContextPtr cx,
     JSHandleObject obj,
     string name,
     JSNative call,
     uint nargs, uint attrs
     ) {
     fixed(char *pName = name)
     return(DefineUCFunction(
                cx, obj, (IntPtr)pName, (uint)name.Length, call, nargs, attrs
                ));
 }
Пример #2
0
        /// <summary>
        /// Registers a managed JSNative as a property on the target object.
        /// The JSNative should return true on success and always set a result value.
        /// </summary>
        /// <returns>
        /// A pinning handle for the function that must be retained as long as the function is available to JS.
        /// </returns>
        public unsafe Managed.JSNativePin DefineFunction(
            JSContextPtr context, string name, JSNative call,
            uint nargs = 0, uint attrs = 0
            )
        {
            var wrapped = new Managed.JSNativePin(call);

            JSAPI.DefineFunction(
                context, TransientSelf(), name, wrapped.Target, nargs, attrs
                );
            return(wrapped);
        }
Пример #3
0
        /// <summary>
        /// Registers a managed JSNative as a property on the target object.
        /// The JSNative should return true on success and always set a result value.
        /// </summary>
        /// <param name="autoRetain">If true, the marshalling proxy is automatically retained by the object wrapper.</param>
        /// <returns>
        /// A pinning handle for the function that must be retained as long as the function is available to JS.
        /// </returns>
        public JSNativePin DefineFunction(
            JSContextPtr context, string name, JSNative call,
            uint nargs      = 0, uint attrs = 0,
            bool autoRetain = true
            )
        {
            var result = Pointer.DefineFunction(Context, name, @call, nargs, attrs);

            if (autoRetain)
            {
                Retain(result);
            }
            return(result);
        }
Пример #4
0
        public void SetConstructor(JSNative constructor)
        {
            AssertNotInitialized();

            if (NativeConstructor != null)
            {
                NativeConstructor.Dispose();
            }
            if (ManagedConstructor != null)
            {
                ManagedConstructor.Dispose();
            }

            NativeConstructor  = new JSNativePin(constructor);
            ManagedConstructor = null;
        }
        public NativeToManagedProxy(Delegate managedMethod)
        {
            if (managedMethod == null)
            {
                throw new ArgumentNullException("managedMethod");
            }

            ManagedMethod = managedMethod;

            var invoke = GetType().GetMethod("Invoke", BindingFlags.NonPublic | BindingFlags.Instance);

            WrappedMethod = (JSNative)Delegate.CreateDelegate(typeof(JSNative), this, invoke, true);

            ArgumentInfo  = managedMethod.Method.GetParameters();
            ArgumentCount = (uint)ArgumentInfo.Length;

            ManagedPin = GCHandle.Alloc(ManagedMethod);
            WrappedPin = GCHandle.Alloc(WrappedMethod);
        }
Пример #6
0
 public static extern int InitJSEngine(JSErrorReporter er, CSEntry csEntry, JSNative req, OnObjCollected onObjCollected, JSNative print);
 public JSNativePin(JSNative target)
 {
     Target = target;
     Pin    = GCHandle.Alloc(target);
 }
Пример #8
0
 public static extern int InitJSEngine(JSErrorReporter er, CSEntry csEntry, JSNative req, OnObjCollected onObjCollected);
Пример #9
0
		private static void SetSyntax(JSNative value, XElement child) {
			var syntax = child.Attribute("syntax");
			if (syntax != null) {
				switch (syntax.Value) {
					case "instance": value.CallType = NativeCallType.Instance; break;
					case "static": value.CallType = NativeCallType.Static; break;
				}
			}
		}
Пример #10
0
		private static JSNative CreateJSNative(XElement element) {
			var value = new JSNative();
			foreach (var child in element.Elements()) {
				switch (child.Name.LocalName) {
					case "ignore": value.Ignore = true; break;
					case "opCode": value.OpCode = child.Attribute("value").Value; break;
					case "code":
						value.Code = child.Value;
						SetSyntax(value, child);
						break;
					case "additionalCode": value.AdditionalCode = child.Value; break;
					case "method": {
							var name = child.Attribute("name");
							if (name != null) {
								value.Name = name.Value;
							}
							SetSyntax(value, child);
						}
						break;
				}
			}
			return value;
		}
Пример #11
0
		public void RegisterDotNetNative(MemberInfo member, JSNative attribute) {
			List<MemberInfo> members;

#if VALIDATION
			if (attribute.CallType != NativeCallType.Default && member is MethodBase && ((MethodBase)member).IsVirtual) {
				ThrowHelper.Throw("JSNative::CallType cannot be set for {0} since it is virtual.", member.GetSignature());
			}
#endif

			if (member.DeclaringType.IsGenericTypeDefinition) {
				if (!dotNetNativeMembersForType.TryGetValue(member.DeclaringType, out members)) {
					members = new List<MemberInfo>();
					dotNetNativeMembersForType[member.DeclaringType] = members;
				}
				dotNetNativeMembersForType[member.DeclaringType].Add(member);
			}
			dotNetNatives[member] = attribute;
		}
Пример #12
0
		public void RegisterDotNetNative(Type member, JSNative attribute) {
			dotNetNatives[member] = attribute;
		}
Пример #13
0
		public string Get_native_Value(JSNative Native, MemberInfo member) {
			if (Native.Code != null) return Native.Code;
			switch (member.MemberType) {
				case MemberTypes.Field: {
						var field = (FieldInfo)member;
						if (field.IsStatic && IsNative(member.DeclaringType)) {
							return Get_native_Value(GetNative(member.DeclaringType), member.DeclaringType) + "." + get_native_Part(Native, member);
						} else {
							return get_native_Part(Native, member);
						}
					}
				case MemberTypes.TypeInfo:
				case MemberTypes.NestedType:
					if (member.DeclaringType != null && IsNative(member.DeclaringType)) {
						return Get_native_Value(GetNative(member.DeclaringType), member.DeclaringType) + "." + get_native_Part(Native, member);
					} else {
						return get_native_Part(Native, member);
					}
				case MemberTypes.Constructor:
					if (member.DeclaringType.DeclaringType != null && IsNative(member.DeclaringType.DeclaringType)) {
						return Get_native_Value(GetNative(member.DeclaringType.DeclaringMethod), member.DeclaringType.DeclaringMethod) + "." + get_native_Part(Native, member);
					} else {
						return get_native_Part(Native, member.DeclaringType);
					}
				case MemberTypes.Method: return get_native_Part(Native, member);
				default: throw new Exception(member.MemberType + "??");
			}

		}
Пример #14
0
		private static string get_native_Part(JSNative Native, MemberInfo member) {
			if (Native.Name != null) return Native.Name;
			if (Native.Code != null) throw new Exception(Native.Code + " != null");
			switch (member.MemberType) {
				case MemberTypes.NestedType:
				case MemberTypes.TypeInfo:
					return member.Name;
				default: return GetNativeName(member.Name);
			}
		}