// --------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Calls the V8 'SetAccessor()' function on the underlying native 'v8::ObjectTenplate' instance to create a property that is controlled by "getter" and "setter" callbacks.
        /// <para>Note: This is template related, which means all objects created from this template will be affected by these special properties.</para>
        /// </summary>
        public void SetAccessor(string name,
                                V8NativeObjectPropertyGetter getter, V8NativeObjectPropertySetter setter,
                                V8PropertyAttributes attributes = V8PropertyAttributes.None, V8AccessControl access = V8AccessControl.Default)
        {
            if (name.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException("name (cannot be null, empty, or only whitespace)");
            }

            var engine = Engine;

            V8NetProxy.SetObjectTemplateAccessor(_NativeObjectTemplateProxy, -1, name,
                                                 _Engine._StoreAccessor <ManagedAccessorGetter>(_NativeObjectTemplateProxy->ObjectID, "get_" + name, (HandleProxy * _this, string propertyName) =>
            {
                try
                {
                    using (InternalHandle hThis = _this) { return(getter != null ? getter(hThis, propertyName) : null); }
                }
                catch (Exception ex)
                {
                    return(engine.CreateError(Exceptions.GetFullErrorMessage(ex), JSValueType.ExecutionError));
                }
            }),
                                                 _Engine._StoreAccessor <ManagedAccessorSetter>(_NativeObjectTemplateProxy->ObjectID, "set_" + name, (HandleProxy * _this, string propertyName, HandleProxy * value) =>
            {
                try
                {
                    using (InternalHandle hThis = _this) { return(setter != null ? setter(hThis, propertyName, value) : null); }
                }
                catch (Exception ex)
                {
                    return(engine.CreateError(Exceptions.GetFullErrorMessage(ex), JSValueType.ExecutionError));
                }
            }),
                                                 access, attributes);
        }
        // --------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Calls the V8 'SetAccessor()' function on the underlying native object to create a property that is controlled by "getter" and "setter" callbacks.
        /// </summary>
        public virtual void SetAccessor(string name,
                                        V8NativeObjectPropertyGetter getter, V8NativeObjectPropertySetter setter,
                                        V8PropertyAttributes attributes = V8PropertyAttributes.None, V8AccessControl access = V8AccessControl.Default)
        {
            _Handle.SetAccessor(name, getter, setter, attributes, access);
        }
Exemple #3
0
 /// <summary>
 /// Calls the V8 'SetAccessor()' function on the underlying native object to create a property that is controlled by "getter" and "setter" callbacks.
 /// </summary>
 public virtual void SetAccessor(string name,
     V8NativeObjectPropertyGetter getter, V8NativeObjectPropertySetter setter,
     V8PropertyAttributes attributes, V8AccessControl access)
 {
     HandleInternal.HandleInternal.SetAccessor(name, getter, setter, attributes, access);
 }
Exemple #4
0
 /// <summary>
 /// Calls the V8 'SetAccessor()' function on the underlying native object to create a property that is controlled by "getter" and "setter" callbacks.
 /// </summary>
 public virtual void SetAccessor(string name,
     V8NativeObjectPropertyGetter getter, V8NativeObjectPropertySetter setter, V8PropertyAttributes attributes)
 {
     SetAccessor(name, getter, setter, attributes, V8AccessControl.Default);
 }
Exemple #5
0
 // --------------------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Calls the V8 'SetAccessor()' function on the underlying native object to create a property that is controlled by "getter" and "setter" callbacks.
 /// </summary>
 public virtual void SetAccessor(string name,
     V8NativeObjectPropertyGetter getter, V8NativeObjectPropertySetter setter,
     V8PropertyAttributes attributes = V8PropertyAttributes.None, V8AccessControl access = V8AccessControl.Default)
 {
     _Handle._Handle.SetAccessor(name, getter, setter, attributes, access);
 }