Esempio n. 1
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(IeJsPropertyId propertyId, IeJsValue propertyDescriptor)
        {
            bool result;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsDefineProperty(this, propertyId, propertyDescriptor, out result));

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Determines whether an object has a property
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="propertyId">The ID of the property</param>
        /// <returns>Whether the object (or a prototype) has the property</returns>
        public bool HasProperty(IeJsPropertyId propertyId)
        {
            bool hasProperty;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsHasProperty(this, propertyId, out hasProperty));

            return(hasProperty);
        }
Esempio n. 3
0
        /// <summary>
        /// Deletes a 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 IeJsValue DeleteProperty(IeJsPropertyId propertyId, bool useStrictRules)
        {
            IeJsValue returnReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsDeleteProperty(this, propertyId, useStrictRules, out returnReference));

            return(returnReference);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a 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 IeJsValue GetProperty(IeJsPropertyId id)
        {
            IeJsValue propertyReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsGetProperty(this, id, out propertyReference));

            return(propertyReference);
        }
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 IeJsValue GetOwnPropertyDescriptor(IeJsPropertyId propertyId)
        {
            IeJsValue descriptorReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsGetOwnPropertyDescriptor(this, propertyId, out descriptorReference));

            return(descriptorReference);
        }
Esempio n. 6
0
        public override void RemoveVariable(string variableName)
        {
            InvokeScript(() =>
            {
                IeJsValue globalObj       = IeJsValue.GlobalObject;
                IeJsPropertyId variableId = IeJsPropertyId.FromString(variableName);

                if (globalObj.HasProperty(variableId))
                {
                    globalObj.SetProperty(variableId, IeJsValue.Undefined, true);
                }
            });
        }
Esempio n. 7
0
        public override object CallFunction(string functionName, params object[] args)
        {
            object result = InvokeScript(() =>
            {
                IeJsValue globalObj       = IeJsValue.GlobalObject;
                IeJsPropertyId functionId = IeJsPropertyId.FromString(functionName);

                bool functionExist = globalObj.HasProperty(functionId);
                if (!functionExist)
                {
                    throw new JsRuntimeException(
                        string.Format(CommonStrings.Runtime_FunctionNotExist, functionName));
                }

                IeJsValue resultValue;
                IeJsValue functionValue = globalObj.GetProperty(functionId);

                if (args.Length > 0)
                {
                    IeJsValue[] processedArgs = MapToScriptType(args);

                    foreach (IeJsValue processedArg in processedArgs)
                    {
                        AddReferenceToValue(processedArg);
                    }

                    IeJsValue[] allProcessedArgs = new[] { globalObj }.Concat(processedArgs).ToArray();
                    resultValue = functionValue.CallFunction(allProcessedArgs);

                    foreach (IeJsValue processedArg in processedArgs)
                    {
                        RemoveReferenceToValue(processedArg);
                    }
                }
                else
                {
                    resultValue = functionValue.CallFunction(globalObj);
                }

                return(MapToHostType(resultValue));
            });

            return(result);
        }
Esempio n. 8
0
        public override bool HasVariable(string variableName)
        {
            bool result = InvokeScript(() =>
            {
                IeJsValue globalObj       = IeJsValue.GlobalObject;
                IeJsPropertyId variableId = IeJsPropertyId.FromString(variableName);
                bool variableExist        = globalObj.HasProperty(variableId);

                if (variableExist)
                {
                    IeJsValue variableValue = globalObj.GetProperty(variableId);
                    variableExist           = variableValue.ValueType != JsValueType.Undefined;
                }

                return(variableExist);
            });

            return(result);
        }
Esempio n. 9
0
 /// <summary>
 /// Sets a 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(IeJsPropertyId id, IeJsValue value, bool useStrictRules)
 {
     IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsSetProperty(this, id, value, useStrictRules));
 }
Esempio n. 10
0
 internal static extern JsErrorCode JsGetOwnPropertyDescriptor(IeJsValue obj, IeJsPropertyId propertyId,
                                                               out IeJsValue propertyDescriptor);
Esempio n. 11
0
 internal static extern JsErrorCode JsGetPropertyNameFromId(IeJsPropertyId propertyId, out IntPtr buffer);
Esempio n. 12
0
 internal static extern JsErrorCode JsGetPropertyIdFromName(string name, out IeJsPropertyId propertyId);
Esempio n. 13
0
 internal static extern JsErrorCode JsDefineProperty(IeJsValue obj, IeJsPropertyId propertyId,
                                                     IeJsValue propertyDescriptor, out bool result);
Esempio n. 14
0
 internal static extern JsErrorCode JsDeleteProperty(IeJsValue obj, IeJsPropertyId propertyId,
                                                     bool useStrictRules, out IeJsValue result);
Esempio n. 15
0
 internal static extern JsErrorCode JsHasProperty(IeJsValue obj, IeJsPropertyId propertyId,
                                                  out bool hasProperty);
Esempio n. 16
0
 internal static extern JsErrorCode JsSetProperty(IeJsValue obj, IeJsPropertyId propertyId, IeJsValue value,
                                                  bool useStrictRules);
Esempio n. 17
0
        private JsRuntimeException ConvertJsExceptionToJsRuntimeException(
            JsException jsException)
        {
            string message        = jsException.Message;
            string category       = string.Empty;
            int    lineNumber     = 0;
            int    columnNumber   = 0;
            string sourceFragment = string.Empty;

            var jsScriptException = jsException as IeJsScriptException;

            if (jsScriptException != null)
            {
                category = "Script error";
                IeJsValue errorValue = jsScriptException.Error;

                IeJsPropertyId messagePropertyId    = IeJsPropertyId.FromString("message");
                IeJsValue      messagePropertyValue = errorValue.GetProperty(messagePropertyId);
                string         scriptMessage        = messagePropertyValue.ConvertToString().ToString();
                if (!string.IsNullOrWhiteSpace(scriptMessage))
                {
                    message = string.Format("{0}: {1}", message.TrimEnd('.'), scriptMessage);
                }

                IeJsPropertyId linePropertyId = IeJsPropertyId.FromString("line");
                if (errorValue.HasProperty(linePropertyId))
                {
                    IeJsValue linePropertyValue = errorValue.GetProperty(linePropertyId);
                    lineNumber = (int)linePropertyValue.ConvertToNumber().ToDouble() + 1;
                }

                IeJsPropertyId columnPropertyId = IeJsPropertyId.FromString("column");
                if (errorValue.HasProperty(columnPropertyId))
                {
                    IeJsValue columnPropertyValue = errorValue.GetProperty(columnPropertyId);
                    columnNumber = (int)columnPropertyValue.ConvertToNumber().ToDouble() + 1;
                }

                IeJsPropertyId sourcePropertyId = IeJsPropertyId.FromString("source");
                if (errorValue.HasProperty(sourcePropertyId))
                {
                    IeJsValue sourcePropertyValue = errorValue.GetProperty(sourcePropertyId);
                    sourceFragment = sourcePropertyValue.ConvertToString().ToString();
                }
            }
            else if (jsException is JsUsageException)
            {
                category = "Usage error";
            }
            else if (jsException is JsEngineException)
            {
                category = "Engine error";
            }
            else if (jsException is JsFatalException)
            {
                category = "Fatal error";
            }

            var jsEngineException = new JsRuntimeException(message, _engineModeName)
            {
                ErrorCode      = ((uint)jsException.ErrorCode).ToString(CultureInfo.InvariantCulture),
                Category       = category,
                LineNumber     = lineNumber,
                ColumnNumber   = columnNumber,
                SourceFragment = sourceFragment
            };

            return(jsEngineException);
        }
Esempio n. 18
0
 internal static extern JsErrorCode JsGetProperty(IeJsValue obj, IeJsPropertyId propertyId,
                                                  out IeJsValue value);