GetProperty() public method

Gets a object's property
Requires an active script context.
public GetProperty ( IeJsPropertyId id ) : IeJsValue
id IeJsPropertyId The ID of the property
return IeJsValue
Ejemplo n.º 1
0
        private void FreezeObject(IeJsValue objValue)
        {
            IeJsValue objectValue       = IeJsValue.GlobalObject.GetProperty("Object");
            IeJsValue freezeMethodValue = objectValue.GetProperty("freeze");

            freezeMethodValue.CallFunction(objectValue, objValue);
        }
Ejemplo n.º 2
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.º 3
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.º 4
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);
        }