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