Beispiel #1
0
        internal void _Initialize(V8Engine v8EngineProxy, NativeFunctionTemplateProxy *nativeFunctionTemplateProxy)
        {
            if (v8EngineProxy == null)
            {
                throw new ArgumentNullException("v8EngineProxy");
            }

            if (nativeFunctionTemplateProxy == null)
            {
                throw new ArgumentNullException("nativeFunctionTemplateProxy");
            }

            _Engine = v8EngineProxy;

            _NativeFunctionTemplateProxy = nativeFunctionTemplateProxy;

            InstanceTemplate        = new ObjectTemplate();
            InstanceTemplate.Parent = this;
            InstanceTemplate._Initialize(_Engine, V8NetProxy.GetFunctionInstanceTemplateProxy(_NativeFunctionTemplateProxy), false);

            PrototypeTemplate        = new ObjectTemplate();
            PrototypeTemplate.Parent = this;
            PrototypeTemplate._Initialize(_Engine, V8NetProxy.GetFunctionPrototypeTemplateProxy(_NativeFunctionTemplateProxy), false);

            OnInitialized();
        }
        public override void Dispose()
        {
            if (_NativeFunctionTemplateProxy != null && CanDispose)
            {
                V8NetProxy.DeleteFunctionTemplateProxy(_NativeFunctionTemplateProxy); // (delete the corresponding native object as well; WARNING: This is done on the GC thread!)
                _NativeFunctionTemplateProxy = null;

                PrototypeTemplate.Parent = null;
                InstanceTemplate.Parent  = null;
                PrototypeTemplate        = null;
                InstanceTemplate         = null;
            }
        }
Beispiel #3
0
        public void Dispose()
        {
            if (_NativeFunctionTemplateProxy != null)
            {
                V8NetProxy.DeleteFunctionTemplateProxy(_NativeFunctionTemplateProxy); // (delete the corresponding native object as well; WARNING: This is done on the GC thread!)
                _NativeFunctionTemplateProxy = null;

                PrototypeTemplate.Parent = null;
                InstanceTemplate.Parent  = null;
                PrototypeTemplate        = null;
                InstanceTemplate         = null;
            }

            ((IFinalizable)this).CanFinalize = true;
        }
Beispiel #4
0
        protected override bool _Finalize(bool finalizer) // (note: This can cause issues if removed while the native object exists [because of the callbacks].)
        {
            if (_NativeFunctionTemplateProxy != null)
            {
                if (V8NetProxy.DeleteFunctionTemplateProxy(_NativeFunctionTemplateProxy)) // (delete the corresponding native object as well; WARNING: This is done on the GC thread!)
                {
                    _NativeFunctionTemplateProxy = null;

                    PrototypeTemplate.Parent = null;
                    InstanceTemplate.Parent  = null;
                    PrototypeTemplate        = null;
                    InstanceTemplate         = null;
                }
                else
                {
                    return(false); // (bounced, a script might be in progress; try again later)
                }
            }
            return(true);
        }
Beispiel #5
0
 public static unsafe extern void SetFunctionTemplateProperty(NativeFunctionTemplateProxy *proxy, string name, HandleProxy *value, V8PropertyAttributes attributes = V8PropertyAttributes.None);
Beispiel #6
0
 public static unsafe extern HandleProxy *CreateFunctionInstance(NativeFunctionTemplateProxy *functionTemplateProxy, Int32 objID, Int32 argCount = 0, HandleProxy **args = null);
Beispiel #7
0
 public static unsafe extern HandleProxy *GetFunction(NativeFunctionTemplateProxy *functionTemplateProxy);
Beispiel #8
0
 public static unsafe extern void *GetFunctionPrototypeTemplateProxy(NativeFunctionTemplateProxy *functionTemplateProxy);
Beispiel #9
0
 public static unsafe extern NativeObjectTemplateProxy *GetFunctionInstanceTemplateProxy(NativeFunctionTemplateProxy *functionTemplateProxy);
Beispiel #10
0
 public static extern unsafe void DeleteFunctionTemplateProxy(NativeFunctionTemplateProxy *functionTemplateProxy);
        /// <summary>
        /// If there's any marshalling incompatibility, this will throw an exception.
        /// </summary>
        public void RunMarshallingTests()
        {
            HandleProxy *                hp    = V8NetProxy.CreateHandleProxyTest();
            NativeV8EngineProxy *        nv8ep = V8NetProxy.CreateV8EngineProxyTest();
            NativeObjectTemplateProxy *  notp  = V8NetProxy.CreateObjectTemplateProxyTest();
            NativeFunctionTemplateProxy *nftp  = V8NetProxy.CreateFunctionTemplateProxyTest();

            byte[] data;
            byte   ofs = 0; // (skip type)

            try
            {
                ofs = (byte)((int)&hp->NativeClassType - (int)hp);
                if (hp->NativeClassType != ProxyObjectType.HandleProxyClass)
                {
                    _ThrowMarshalTestError("HandleProxy", "NativeClassType", ofs, null, (byte *)&hp->NativeClassType, 4);
                }
                ofs = (byte)((int)&hp->ID - (int)hp);
                if ((Int32)hp->ID != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "ID", ofs, data, (byte *)&hp->ID);
                }
                ofs = (byte)((int)&hp->_ObjectID - (int)hp);
                if ((Int32)hp->_ObjectID != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "_ObjectID", ofs, data, (byte *)&hp->_ObjectID);
                }
                ofs = (byte)((int)&hp->_CLRTypeID - (int)hp);
                if ((Int32)hp->_CLRTypeID != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "_CLRTypeID", ofs, data, (byte *)&hp->_CLRTypeID);
                }
                ofs = (byte)((int)&hp->_Type - (int)hp);
                if ((Int32)hp->_Type != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "_ValueType", ofs, data, (byte *)&hp->_Type);
                }
                // region ### HANDLE VALUE ### - Note: This is only valid upon calling 'UpdateValue()'.
                ofs = (byte)((int)&hp->V8Boolean - (int)hp);
                if ((byte)hp->V8Boolean != _GetMarshalTestByteValue(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "V8Boolean", ofs, data, (byte *)&hp->V8Boolean);
                }
                if ((Int64)hp->V8Integer != _GetMarshalTestInt64Value(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "V8Integer", ofs, data, (byte *)&hp->V8Integer);
                }
                if ((double)hp->V8Number != _GetMarshalTestDoubleValue(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "V8Number", ofs, data, (byte *)&hp->V8Number);
                }
                ofs = (byte)((int)&hp->V8String - (int)hp);
                if ((Int64)hp->V8String != _GetMarshalTestPTRValue(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "V8String", ofs, data, (byte *)&hp->V8String);
                }
                // endregion
                ofs = (byte)((int)&hp->ManagedReference - (int)hp);
                if ((Int64)hp->ManagedReference != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "ManagedReference", ofs, data, (byte *)&hp->ManagedReference);                                                                         // The number of references on the managed side.
                }
                ofs = (byte)((int)&hp->Disposed - (int)hp);
                if ((Int32)hp->Disposed != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "Disposed", ofs, data, (byte *)&hp->Disposed);                                                                 // (0 = in use, 1 = managed side ready to dispose, 2 = object is weak (if applicable), 3 = disposed/cached)
                }
                ofs = (byte)((int)&hp->EngineID - (int)hp);
                if ((Int32)hp->EngineID != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "EngineID", ofs, data, (byte *)&hp->EngineID);
                }
                ofs = (byte)((int)&hp->NativeEngineProxy - (int)hp);
                if ((Int64)hp->NativeEngineProxy != _GetMarshalTestPTRValue(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "NativeEngineProxy", ofs, data, (byte *)&hp->NativeEngineProxy);                                                                        // Pointer to the native V8 engine proxy object associated with this proxy handle instance (used native side to free the handle upon destruction).
                }
                ofs = (byte)((int)&hp->NativeV8Handle - (int)hp);
                if ((Int64)hp->NativeV8Handle != _GetMarshalTestPTRValue(ofs, out data))
                {
                    _ThrowMarshalTestError("HandleProxy", "NativeV8Handle", ofs, data, (byte *)&hp->NativeV8Handle);                                                                     // The native V8 persistent object handle (not used on the managed side).
                }
                ofs = (byte)((int)&nv8ep->NativeClassType - (int)nv8ep);
                if (nv8ep->NativeClassType != ProxyObjectType.V8EngineProxyClass)
                {
                    _ThrowMarshalTestError("NativeV8EngineProxy", "NativeClassType", ofs, null, (byte *)&nv8ep->NativeClassType, 4);
                }
                ofs = (byte)((int)&nv8ep->ID - (int)nv8ep);
                if ((Int32)nv8ep->ID != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("NativeV8EngineProxy", "ID", ofs, data, (byte *)&nv8ep->ID);
                }
                ofs += (byte)data.Length;

                ofs = (byte)((int)&notp->NativeClassType - (int)notp);
                if (notp->NativeClassType != ProxyObjectType.ObjectTemplateProxyClass)
                {
                    _ThrowMarshalTestError("NativeObjectTemplateProxy", "NativeClassType", ofs, null, (byte *)&notp->NativeClassType, 4);
                }
                ofs = (byte)((int)&notp->NativeEngineProxy - (int)notp);
                if ((Int64)notp->NativeEngineProxy != _GetMarshalTestPTRValue(ofs, out data))
                {
                    _ThrowMarshalTestError("NativeObjectTemplateProxy", "NativeEngineProxy", ofs, data, (byte *)&notp->NativeEngineProxy);
                }
                ofs = (byte)((int)&notp->EngineID - (int)notp);
                if ((Int32)notp->EngineID != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("NativeObjectTemplateProxy", "EngineID", ofs, data, (byte *)&notp->EngineID);
                }
                ofs = (byte)((int)&notp->ObjectID - (int)notp);
                if ((Int32)notp->ObjectID != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("NativeObjectTemplateProxy", "ObjectID", ofs, data, (byte *)&notp->ObjectID);
                }
                ofs = (byte)((int)&notp->NativeObjectTemplate - (int)notp);
                if ((Int64)notp->NativeObjectTemplate != _GetMarshalTestPTRValue(ofs, out data))
                {
                    _ThrowMarshalTestError("NativeObjectTemplateProxy", "NativeObjectTemplate", ofs, data, (byte *)&notp->NativeObjectTemplate);
                }

                ofs = (byte)((int)&nftp->NativeClassType - (int)nftp);
                if (nftp->NativeClassType != ProxyObjectType.FunctionTemplateProxyClass)
                {
                    _ThrowMarshalTestError("NativeFunctionTemplateProxy", "NativeClassType", ofs, null, (byte *)&nftp->NativeClassType, 4);
                }
                ofs = (byte)((int)&nftp->NativeEngineProxy - (int)nftp);
                if ((Int64)nftp->NativeEngineProxy != _GetMarshalTestPTRValue(ofs, out data))
                {
                    _ThrowMarshalTestError("NativeFunctionTemplateProxy", "NativeEngineProxy", ofs, data, (byte *)&nftp->NativeEngineProxy);
                }
                ofs = (byte)((int)&nftp->EngineID - (int)nftp);
                if ((Int32)nftp->EngineID != _GetMarshalTestInt32Value(ofs, out data))
                {
                    _ThrowMarshalTestError("NativeFunctionTemplateProxy", "EngineID", ofs, data, (byte *)&nftp->EngineID);
                }
                ofs = (byte)((int)&nftp->NativeFucntionTemplate - (int)nftp);
                if ((Int64)nftp->NativeFucntionTemplate != _GetMarshalTestPTRValue(ofs, out data))
                {
                    _ThrowMarshalTestError("NativeFunctionTemplateProxy", "NativeFucntionTemplate", ofs, data, (byte *)&nftp->NativeFucntionTemplate);
                }
            }
            finally
            {
                V8NetProxy.DeleteTestData(hp);
                V8NetProxy.DeleteTestData(nv8ep);
                V8NetProxy.DeleteTestData(notp);
                V8NetProxy.DeleteTestData(nftp);
            }
        }
Beispiel #12
0
 public static unsafe extern HandleProxy *CreateInstanceFromFunctionTemplate(NativeFunctionTemplateProxy *functionTemplateProxy, Int32 objID, Int32 argCount, HandleProxy **args);
 public static unsafe extern NativeObjectTemplateProxy *GetFunctionPrototypeTemplateProxy32(NativeFunctionTemplateProxy *functionTemplateProxy);
Beispiel #14
0
 public static extern unsafe bool DeleteFunctionTemplateProxy64(NativeFunctionTemplateProxy *functionTemplateProxy);