// -------------------------------------------------------------------------------------------------------------------- /// <summary> /// Calls the V8 'Set()' function on the underlying native function template to set properties that will exist on all function objects created from this template. /// </summary> public void SetProperty(string name, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.Undefined) { if (name.IsNullOrWhiteSpace()) { throw new ArgumentNullException("name (cannot be null, empty, or only whitespace)"); } V8NetProxy.SetFunctionTemplateProperty(_NativeFunctionTemplateProxy, name, value, attributes); }
// -------------------------------------------------------------------------------------------------------------------- // Since some base methods operate on object properties, and the properties exist on this managed object, we override // them here to speed things up. public override bool SetProperty(string name, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.None) { var result = NamedPropertySetter(ref name, value, attributes); if (result.IsUndefined) { return(base.SetProperty(name, value, attributes)); // (if this virtual override fails to set the property, try to do it via the base [directly on the native object]) } return(true); }
public override bool SetProperty(int index, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.Undefined) { var result = IndexedPropertySetter(index, value); if (result.IsUndefined) { return(base.SetProperty(index, value, attributes)); } return(true); }
// -------------------------------------------------------------------------------------------------------------------- /// <summary> /// Calls the V8 'SetAccessor()' function on the underlying native object to create a property that is controlled by /// "getter" and "setter" callbacks. /// <para>WARNING: If you try to set managed accessors on a native-ONLY object (as in, this handle does not yet have a /// managed-side object associated with it) then /// <see cref="V8Engine.CreateObject(InternalHandle, bool)"/> will be called to create a wrapper object so the /// accessor delegates will not get garbage collected, causing errors. You can optionally take control of this yourself /// and call one of the 'CreateObject()' methods on <see cref="V8Engine"/>.</para> /// </summary> /// <param name="name"> The property name. </param> /// <param name="getter"> /// The property getter delegate that returns a value when the property is accessed within JavaScript. /// </param> /// <param name="setter"> /// The property setter delegate that sets AND returns a value when the property is accessed within JavaScript. /// </param> /// <param name="attributes"> (Optional) The attributes to assign to the property. </param> /// <param name="access"> (Optional) The access security on the property. </param> /// <seealso cref="M:V8.Net.IV8Object.SetAccessor(string,GetterAccessor,SetterAccessor,V8PropertyAttributes,V8AccessControl)"/> public virtual void SetAccessor(string name, GetterAccessor getter, SetterAccessor setter, V8PropertyAttributes attributes = V8PropertyAttributes.None, V8AccessControl access = V8AccessControl.Default) { attributes = _CreateAccessorProxies(Engine, name, getter, setter, attributes, access, ref _Getter, ref _Setter); Getter = getter; Setter = setter; V8NetProxy.SetObjectAccessor(this, ID, name, _Getter, _Setter, access, attributes); }
/// <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, GetterAccessor getter, SetterAccessor setter, V8PropertyAttributes attributes = V8PropertyAttributes.None, V8AccessControl access = V8AccessControl.Default) { attributes = V8NativeObject._CreateAccessorProxies(Engine, name, getter, setter, attributes, access, ref _Getter, ref _Setter); Getter = getter; Setter = setter; V8NetProxy.SetObjectTemplateAccessor(_NativeObjectTemplateProxy, -1, name, _Getter, _Setter, access, attributes); }
// -------------------------------------------------------------------------------------------------------------------- /// <summary> /// Calls the V8 'Set()' function on the underlying native object template to set properties that will exist on all objects created from this template. /// </summary> public void SetProperty(string name, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.None) { try { if (name.IsNullOrWhiteSpace()) { throw new ArgumentNullException("name (cannot be null, empty, or only whitespace)"); } V8NetProxy.SetObjectTemplateProperty(_NativeObjectTemplateProxy, name, value, attributes); } finally { value._DisposeIfFirst(); } }
// -------------------------------------------------------------------------------------------------------------------- /// <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); }
public static unsafe extern bool SetObjectPropertyByIndex32(HandleProxy *proxy, Int32 index, HandleProxy *value, V8PropertyAttributes attributes = V8PropertyAttributes.None);
// -------------------------------------------------------------------------------------------------------------------- /// <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); }
public static unsafe extern void SetObjectTemplateAccessor(NativeObjectTemplateProxy *proxy, Int32 managedObjectID, string name, ManagedAccessorGetter getter, ManagedAccessorSetter setter, V8AccessControl access, V8PropertyAttributes attributes);
public static unsafe extern void SetObjectTemplateProperty(NativeObjectTemplateProxy* proxy, string name, HandleProxy* value, V8PropertyAttributes attributes = V8PropertyAttributes.None);
/// <summary> /// Binds a 'V8Function' object to the specified type and associates the type name (or custom script name) with the underlying object. /// Returns true if successful. /// </summary> /// <param name="type">The type to wrap.</param> /// <param name="propertyAttributes">Flags that describe the property behavior. They must be 'OR'd together as needed.</param> /// <param name="className">A custom in-script function name for the specified type, or 'null' to use either the type name as is (the default) or any existing 'ScriptObject' attribute name.</param> /// <param name="recursive">For object types, if true, then object reference members are included, otherwise only the object itself is bound and returned. /// For security reasons, public members that point to object instances will be ignored. This must be true to included those as well, effectively allowing /// in-script traversal of the object reference tree (so make sure this doesn't expose sensitive methods/properties/fields).</param> /// <param name="memberSecurity">For object instances, these are default flags that describe JavaScript properties for all object instance members that /// don't have any 'ScriptMember' attribute. The flags should be 'OR'd together as needed.</param> public virtual bool SetProperty(Type type, V8PropertyAttributes propertyAttributes = V8PropertyAttributes.None, string className = null, bool?recursive = null, ScriptMemberSecurity?memberSecurity = null) { return(_Handle.SetProperty(type, propertyAttributes, className, recursive, memberSecurity)); }
// -------------------------------------------------------------------------------------------------------------------- /// <summary> /// Calls the V8 'Set()' function on the underlying native object. /// Returns true if successful. /// </summary> /// <param name="attributes">Flags that describe the property behavior. They must be 'OR'd together as needed.</param> public virtual bool SetProperty(string name, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.None) { return(_Handle.SetProperty(name, value, attributes)); }
public virtual InternalHandle NamedPropertySetter(ref string propertyName, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.Undefined) { if (_Proxy != this) { var result = ((IV8ManagedObject)_Proxy).NamedPropertySetter(ref propertyName, value, attributes); if (!result.IsUndefined) return result; } var jsVal = this[propertyName]; if (jsVal.Value.IsEmpty) this[propertyName] = jsVal = new JSProperty(value, attributes != V8PropertyAttributes.Undefined ? attributes : V8PropertyAttributes.None); else { if (attributes != V8PropertyAttributes.Undefined) { jsVal.Attributes = attributes; jsVal.Value = value; // (note: updating attributes automatically assumes writable access) } else if ((jsVal.Attributes & V8PropertyAttributes.ReadOnly) == 0) jsVal.Value = value; } return jsVal.Value; }
/// <summary> /// Binds a 'V8Function' object to the specified type and associates the type name (or custom script name) with the underlying object. /// Returns true if successful. /// </summary> /// <param name="type">The type to wrap.</param> /// <param name="propertyAttributes">Flags that describe the property behavior. They must be 'OR'd together as needed.</param> /// <param name="className">A custom in-script function name for the specified type, or 'null' to use either the type name as is (the default) or any existing 'ScriptObject' attribute name.</param> /// <param name="recursive">For object types, if true, then object reference members are included, otherwise only the object itself is bound and returned. /// For security reasons, public members that point to object instances will be ignored. This must be true to included those as well, effectively allowing /// in-script traversal of the object reference tree (so make sure this doesn't expose sensitive methods/properties/fields).</param> /// <param name="memberSecurity">For object instances, these are default flags that describe JavaScript properties for all object instance members that /// don't have any 'ScriptMember' attribute. The flags should be 'OR'd together as needed.</param> public virtual bool SetProperty(Type type, V8PropertyAttributes propertyAttributes = V8PropertyAttributes.None, string className = null, bool? recursive = null, ScriptMemberSecurity? memberSecurity = null) { return _Handle._Handle.SetProperty(type, propertyAttributes, className, recursive, memberSecurity); }
public virtual InternalHandle NamedPropertySetter(ref string propertyName, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.Undefined) { if (_Proxy != this) { var result = ((IV8ManagedObject)_Proxy).NamedPropertySetter(ref propertyName, value, attributes); if (!result.IsUndefined) { return(result); } } var jsVal = this[propertyName]; if (jsVal.Value.IsEmpty) { this[propertyName] = jsVal = new JSProperty(value, attributes != V8PropertyAttributes.Undefined ? attributes : V8PropertyAttributes.None); } else { if (attributes != V8PropertyAttributes.Undefined) { jsVal.Attributes = attributes; jsVal.Value = value; // (note: updating attributes automatically assumes writable access) } else if ((jsVal.Attributes & V8PropertyAttributes.ReadOnly) == 0) { jsVal.Value = value; } } return(jsVal.Value); }
public static extern void SetFunctionTemplateProperty(NativeFunctionTemplateProxy* proxy, string name, HandleProxy* value, V8PropertyAttributes attributes = V8PropertyAttributes.None);
public static extern void SetObjectTemplateAccessor(NativeObjectTemplateProxy* proxy, Int32 managedObjectId, string name, ManagedAccessorGetter getter, ManagedAccessorSetter setter, V8AccessControl access, V8PropertyAttributes attributes);
public static extern bool SetObjectPropertyByName(HandleProxy* proxy, string name, HandleProxy* value, V8PropertyAttributes attributes = V8PropertyAttributes.None);
public static unsafe extern void SetObjectTemplateProperty32(NativeObjectTemplateProxy *proxy, string name, HandleProxy *value, V8PropertyAttributes attributes = V8PropertyAttributes.None);
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); }
public override bool SetProperty(string name, InternalHandle value, V8PropertyAttributes attributes) { var result = NamedPropertySetter(ref name, value, attributes); return !result.IsUndefined || base.SetProperty(name, value, attributes); }
public JSProperty(TValueSource source, V8PropertyAttributes attributes = V8PropertyAttributes.None) { Source = source; _Attributes = attributes; }
// -------------------------------------------------------------------------------------------------------------------- // Since some base methods operate on object properties, and the properties exist on this managed object, we override // them here to speed things up. public override bool SetProperty(string name, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.None) { var result = NamedPropertySetter(ref name, value, attributes); if (result.IsUndefined) return base.SetProperty(name, value, attributes); // (if this virtual override fails to set the property, try to do it via the base [directly on the native object]) return true; }
public JSProperty(InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.None) : this(default(TValueSource), value, attributes) { }
/// <summary> /// Calls the V8 'Set()' function on the underlying native object. /// Returns true if successful. /// </summary> /// <param name="index"> Zero-based index to set. </param> /// <param name="value"> The value to set. </param> /// <param name="attributes"> /// (Optional) Flags that describe the property behavior. They must be 'OR'd together as needed. /// <para>Warning: V8 does not support setting attributes using numerical indexes. If you set an attribute, the given /// value is converted to a string, and a named property setter will be used instead. </para> /// </param> public virtual bool SetProperty(Int32 index, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.Undefined) { return(_Handle.SetProperty(index, value, attributes)); }
// -------------------------------------------------------------------------------------------------------------------- /// <summary> /// Calls the V8 'Set()' function on the underlying native object. /// Returns true if successful. /// </summary> /// <param name="attributes">Flags that describe the property behavior. They must be 'OR'd together as needed.</param> public virtual bool SetProperty(string name, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.None) { return _Handle._Handle.SetProperty(name, value, 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) { SetAccessor(name, getter, setter, attributes, V8AccessControl.Default); }
public static unsafe extern void SetObjectAccessor(HandleProxy* proxy, Int32 managedObjectID, string name, ManagedAccessorGetter getter, ManagedAccessorSetter setter, V8AccessControl access, V8PropertyAttributes attributes);
/// <summary> /// Create a new JSProperty instance to help keep track of JavaScript object properties on managed objects. /// </summary> public JSProperty(V8PropertyAttributes attributes = V8PropertyAttributes.None) { Source = default(TValueSource); _Attributes = 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, V8AccessControl access) { HandleInternal.HandleInternal.SetAccessor(name, getter, setter, attributes, access); }
public JSProperty(TValueSource source, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.None) : this(source, attributes) { _Value.Set(value); }
/// <summary> /// Calls the V8 'Set()' function on the underlying native object. /// Returns true if successful. /// </summary> /// <param name="attributes">Flags that describe the property behavior. They must be 'OR'd together as needed.</param> public virtual bool SetProperty(string name, InternalHandle value, V8PropertyAttributes attributes) { return HandleInternal.HandleInternal.SetProperty(name, value, attributes); }
public JSProperty(V8Engine engine, object value, V8PropertyAttributes attributes = V8PropertyAttributes.None) : this(InternalHandle.Empty, attributes) { _Value.Set(engine != null ? engine.CreateValue(value) : InternalHandle.Empty); }
/// <summary> /// Binds a 'V8Function' object to the specified type and associates the type name (or custom script name) with the underlying object. /// Returns true if successful. /// </summary> /// <param name="type">The type to wrap.</param> /// <param name="propertyAttributes">Flags that describe the property behavior. They must be 'OR'd together as needed.</param> /// <param name="className">A custom in-script function name for the specified type, or 'null' to use either the type name as is (the default) or any existing 'ScriptObject' attribute name.</param> /// <param name="recursive">For object types, if true, then object reference members are included, otherwise only the object itself is bound and returned. /// For security reasons, public members that point to object instances will be ignored. This must be true to included those as well, effectively allowing /// in-script traversal of the object reference tree (so make sure this doesn't expose sensitive methods/properties/fields).</param> /// <param name="memberSecurity">For object instances, these are default flags that describe JavaScript properties for all object instance members that /// don't have any 'ScriptMember' attribute. The flags should be 'OR'd together as needed.</param> public virtual bool SetProperty(Type type, V8PropertyAttributes propertyAttributes, string className, bool? recursive, ScriptMemberSecurity? memberSecurity) { return HandleInternal.HandleInternal.SetProperty(type, propertyAttributes, className, recursive, memberSecurity); }
public static unsafe extern bool SetObjectPropertyByName(HandleProxy *proxy, string name, HandleProxy *value, V8PropertyAttributes attributes = V8PropertyAttributes.None);
// -------------------------------------------------------------------------------------------------------------------- /// <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); }
public static unsafe extern void SetFunctionTemplateProperty(NativeFunctionTemplateProxy *proxy, string name, HandleProxy *value, V8PropertyAttributes attributes = V8PropertyAttributes.None);
public static unsafe extern void SetObjectAccessor64(HandleProxy *proxy, Int32 managedObjectID, string name, NativeGetterAccessor getter, NativeSetterAccessor setter, V8AccessControl access, V8PropertyAttributes attributes);