コード例 #1
0
ファイル: V8NativeObject.cs プロジェクト: wukongiii/v8dotnet
        static internal V8PropertyAttributes _CreateAccessorProxies(V8Engine engine, string name, GetterAccessor getter, SetterAccessor setter, V8PropertyAttributes attributes, V8AccessControl access,
                                                                    ref NativeGetterAccessor _Getter, ref NativeSetterAccessor _Setter)
        {
            if (name.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(name), "Cannot be null, empty, or only whitespace.");
            }
            if (attributes == V8PropertyAttributes.Undefined)
            {
                attributes = V8PropertyAttributes.None;
            }
            if (attributes < 0)
            {
                throw new InvalidOperationException("'attributes' has an invalid value.");
            }
            if (access < 0)
            {
                throw new InvalidOperationException("'access' has an invalid value.");
            }

            if (getter != null && _Getter == null)
            {
                _Getter = (_this, _name) => // (only need to set this once on first use)
                {
                    try
                    {
                        return(getter != null?getter(_this, _name) : null);
                    }
                    catch (Exception ex)
                    {
                        return(engine.CreateError(Exceptions.GetFullErrorMessage(ex), JSValueType.ExecutionError));
                    }
                }
            }
            ;

            if (setter != null && _Setter == null)
            {
                _Setter = (_this, _name, _val) => // (only need to set this once on first use)
                {
                    try
                    {
                        return(setter != null?setter(_this, _name, _val) : null);
                    }
                    catch (Exception ex)
                    {
                        return(engine.CreateError(Exceptions.GetFullErrorMessage(ex), JSValueType.ExecutionError));
                    }
                }
            }
            ;

            return(attributes);
        }
コード例 #2
0
ファイル: V8NativeObject.cs プロジェクト: wukongiii/v8dotnet
        /// <summary>
        ///     Returns true if disposed, and false if already disposed.
        /// </summary>
        internal bool _Dispose() // WARNING: The worker thread may cause a V8 GC callback in its own thread!
        {
            if (!_Handle.IsEmpty)
            {
                //? _Handle.IsDisposing = true;
                var engine = Engine;

                //// ... remove this object from the abandoned queue ...

                //lock (engine._AbandondObjects)
                //{
                //    LinkedListNode<IV8Disposable> node;
                //    if (engine._AbandondObjectsIndex.TryGetValue(this, out node))
                //    {
                //        engine._AbandondObjects.Remove(node);
                //        engine._AbandondObjectsIndex.Remove(this);
                //    }
                //}

                // ... notify any custom dispose methods to clean up ...

                try
                {
                    OnDispose();
                }
                finally
                {
                }

                // ... if this belongs to a function template, then this is a V8Function object, so remove it from the template's type list ...

                if (Template is FunctionTemplate)
                {
                    ((FunctionTemplate)Template)._RemoveFunctionType(ID);// (make sure to remove the function references from the template instance)
                }
                // ... clear any registered accessors ...

                Getter  = null;
                _Getter = null;
                Setter  = null;
                _Setter = null;

                // ... reset and dispose the handle ...

                if (!_Handle.IsEmpty)
                {
                    _Handle.ObjectID = -1; // (resets the object ID on the native side [though this happens anyhow once cached], which also causes the reference to clear)
                    // (MUST clear the object ID, else the handle will not get disposed [because '{Handle}.IsLocked' will return false])
                    _Handle._Finalize(false);
                }

                if (_ID != null)
                {
                    engine._RemoveObjectWeakReference(_ID.Value);
                }

                Template = null; // (note: this decrements a template counter, allowing the template object to be finally allowed to dispose)
                _ID      = null; // (also allows the GC finalizer to collect the object)

                return(true);
            }

            return(false);
        }
コード例 #3
0
        public static unsafe extern void SetObjectTemplateAccessor64(NativeObjectTemplateProxy *proxy, Int32 managedObjectID, string name,

                                                                     NativeGetterAccessor getter, NativeSetterAccessor setter,
                                                                     V8AccessControl access, V8PropertyAttributes attributes);