Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1927)

Unified Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1508293003: [Interpreter] Add support for calling eval. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index 3db22ece19d4972925bd031dc6d6315f16c62f5b..3db8025ccb68d7135c447b8dc67be931cf1378aa 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -66,6 +66,7 @@ class InterpreterTester {
feedback_vector_(feedback_vector) {
i::FLAG_ignition = true;
i::FLAG_ignition_fake_try_catch = true;
+ i::FLAG_ignition_fallback_on_eval_and_catch = false;
i::FLAG_always_opt = false;
// Set ignition filter flag via SetFlagsFromString to avoid double-free
// (or potential leak with StrDup() based on ownership confusion).
@@ -3195,6 +3196,40 @@ TEST(InterpreterToName) {
}
+TEST(TemporaryRegisterAllocation) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ std::pair<const char*, Handle<Object>> reg_tests[] = {
+ {"function add(a, b, c) {"
+ " return a + b + c;"
+ "}"
+ "function f() {"
+ " var a = 10, b = 10;"
+ " return add(a, b++, b);"
+ "}",
+ factory->NewNumberFromInt(31)},
+ {"function add(a, b, c, d) {"
+ " return a + b + c + d;"
+ "}"
+ "function f() {"
+ " var x = 10, y = 20, z = 30;"
+ " return x + add(x, (y= x++), x, z);"
+ "}",
+ factory->NewNumberFromInt(71)},
+ };
+
+ for (size_t i = 0; i < arraysize(reg_tests); i++) {
+ InterpreterTester tester(handles.main_isolate(), reg_tests[i].first);
+ auto callable = tester.GetCallable<>();
+
+ Handle<i::Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*reg_tests[i].second));
+ }
+}
+
+
TEST(InterpreterLookupSlot) {
HandleAndZoneScope handles;
i::Isolate* isolate = handles.main_isolate();
@@ -3276,40 +3311,6 @@ TEST(InterpreterLookupSlotWide) {
}
-TEST(TemporaryRegisterAllocation) {
- HandleAndZoneScope handles;
- i::Isolate* isolate = handles.main_isolate();
- i::Factory* factory = isolate->factory();
-
- std::pair<const char*, Handle<Object>> reg_tests[] = {
- {"function add(a, b, c) {"
- " return a + b + c;"
- "}"
- "function f() {"
- " var a = 10, b = 10;"
- " return add(a, b++, b);"
- "}",
- factory->NewNumberFromInt(31)},
- {"function add(a, b, c, d) {"
- " return a + b + c + d;"
- "}"
- "function f() {"
- " var x = 10, y = 20, z = 30;"
- " return x + add(x, (y= x++), x, z);"
- "}",
- factory->NewNumberFromInt(71)},
- };
-
- for (size_t i = 0; i < arraysize(reg_tests); i++) {
- InterpreterTester tester(handles.main_isolate(), reg_tests[i].first);
- auto callable = tester.GetCallable<>();
-
- Handle<i::Object> return_value = callable().ToHandleChecked();
- CHECK(return_value->SameValue(*reg_tests[i].second));
- }
-}
-
-
TEST(InterpreterDeleteLookupSlot) {
HandleAndZoneScope handles;
i::Isolate* isolate = handles.main_isolate();
@@ -3387,6 +3388,112 @@ TEST(JumpWithConstantsAndWideConstants) {
}
}
+
+TEST(InterpreterEval) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ std::pair<const char*, Handle<Object>> eval[] = {
+ {"return eval('1;');", handle(Smi::FromInt(1), isolate)},
+ {"return eval('100 * 20;');", handle(Smi::FromInt(2000), isolate)},
+ {"var x = 10; return eval('x + 20;');",
+ handle(Smi::FromInt(30), isolate)},
+ {"var x = 10; eval('x = 33;'); return x;",
+ handle(Smi::FromInt(33), isolate)},
+ {"'use strict'; var x = 20; var z = 0;\n"
+ "eval('var x = 33; z = x;'); return x + z;",
+ handle(Smi::FromInt(53), isolate)},
+ {"eval('var x = 33;'); eval('var y = x + 20'); return x + y;",
+ handle(Smi::FromInt(86), isolate)},
+ {"var x = 1; eval('for(i = 0; i < 10; i++) x = x + 1;'); return x",
+ handle(Smi::FromInt(11), isolate)},
+ {"var x = 10; eval('var x = 20;'); return x;",
+ handle(Smi::FromInt(20), isolate)},
+ {"var x = 1; eval('\"use strict\"; var x = 2;'); return x;",
+ handle(Smi::FromInt(1), isolate)},
+ {"'use strict'; var x = 1; eval('var x = 2;'); return x;",
+ handle(Smi::FromInt(1), isolate)},
+ {"var x = 10; eval('x + 20;'); return typeof x;",
+ factory->NewStringFromStaticChars("number")},
+ {"eval('var y = 10;'); return typeof unallocated;",
+ factory->NewStringFromStaticChars("undefined")},
+ {"'use strict'; eval('var y = 10;'); return typeof unallocated;",
+ factory->NewStringFromStaticChars("undefined")},
+ {"eval('var x = 10;'); return typeof x;",
+ factory->NewStringFromStaticChars("number")},
+ {"var x = {}; eval('var x = 10;'); return typeof x;",
+ factory->NewStringFromStaticChars("number")},
+ {"'use strict'; var x = {}; eval('var x = 10;'); return typeof x;",
+ factory->NewStringFromStaticChars("object")},
+ };
+
+ for (size_t i = 0; i < arraysize(eval); i++) {
+ std::string source(InterpreterTester::SourceForBody(eval[i].first));
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ auto callable = tester.GetCallable<>();
+
+ Handle<i::Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*eval[i].second));
+ }
+}
+
+
+TEST(InterpreterEvalParams) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+
+ std::pair<const char*, Handle<Object>> eval_params[] = {
+ {"var x = 10; return eval('x + p1;');",
+ handle(Smi::FromInt(30), isolate)},
+ {"var x = 10; eval('p1 = x;'); return p1;",
+ handle(Smi::FromInt(10), isolate)},
+ {"var a = 10;"
+ "function inner() { return eval('a + p1;');}"
+ "return inner();",
+ handle(Smi::FromInt(30), isolate)},
+ };
+
+ for (size_t i = 0; i < arraysize(eval_params); i++) {
+ std::string source = "function " + InterpreterTester::function_name() +
+ "(p1) {" + eval_params[i].first + "}";
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ auto callable = tester.GetCallable<Handle<Object>>();
+
+ Handle<i::Object> return_value =
+ callable(handle(Smi::FromInt(20), isolate)).ToHandleChecked();
+ CHECK(return_value->SameValue(*eval_params[i].second));
+ }
+}
+
+
+TEST(InterpreterEvalGlobal) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ std::pair<const char*, Handle<Object>> eval_global[] = {
+ {"function add_global() { eval('function test() { z = 33; }; test()'); };"
+ "function f() { add_global(); return z; }; f();",
+ handle(Smi::FromInt(33), isolate)},
+ {"function add_global() {\n"
+ " eval('\"use strict\"; function test() { y = 33; };"
+ " try { test() } catch(e) {}');\n"
+ "}\n"
+ "function f() { add_global(); return typeof y; } f();",
+ factory->NewStringFromStaticChars("undefined")},
+ };
+
+ for (size_t i = 0; i < arraysize(eval_global); i++) {
+ InterpreterTester tester(handles.main_isolate(), eval_global[i].first,
+ "test");
+ auto callable = tester.GetCallable<>();
+
+ Handle<i::Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*eval_global[i].second));
+ }
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698