Browse Source

Fixing member expression evaluation

Sebastien Ros 12 years ago
parent
commit
ac0a1531cd

+ 1 - 0
Jint.Tests.Ecma/Ecma/11.2.1.cs

@@ -2,6 +2,7 @@ using Xunit;
 
 namespace Jint.Tests.Ecma
 {
+    [Trait("Category", "Pass")]
     public class Test_11_2_1 : EcmaTest
     {
         [Fact]

+ 12 - 7
Jint/Runtime/Environments/LexicalEnvironment.cs

@@ -30,19 +30,24 @@ namespace Jint.Runtime.Environments
             get { return _outer; }
         }
 
-        public Reference GetIdentifierReference(string name, bool strict)
+        public static Reference GetIdentifierReference(LexicalEnvironment lex, string name, bool strict)
         {
-            if (Record.HasBinding(name))
+            if (lex == null)
             {
-                return new Reference(Record, name, strict);
+                return new Reference(Undefined.Instance, name, strict);
             }
-            
-            if (Outer == null)
+
+            if (lex.Record.HasBinding(name))
+            {
+                return new Reference(lex.Record, name, strict);
+            }
+
+            if (lex.Outer == null)
             {
                 return new Reference(Undefined.Instance, name, strict);    
             }
-            
-            return Outer.GetIdentifierReference(name, strict);
+
+            return GetIdentifierReference(lex.Outer, name, strict);
         }
 
         public static LexicalEnvironment NewDeclarativeEnvironment(Engine engine, LexicalEnvironment outer = null)

+ 13 - 11
Jint/Runtime/ExpressionIntepreter.cs

@@ -614,9 +614,12 @@ namespace Jint.Runtime
             }
         }
 
-        public object EvaluateIdentifier(Identifier identifier)
+        public Reference EvaluateIdentifier(Identifier identifier)
         {
-            return _engine.ExecutionContext.LexicalEnvironment.GetIdentifierReference(identifier.Name, StrictModeScope.IsStrictModeCode);
+            var env = _engine.ExecutionContext.LexicalEnvironment;
+            var strict = StrictModeScope.IsStrictModeCode;
+
+            return LexicalEnvironment.GetIdentifierReference(env, identifier.Name, strict);
         }
 
         public object EvaluateLiteral(Literal literal)
@@ -765,20 +768,19 @@ namespace Jint.Runtime
         {
             var baseReference = EvaluateExpression(memberExpression.Object);
             var baseValue = _engine.GetValue(baseReference);
+            Expression expression = memberExpression.Property;
 
-            string propertyNameString;
+            
             if (!memberExpression.Computed) // index accessor ?
             {
-                propertyNameString = memberExpression.Property.As<Identifier>().Name;
-            }
-            else
-            {
-                var propertyNameReference = EvaluateExpression(memberExpression.Property);
-                var propertyNameValue = _engine.GetValue(propertyNameReference);
-                TypeConverter.CheckObjectCoercible(_engine, baseValue);
-                propertyNameString = TypeConverter.ToString(propertyNameValue);
+                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);
+            var propertyNameString = TypeConverter.ToString(propertyNameValue);
+
             return new Reference(baseValue, propertyNameString, StrictModeScope.IsStrictModeCode);
         }
 

+ 1 - 1
Jint/Runtime/References/Reference.cs

@@ -49,7 +49,7 @@ namespace Jint.Runtime.References
 
         public bool IsUnresolvableReference()
         {
-            return _baseValue == Undefined.Instance || _baseValue == Null.Instance;
+            return _baseValue == Undefined.Instance;
         }
 
         public bool IsPropertyReference()