コード例 #1
0
        public void SetConstructor <T> (T constructor)
        {
            var ctorDelegate = constructor as Delegate;

            if (ctorDelegate == null)
            {
                throw new ArgumentException("Must be a managed delegate", "constructor");
            }

            // No need to create a proxy
            if (ctorDelegate is JSNative)
            {
                SetConstructor((JSNative)ctorDelegate);
                return;
            }

            AssertNotInitialized();

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

            // Wrap the delegate in a proxy and retain the proxy
            ManagedConstructor = new NativeToManagedProxy(ctorDelegate);
            NativeConstructor  = null;
        }
コード例 #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
        public void SetConstructor(JSNative constructor)
        {
            AssertNotInitialized();

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

            NativeConstructor  = new JSNativePin(constructor);
            ManagedConstructor = null;
        }
コード例 #4
0
        public void Dispose()
        {
            ClassPin.Free();

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

            NativeConstructor  = null;
            ManagedConstructor = null;
        }