Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 8
0
 internal static extern JsErrorCode JsCreatePropertyId(string name, UIntPtr length,
                                                       out JsPropertyId propertyId);
Esempio n. 9
0
 internal static extern JsErrorCode JsDefineProperty(JsValue obj, JsPropertyId propertyId,
                                                     JsValue propertyDescriptor, out bool result);
Esempio n. 10
0
 internal static extern JsErrorCode JsDeleteProperty(JsValue obj, JsPropertyId propertyId, bool useStrictRules,
                                                     out JsValue result);
Esempio n. 11
0
 internal static extern JsErrorCode JsHasOwnProperty(JsValue obj, JsPropertyId propertyId, out bool hasOwnProperty);
Esempio n. 12
0
 internal static extern JsErrorCode JsSetProperty(JsValue obj, JsPropertyId propertyId, JsValue value,
                                                  bool useStrictRules);
Esempio n. 13
0
 internal static extern JsErrorCode JsGetOwnPropertyDescriptor(JsValue obj, JsPropertyId propertyId,
                                                               out JsValue propertyDescriptor);
Esempio n. 14
0
 internal static extern JsErrorCode JsGetPropertyNameFromId(JsPropertyId propertyId, out string name);
Esempio n. 15
0
 internal static extern JsErrorCode JsGetPropertyIdType(JsPropertyId propertyId,
                                                        out JsPropertyIdType propertyIdType);
Esempio n. 16
0
 internal static extern JsErrorCode JsCopyPropertyId(JsPropertyId propertyId, byte[] buffer,
                                                     UIntPtr bufferSize, out UIntPtr length);
Esempio n. 17
0
 /// <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));
 }
Esempio n. 18
0
 internal static extern JsErrorCode JsGetSymbolFromPropertyId(JsPropertyId propertyId, out JsValue symbol);
Esempio n. 19
0
 internal static extern JsErrorCode JsGetProperty(JsValue obj, JsPropertyId propertyId, out JsValue value);
Esempio n. 20
0
 internal static extern JsErrorCode JsGetPropertyIdFromSymbol(JsValue symbol, out JsPropertyId propertyId);
Esempio n. 21
0
 internal static extern JsErrorCode JsGetPropertyIdFromName(string name, out JsPropertyId propertyId);