소스 검색

Fixing direct call to eval()

Sebastien Ros 12 년 전
부모
커밋
24071e0c9b
5개의 변경된 파일26개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 0
      Jint.Tests.Ecma/Ecma/10.4.1.cs
  2. 1 0
      Jint.Tests.Ecma/Ecma/10.4.2.cs
  3. 1 1
      Jint/Engine.cs
  4. 17 4
      Jint/Native/Function/EvalFunctionInstance.cs
  5. 6 0
      Jint/Runtime/ExpressionIntepreter.cs

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

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

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

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

+ 1 - 1
Jint/Engine.cs

@@ -116,7 +116,7 @@ namespace Jint
                 }
                 }
             }
             }
 
 
-            Eval = new EvalFunctionInstance(this, new ObjectInstance(this), new string[0], LexicalEnvironment.NewDeclarativeEnvironment(this, ExecutionContext.LexicalEnvironment), StrictModeScope.IsStrictModeCode);
+            Eval = new EvalFunctionInstance(this, new string[0], LexicalEnvironment.NewDeclarativeEnvironment(this, ExecutionContext.LexicalEnvironment), StrictModeScope.IsStrictModeCode);
             Global.FastAddProperty("eval", Eval, true, false, true);
             Global.FastAddProperty("eval", Eval, true, false, true);
 
 
             _statements = new StatementInterpreter(this);
             _statements = new StatementInterpreter(this);

+ 17 - 4
Jint/Native/Function/EvalFunctionInstance.cs

@@ -1,6 +1,4 @@
-using System.Net.NetworkInformation;
-using Jint.Native.Object;
-using Jint.Parser;
+using Jint.Parser;
 using Jint.Runtime;
 using Jint.Runtime;
 using Jint.Runtime.Environments;
 using Jint.Runtime.Environments;
 
 
@@ -10,12 +8,17 @@ namespace Jint.Native.Function
     {
     {
         private readonly Engine _engine;
         private readonly Engine _engine;
 
 
-        public EvalFunctionInstance(Engine engine, ObjectInstance prototype, string[] parameters, LexicalEnvironment scope, bool strict) : base(engine, parameters, scope, strict)
+        public EvalFunctionInstance(Engine engine, string[] parameters, LexicalEnvironment scope, bool strict) : base(engine, parameters, scope, strict)
         {
         {
             _engine = engine;
             _engine = engine;
         }
         }
 
 
         public override object Call(object thisObject, object[] arguments)
         public override object Call(object thisObject, object[] arguments)
+        {
+            return Call(thisObject, arguments, false);
+        }
+
+        public object Call(object thisObject, object[] arguments, bool directCall)
         {
         {
             var code = TypeConverter.ToString(arguments.At(0));
             var code = TypeConverter.ToString(arguments.At(0));
 
 
@@ -31,6 +34,11 @@ namespace Jint.Native.Function
 
 
                         try
                         try
                         {
                         {
+                            if (!directCall)
+                            {
+                                Engine.EnterExecutionContext(Engine.GlobalEnvironment, Engine.GlobalEnvironment, Engine.Global);
+                            }
+
                             if (StrictModeScope.IsStrictModeCode)
                             if (StrictModeScope.IsStrictModeCode)
                             {
                             {
                                 strictVarEnv = LexicalEnvironment.NewDeclarativeEnvironment(Engine, Engine.ExecutionContext.LexicalEnvironment);
                                 strictVarEnv = LexicalEnvironment.NewDeclarativeEnvironment(Engine, Engine.ExecutionContext.LexicalEnvironment);
@@ -56,6 +64,11 @@ namespace Jint.Native.Function
                             {
                             {
                                 Engine.LeaveExecutionContext();
                                 Engine.LeaveExecutionContext();
                             }
                             }
+
+                            if (!directCall)
+                            {
+                                Engine.LeaveExecutionContext();
+                            }
                         }
                         }
                     }
                     }
                 }
                 }

+ 6 - 0
Jint/Runtime/ExpressionIntepreter.cs

@@ -825,6 +825,12 @@ namespace Jint.Runtime
                 thisObject = Undefined.Instance;
                 thisObject = Undefined.Instance;
             }
             }
 
 
+            // is it a direct call to eval ? http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.2.1.1
+            if (r != null && r.GetReferencedName() == "eval" && callable is EvalFunctionInstance)
+            {
+                return ((EvalFunctionInstance) callable).Call(thisObject, arguments, true);
+            }
+            
             return callable.Call(thisObject, arguments);
             return callable.Call(thisObject, arguments);
         }
         }