| Index: test/cctest/interpreter/test-interpreter.cc
|
| diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
|
| index c89af183d721ae5ea1892609c26c9669e77e88ec..fdc1f1b07d3a5aa86f3cd9771a8058c28e4b1ac2 100644
|
| --- a/test/cctest/interpreter/test-interpreter.cc
|
| +++ b/test/cctest/interpreter/test-interpreter.cc
|
| @@ -2264,3 +2264,107 @@ TEST(InterpreterCreateArguments) {
|
| CHECK(return_val->SameValue(*args[create_args[i].second]));
|
| }
|
| }
|
| +
|
| +
|
| +TEST(InterpreterForIn) {
|
| + HandleAndZoneScope handles;
|
| +
|
| + // TODO(oth): Add a test here for delete mid-loop when delete is ready.
|
| + std::pair<const char*, int> for_in_samples[] = {
|
| + {"function f() {\n"
|
| + " var r = -1;\n"
|
| + " for (var a in null) { r = a; }\n"
|
| + " return r;\n"
|
| + "}",
|
| + -1},
|
| + {"function f() {\n"
|
| + " var r = -1;\n"
|
| + " for (var a in undefined) { r = a; }\n"
|
| + " return r;\n"
|
| + "}",
|
| + -1},
|
| + {"function f() {\n"
|
| + " var r = 0;\n"
|
| + " for (var a in [0,6,7,9]) { r = r + (1 << a); }\n"
|
| + " return r;\n"
|
| + "}",
|
| + 0xf},
|
| + {"function f() {\n"
|
| + " var r = 0;\n"
|
| + " for (var a in [0,6,7,9]) { r = r + (1 << a); }\n"
|
| + " var r = 0;\n"
|
| + " for (var a in [0,6,7,9]) { r = r + (1 << a); }\n"
|
| + " return r;\n"
|
| + "}",
|
| + 0xf},
|
| + {"function f() {\n"
|
| + " var r = 0;\n"
|
| + " for (var a in 'foobar') { r = r + (1 << a); }\n"
|
| + " return r;\n"
|
| + "}",
|
| + 0x3f},
|
| + {"function f() {\n"
|
| + " var r = 0;\n"
|
| + " for (var a in {1:0, 10:1, 100:2, 1000:3}) {\n"
|
| + " r = r + Number(a);\n"
|
| + " }\n"
|
| + " return r;\n"
|
| + "}",
|
| + 1111},
|
| + {"function f() {\n"
|
| + " var r = 0;\n"
|
| + " var input = 'foobar';\n"
|
| + " for (var a in input) {\n"
|
| + " if (input[a] == 'b') break;\n"
|
| + " r = r + (1 << a);\n"
|
| + " }\n"
|
| + " return r;\n"
|
| + "}",
|
| + 0x7},
|
| + {"function f() {\n"
|
| + "var r = 0;\n"
|
| + "var input = 'foobar';\n"
|
| + "for (var a in input) {\n"
|
| + " if (input[a] == 'b') continue;\n"
|
| + " r = r + (1 << a);\n"
|
| + "}\n"
|
| + "return r;\n"
|
| + "}",
|
| + 0x37},
|
| + {"function f() {\n"
|
| + " var r = 0;\n"
|
| + " var data = {1:0, 10:1, 100:2, 1000:3};\n"
|
| + " for (var a in data) {\n"
|
| + " if (a == 10) {\n"
|
| + " data[10000] = 4;\n"
|
| + " }\n"
|
| + " r = r + Number(a);\n"
|
| + " }\n"
|
| + " return r;\n"
|
| + "}",
|
| + 1111},
|
| + {"function f() {\n"
|
| + " var r = [ 3 ];\n"
|
| + " var data = {1:0, 10:1, 100:2, 1000:3};\n"
|
| + " for (r[10] in data) {\n"
|
| + " }\n"
|
| + " return Number(r[10]);\n"
|
| + "}",
|
| + 1000},
|
| + {"function f() {\n"
|
| + " var r = [ 3 ];\n"
|
| + " var data = {1:0, 10:1, 100:2, 1000:3};\n"
|
| + " for (r['100'] in data) {\n"
|
| + " }\n"
|
| + " return Number(r['100']);\n"
|
| + "}",
|
| + 1000},
|
| + };
|
| +
|
| + for (size_t i = 0; i < arraysize(for_in_samples); i++) {
|
| + InterpreterTester tester(handles.main_isolate(), for_in_samples[i].first);
|
| + auto callable = tester.GetCallable<>();
|
| + Handle<Object> return_val = callable().ToHandleChecked();
|
| + CHECK_EQ(Handle<Smi>::cast(return_val)->value(), for_in_samples[i].second);
|
| + }
|
| +}
|
|
|