CheckObjectCoercible() публичный статический Метод

public static CheckObjectCoercible ( Engine engine, Jint.Native.JsValue o ) : void
engine Engine
o Jint.Native.JsValue
Результат void
        /// <summary>
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-11.2.1
        /// </summary>
        /// <param name="memberExpression"></param>
        /// <returns></returns>
        public Reference EvaluateMemberExpression(MemberExpression memberExpression)
        {
            var        baseReference = EvaluateExpression(memberExpression.Object);
            var        baseValue     = _engine.GetValue(baseReference);
            Expression expression    = memberExpression.Property;

            if (!memberExpression.Computed) // index accessor ?
            {
                expression = new Literal {
                    Type = SyntaxNodes.Literal, Value = memberExpression.Property.As <Identifier>().Name
                };
            }

            var propertyNameReference = EvaluateExpression(expression);
            var propertyNameValue     = _engine.GetValue(propertyNameReference);

            TypeConverter.CheckObjectCoercible(_engine, baseValue, memberExpression, baseReference);
            var propertyNameString = TypeConverter.ToString(propertyNameValue);

            return(new Reference(baseValue, propertyNameString, StrictModeScope.IsStrictModeCode));
        }
Пример #2
0
        /// <summary>
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-11.2.1
        /// </summary>
        /// <param name="memberExpression"></param>
        /// <returns></returns>
        public Reference EvaluateMemberExpression(MemberExpression memberExpression)
        {
            var        baseReference = EvaluateExpression(memberExpression.Object);
            var        baseValue     = _engine.GetValue(baseReference);
            Expression expression    = memberExpression.Property;


            if (!memberExpression.Computed) // index accessor ?
            {
                expression = new Literal {
                    Type = SyntaxNodes.Literal, Value = memberExpression.Property.As <Identifier>().Name
                };
            }

            var propertyNameReference = EvaluateExpression(expression);
            var propertyNameValue     = _engine.GetValue(propertyNameReference);

            try
            {
                TypeConverter.CheckObjectCoercible(_engine, baseValue);
            }
            catch (Exception exception)
            {
                if (string.IsNullOrEmpty(exception.Message))
                {
                    string undefinedObjectName = null;
                    string message             = "Jint error";

                    try
                    {
                        switch (memberExpression.Object.Type)
                        {
                        case SyntaxNodes.MemberExpression:
                            if (memberExpression.Object.As <MemberExpression>().Property.Type.Equals(SyntaxNodes.Identifier))
                            {
                                undefinedObjectName = memberExpression.Object.As <MemberExpression>().Property.As <Identifier>().Name;
                            }
                            break;

                        case SyntaxNodes.Identifier:
                            undefinedObjectName = memberExpression.Object.As <Identifier>().Name;
                            break;

                        default:
                            break;
                        }
                        switch (memberExpression.Property.Type)
                        {
                        case SyntaxNodes.Identifier:
                            string undefinedPropertyName = memberExpression.Property.As <Identifier>().Name;
                            if (!string.IsNullOrEmpty(undefinedObjectName) && !string.IsNullOrEmpty(undefinedPropertyName))
                            {
                                message = string.Format("Could not evaluate property '{0}' of undefined object '{1}'", undefinedPropertyName, undefinedObjectName);
                            }
                            break;

                        case SyntaxNodes.Literal:
                            string undefinedLiteral = memberExpression.Property.As <Literal>().GetKey();
                            if (!string.IsNullOrEmpty(undefinedObjectName) && !string.IsNullOrEmpty(undefinedLiteral))
                            {
                                message = string.Format("Could not evaluate object '{1}' with literal {0}", undefinedLiteral, undefinedObjectName);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    catch
                    {
                    }
                    throw new JavaScriptException(_engine.TypeError, message);
                }

                throw exception;
            }
            var propertyNameString = TypeConverter.ToString(propertyNameValue);

            return(new Reference(baseValue, propertyNameString, StrictModeScope.IsStrictModeCode));
        }