Exemple #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;
        }
        /// <summary>
        /// Registers a managed function as a property on the target object.
        /// The managed function is wrapped automatically by a marshalling proxy.
        /// </summary>
        /// <returns>
        /// The function's marshalling proxy that must be retained as long as the function is available to JS.
        /// </returns>
        public Managed.NativeToManagedProxy DefineFunction(
            JSContextPtr context, string name, Delegate @delegate, uint attrs = 0
            )
        {
            var wrapped = new Managed.NativeToManagedProxy(@delegate);

            JSAPI.DefineFunction(
                context, TransientSelf(), name, wrapped.WrappedMethod, wrapped.ArgumentCount, attrs
                );
            return(wrapped);
        }
Exemple #3
0
        public void SetConstructor(JSNative constructor)
        {
            AssertNotInitialized();

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

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

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

            NativeConstructor  = null;
            ManagedConstructor = null;
        }