Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
                }
            });
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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));
 }
Ejemplo n.º 10
0
 internal static extern JsErrorCode JsGetOwnPropertyDescriptor(IeJsValue obj, IeJsPropertyId propertyId,
                                                               out IeJsValue propertyDescriptor);
Ejemplo n.º 11
0
 internal static extern JsErrorCode JsGetPropertyNameFromId(IeJsPropertyId propertyId, out IntPtr buffer);
Ejemplo n.º 12
0
 internal static extern JsErrorCode JsGetPropertyIdFromName(string name, out IeJsPropertyId propertyId);
Ejemplo n.º 13
0
 internal static extern JsErrorCode JsDefineProperty(IeJsValue obj, IeJsPropertyId propertyId,
                                                     IeJsValue propertyDescriptor, out bool result);
Ejemplo n.º 14
0
 internal static extern JsErrorCode JsDeleteProperty(IeJsValue obj, IeJsPropertyId propertyId,
                                                     bool useStrictRules, out IeJsValue result);
Ejemplo n.º 15
0
 internal static extern JsErrorCode JsHasProperty(IeJsValue obj, IeJsPropertyId propertyId,
                                                  out bool hasProperty);
Ejemplo n.º 16
0
 internal static extern JsErrorCode JsSetProperty(IeJsValue obj, IeJsPropertyId propertyId, IeJsValue value,
                                                  bool useStrictRules);
Ejemplo 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);
        }
Ejemplo n.º 18
0
 internal static extern JsErrorCode JsGetProperty(IeJsValue obj, IeJsPropertyId propertyId,
                                                  out IeJsValue value);