| Index: test/cctest/interpreter/test-source-positions.cc
|
| diff --git a/test/cctest/interpreter/test-source-positions.cc b/test/cctest/interpreter/test-source-positions.cc
|
| index 20bb4404d9cbb652c3cb934bd81a5851a6e132f7..d50bb62b2b31ca9c4de77d112dd27c0020695419 100644
|
| --- a/test/cctest/interpreter/test-source-positions.cc
|
| +++ b/test/cctest/interpreter/test-source-positions.cc
|
| @@ -19,9 +19,11 @@ namespace interpreter {
|
|
|
| // Flags enabling optimizations that change generated bytecode array.
|
| // Format is <command-line flag> <flag name> <bit index>
|
| -#define OPTIMIZATION_FLAGS(V) \
|
| - V(FLAG_ignition_reo, kUseReo, 0) \
|
| - V(FLAG_ignition_peephole, kUsePeephole, 1)
|
| +#define OPTIMIZATION_FLAGS(V) \
|
| + V(FLAG_ignition_reo, kUseReo, 0) \
|
| + V(FLAG_ignition_peephole, kUsePeephole, 1) \
|
| + V(FLAG_ignition_filter_expression_positions, \
|
| + kUseUseFilterExpressionPositions, 2)
|
|
|
| #define DECLARE_BIT(_, Name, BitIndex) static const int Name = 1 << BitIndex;
|
| OPTIMIZATION_FLAGS(DECLARE_BIT)
|
| @@ -30,73 +32,89 @@ OPTIMIZATION_FLAGS(DECLARE_BIT)
|
| // Test cases source positions are checked for. Please ensure all
|
| // combinations of flags are present here. This is done manually
|
| // because it provides easier to comprehend failure case for humans.
|
| -#define TEST_CASES(V) \
|
| - V(UsingReo, kUseReo) \
|
| - V(UsingReoAndPeephole, kUseReo | kUsePeephole) \
|
| - V(UsingPeephole, kUsePeephole)
|
| -
|
| -static const char* kTestScripts[] = {
|
| - "var x = (y = 3) + (x = y); return x + y;",
|
| -
|
| - "var x = 55;\n"
|
| - "var y = x + (x = 1) + (x = 2) + (x = 3);\n"
|
| - "return y;",
|
| -
|
| - "var x = 10; return x >>> 3;",
|
| -
|
| - "var x = 0; return x || (1, 2, 3);",
|
| -
|
| - "return a || (a, b, a, b, c = 5, 3); ",
|
| -
|
| - "var a = 3; var b = 4; a = b; b = a; a = b; return a;",
|
| -
|
| - "var a = 1; return [[a, 2], [a + 2]];",
|
| -
|
| - "var a = 1; if (a || a < 0) { return 1; }",
|
| -
|
| - "var b;"
|
| - "b = a.name;"
|
| - "b = a.name;"
|
| - "a.name = a;"
|
| - "b = a.name;"
|
| - "a.name = a;"
|
| - "return b;",
|
| -
|
| - "var sum = 0;\n"
|
| - "outer: {\n"
|
| - " for (var x = 0; x < 10; ++x) {\n"
|
| - " for (var y = 0; y < 3; ++y) {\n"
|
| - " ++sum;\n"
|
| - " if (x + y == 12) { break outer; }\n"
|
| - " }\n"
|
| - " }\n"
|
| - "}\n"
|
| - "return sum;\n",
|
| -
|
| - "var a = 1;"
|
| - "switch (a) {"
|
| - " case 1: return a * a + 1;"
|
| - " case 1: break;"
|
| - " case 2: return (a = 3) * a + (a = 4);"
|
| - " case 3:"
|
| - "}"
|
| - "return a;",
|
| -
|
| - "for (var p of [0, 1, 2]) {}",
|
| -
|
| - "var x = { 'a': 1, 'b': 2 };"
|
| - "for (x['a'] of [1,2,3]) { return x['a']; }",
|
| -
|
| - "while (x == 4) {\n"
|
| - " var y = x + 1;\n"
|
| - " if (y == 2) break;\n"
|
| - " for (z['a'] of [0]) {\n"
|
| - " x += (x *= 3) + y;"
|
| - " }\n"
|
| - "}\n",
|
| -
|
| - "function g(a, b) { return a.func(b + b, b); }\n"
|
| - "g(new (function Obj() { this.func = function() { return; }})(), 1)\n"};
|
| +#define TEST_CASES(V) \
|
| + V(UsingReo, kUseReo) \
|
| + V(UsingPeephole, kUsePeephole) \
|
| + V(UsingReoAndPeephole, kUseReo | kUsePeephole) \
|
| + V(UsingUseFilterExpressionPositions, kUseUseFilterExpressionPositions) \
|
| + V(UsingReoAndUseFilterExpressionPositions, \
|
| + kUseReo | kUseUseFilterExpressionPositions) \
|
| + V(UsingPeepholeAndUseFilterExpressionPositions, \
|
| + kUsePeephole | kUseUseFilterExpressionPositions) \
|
| + V(UsingAllOptimizations, \
|
| + kUseReo | kUsePeephole | kUseUseFilterExpressionPositions)
|
| +
|
| +struct TestCaseData {
|
| + TestCaseData(const char* const script,
|
| + const char* const declaration_parameters = "",
|
| + const char* const arguments = "")
|
| + : script_(script),
|
| + declaration_parameters_(declaration_parameters),
|
| + arguments_(arguments) {}
|
| +
|
| + const char* const script() const { return script_; }
|
| + const char* const declaration_parameters() const {
|
| + return declaration_parameters_;
|
| + }
|
| + const char* const arguments() const { return arguments_; }
|
| +
|
| + private:
|
| + TestCaseData();
|
| +
|
| + const char* const script_;
|
| + const char* const declaration_parameters_;
|
| + const char* const arguments_;
|
| +};
|
| +
|
| +static const TestCaseData kTestCaseData[] = {
|
| + {"var x = (y = 3) + (x = y); return x + y;"},
|
| + {"var x = 55;\n"
|
| + "var y = x + (x = 1) + (x = 2) + (x = 3);\n"
|
| + "return y;"},
|
| + {"var x = 10; return x >>> 3;\n"},
|
| + {"var x = 0; return x || (1, 2, 3);\n"},
|
| + {"return a || (a, b, a, b, c = 5, 3);\n"},
|
| + {"var a = 3; var b = 4; a = b; b = a; a = b; return a;\n"},
|
| + {"var a = 1; return [[a, 2], [a + 2]];\n"},
|
| + {"var a = 1; if (a || a < 0) { return 1; }\n"},
|
| + {"var b;"
|
| + "b = a.name;"
|
| + "b = a.name;"
|
| + "a.name = a;"
|
| + "b = a.name;"
|
| + "a.name = a;"
|
| + "return b;"},
|
| + {"var sum = 0;\n"
|
| + "outer: {\n"
|
| + " for (var x = 0; x < 10; ++x) {\n"
|
| + " for (var y = 0; y < 3; ++y) {\n"
|
| + " ++sum;\n"
|
| + " if (x + y == 12) { break outer; }\n"
|
| + " }\n"
|
| + " }\n"
|
| + "}\n"
|
| + "return sum;\n"},
|
| + {"var a = 1;"
|
| + "switch (a) {"
|
| + " case 1: return a * a + 1;"
|
| + " case 1: break;"
|
| + " case 2: return (a = 3) * a + (a = 4);"
|
| + " case 3:"
|
| + "}"
|
| + "return a;"},
|
| + {"for (var p of [0, 1, 2]) {}"},
|
| + {"var x = { 'a': 1, 'b': 2 };"
|
| + "for (x['a'] of [1,2,3]) { return x['a']; }"},
|
| + {"while (x == 4) {\n"
|
| + " var y = x + 1;\n"
|
| + " if (y == 2) break;\n"
|
| + " for (z['a'] of [0]) {\n"
|
| + " x += (x *= 3) + y;"
|
| + " }\n"
|
| + "}\n"},
|
| + {"function g(a, b) { return a.func(b + b, b); }\n"
|
| + "g(new (function Obj() { this.func = function() { return; }})(), 1)\n"},
|
| + {"return some_global[name];", "name", "'a'"}};
|
|
|
| class OptimizedBytecodeSourcePositionTester final {
|
| public:
|
| @@ -116,8 +134,8 @@ class OptimizedBytecodeSourcePositionTester final {
|
| }
|
|
|
| bool SourcePositionsMatch(int optimization_bitmap, const char* function_body,
|
| - const char* function_decl_params = "",
|
| - const char* function_args = "");
|
| + const char* function_decl_params,
|
| + const char* function_args);
|
|
|
| private:
|
| Handle<BytecodeArray> MakeBytecode(int optimization_bitmap,
|
| @@ -220,8 +238,10 @@ void TestSourcePositionsEquivalent(int optimization_bitmap) {
|
| handles.main_isolate()->interpreter()->Initialize();
|
|
|
| OptimizedBytecodeSourcePositionTester tester(handles.main_isolate());
|
| - for (auto test_script : kTestScripts) {
|
| - CHECK(tester.SourcePositionsMatch(optimization_bitmap, test_script));
|
| + for (auto test_case_data : kTestCaseData) {
|
| + CHECK(tester.SourcePositionsMatch(
|
| + optimization_bitmap, test_case_data.script(),
|
| + test_case_data.declaration_parameters(), test_case_data.arguments()));
|
| }
|
| }
|
|
|
|
|