/// <summary> /// Deletes an object's property /// </summary> /// <remarks> /// Requires an active script context. /// </remarks> /// <param name="propertyId">The ID of the property</param> /// <param name="useStrictRules">The property set should follow strict mode rules</param> /// <returns>Whether the property was deleted</returns> public JsValue DeleteProperty(JsPropertyId propertyId, bool useStrictRules) { JsValue returnReference; JsErrorHelpers.ThrowIfError(NativeMethods.JsDeleteProperty(this, propertyId, useStrictRules, out returnReference)); return(returnReference); }
/// <summary> /// Defines a new object's own property from a property descriptor /// </summary> /// <remarks> /// Requires an active script context. /// </remarks> /// <param name="propertyId">The ID of the property</param> /// <param name="propertyDescriptor">The property descriptor</param> /// <returns>Whether the property was defined</returns> public bool DefineProperty(JsPropertyId propertyId, JsValue propertyDescriptor) { bool result; JsErrorHelpers.ThrowIfError(NativeMethods.JsDefineProperty(this, propertyId, propertyDescriptor, out result)); return(result); }
/// <summary> /// Gets an object's property /// </summary> /// <remarks> /// Requires an active script context. /// </remarks> /// <param name="id">The ID of the property</param> /// <returns>The value of the property</returns> public JsValue GetProperty(JsPropertyId id) { JsValue propertyReference; JsErrorHelpers.ThrowIfError(NativeMethods.JsGetProperty(this, id, out propertyReference)); return(propertyReference); }
/// <summary> /// Determines whether an object has a non-inherited property /// </summary> /// <remarks> /// Requires an active script context. /// </remarks> /// <param name="propertyId">The ID of the property</param> /// <returns>Whether the object has the non-inherited property</returns> public bool HasOwnProperty(JsPropertyId propertyId) { bool hasOwnProperty; JsErrorHelpers.ThrowIfError(NativeMethods.JsHasOwnProperty(this, propertyId, out hasOwnProperty)); return(hasOwnProperty); }
/// <summary> /// Gets a property descriptor for an object's own property /// </summary> /// <remarks> /// Requires an active script context. /// </remarks> /// <param name="propertyId">The ID of the property</param> /// <returns>The property descriptor</returns> public JsValue GetOwnPropertyDescriptor(JsPropertyId propertyId) { JsValue descriptorReference; JsErrorHelpers.ThrowIfError(NativeMethods.JsGetOwnPropertyDescriptor(this, propertyId, out descriptorReference)); return(descriptorReference); }
/// <summary> /// Makes a mapping of value from the script type to a host type /// </summary> /// <param name="value">The source value</param> /// <returns>The mapped value</returns> public object MapToHostType(JsValue value) { JsValueType valueType = value.ValueType; object result = null; switch (valueType) { case JsValueType.Null: result = null; break; case JsValueType.Undefined: result = Undefined.Value; break; case JsValueType.Boolean: result = value.ToBoolean(); break; case JsValueType.Number: result = NumericHelpers.CastDoubleValueToCorrectType(value.ToDouble()); break; case JsValueType.String: result = value.ToString(); break; case JsValueType.Function: JsPropertyId externalObjectPropertyId = JsPropertyId.FromString(ExternalObjectPropertyName); if (value.HasProperty(externalObjectPropertyId)) { JsValue externalObjectValue = value.GetProperty(externalObjectPropertyId); result = externalObjectValue.HasExternalData ? GCHandle.FromIntPtr(externalObjectValue.ExternalData).Target : null; } result = result ?? value.ConvertToObject(); break; case JsValueType.Object: case JsValueType.Error: case JsValueType.Array: case JsValueType.Symbol: case JsValueType.ArrayBuffer: case JsValueType.TypedArray: case JsValueType.DataView: result = value.HasExternalData ? GCHandle.FromIntPtr(value.ExternalData).Target : value.ConvertToObject(); break; default: throw new ArgumentOutOfRangeException(); } return(result); }
private static void SetNonEnumerableProperty(JsValue objValue, string name, JsValue value) { JsValue descriptorValue = JsValue.CreateObject(); descriptorValue.SetProperty("enumerable", JsValue.False, true); descriptorValue.SetProperty("writable", JsValue.True, true); JsPropertyId id = JsPropertyId.FromString(name); objValue.DefineProperty(id, descriptorValue); objValue.SetProperty(id, value, true); }
internal static extern JsErrorCode JsCreatePropertyId(string name, UIntPtr length, out JsPropertyId propertyId);
internal static extern JsErrorCode JsDefineProperty(JsValue obj, JsPropertyId propertyId, JsValue propertyDescriptor, out bool result);
internal static extern JsErrorCode JsDeleteProperty(JsValue obj, JsPropertyId propertyId, bool useStrictRules, out JsValue result);
internal static extern JsErrorCode JsHasOwnProperty(JsValue obj, JsPropertyId propertyId, out bool hasOwnProperty);
internal static extern JsErrorCode JsSetProperty(JsValue obj, JsPropertyId propertyId, JsValue value, bool useStrictRules);
internal static extern JsErrorCode JsGetOwnPropertyDescriptor(JsValue obj, JsPropertyId propertyId, out JsValue propertyDescriptor);
internal static extern JsErrorCode JsGetPropertyNameFromId(JsPropertyId propertyId, out string name);
internal static extern JsErrorCode JsGetPropertyIdType(JsPropertyId propertyId, out JsPropertyIdType propertyIdType);
internal static extern JsErrorCode JsCopyPropertyId(JsPropertyId propertyId, byte[] buffer, UIntPtr bufferSize, out UIntPtr length);
/// <summary> /// Sets an object's property /// </summary> /// <remarks> /// Requires an active script context. /// </remarks> /// <param name="id">The ID of the property</param> /// <param name="value">The new value of the property</param> /// <param name="useStrictRules">The property set should follow strict mode rules</param> public void SetProperty(JsPropertyId id, JsValue value, bool useStrictRules) { JsErrorHelpers.ThrowIfError(NativeMethods.JsSetProperty(this, id, value, useStrictRules)); }
internal static extern JsErrorCode JsGetSymbolFromPropertyId(JsPropertyId propertyId, out JsValue symbol);
internal static extern JsErrorCode JsGetProperty(JsValue obj, JsPropertyId propertyId, out JsValue value);
internal static extern JsErrorCode JsGetPropertyIdFromSymbol(JsValue symbol, out JsPropertyId propertyId);
internal static extern JsErrorCode JsGetPropertyIdFromName(string name, out JsPropertyId propertyId);