diff options
Diffstat (limited to 'deps/v8/test/cctest/interpreter/test-bytecode-generator.cc')
-rw-r--r-- | deps/v8/test/cctest/interpreter/test-bytecode-generator.cc | 265 |
1 files changed, 264 insertions, 1 deletions
diff --git a/deps/v8/test/cctest/interpreter/test-bytecode-generator.cc b/deps/v8/test/cctest/interpreter/test-bytecode-generator.cc index 561d163a692..0ec28d3653f 100644 --- a/deps/v8/test/cctest/interpreter/test-bytecode-generator.cc +++ b/deps/v8/test/cctest/interpreter/test-bytecode-generator.cc @@ -129,6 +129,27 @@ std::string BuildActual(const BytecodeExpectationsPrinter& printer, return actual_stream.str(); } +// inplace left trim +static inline void ltrim(std::string& str) { + str.erase(str.begin(), + std::find_if(str.begin(), str.end(), + [](unsigned char ch) { return !std::isspace(ch); })); +} + +// inplace right trim +static inline void rtrim(std::string& str) { + str.erase(std::find_if(str.rbegin(), str.rend(), + [](unsigned char ch) { return !std::isspace(ch); }) + .base(), + str.end()); +} + +static inline std::string trim(std::string& str) { + ltrim(str); + rtrim(str); + return str; +} + bool CompareTexts(const std::string& generated, const std::string& expected) { std::istringstream generated_stream(generated); std::istringstream expected_stream(expected); @@ -157,7 +178,7 @@ bool CompareTexts(const std::string& generated, const std::string& expected) { return false; } - if (generated_line != expected_line) { + if (trim(generated_line) != trim(expected_line)) { std::cerr << "Inputs differ at line " << line_number << "\n"; std::cerr << " Generated: '" << generated_line << "'\n"; std::cerr << " Expected: '" << expected_line << "'\n"; @@ -411,6 +432,242 @@ TEST(PropertyLoads) { LoadGolden("PropertyLoads.golden"))); } +TEST(PropertyLoadStoreOneShot) { + InitializedIgnitionHandleScope scope; + BytecodeExpectationsPrinter printer(CcTest::isolate()); + printer.set_wrap(false); + printer.set_top_level(true); + printer.set_oneshot_opt(true); + + const char* snippets[] = { + R"( + l = { + 'a': 1, + 'b': 2 + }; + + v = l['a'] + l['b']; + l['b'] = 7; + l['a'] = l['b']; + )", + + R"( + l = { + 'a': 1.1, + 'b': 2.2 + }; + for (i = 0; i < 5; ++i) { + l['a'] = l['a'] + l['b']; + l['b'] = l['a'] + l['b']; + } + )", + + R"( + l = { + 'a': 1.1, + 'b': 2.2 + }; + while (s > 0) { + l['a'] = l['a'] - l['b']; + l['b'] = l['b'] - l['a']; + } + )", + + R"( + l = { + 'a': 1.1, + 'b': 2.2 + }; + s = 10; + do { + l['a'] = l['b'] - l['a']; + } while (s < 10); + )", + + R"( + l = { + 'c': 1.1, + 'd': 2.2 + }; + if (l['c'] < 3) { + l['c'] = 3; + } else { + l['d'] = 3; + } + )", + + R"( + a = [1.1, [2.2, 4.5]]; + )", + + R"( + b = []; + )", + }; + CHECK(CompareTexts(BuildActual(printer, snippets), + LoadGolden("PropertyLoadStoreOneShot.golden"))); +} + +TEST(PropertyLoadStoreWithoutOneShot) { + InitializedIgnitionHandleScope scope; + BytecodeExpectationsPrinter printer(CcTest::isolate()); + printer.set_wrap(false); + printer.set_top_level(true); + + const char* snippets[] = { + R"( + l = { + 'aa': 1.1, + 'bb': 2.2 + }; + + v = l['aa'] + l['bb']; + l['bb'] = 7; + l['aa'] = l['bb']; + )", + + R"( + l = { + 'cc': 3.1, + 'dd': 4.2 + }; + if (l['cc'] < 3) { + l['cc'] = 3; + } else { + l['dd'] = 3; + } + )", + }; + CHECK(CompareTexts(BuildActual(printer, snippets), + LoadGolden("PropertyLoadStoreWithoutOneShot.golden"))); +} + +TEST(IIFEWithOneshotOpt) { + InitializedIgnitionHandleScope scope; + v8::Isolate* isolate = CcTest::isolate(); + BytecodeExpectationsPrinter printer(isolate); + printer.set_wrap(false); + printer.set_top_level(true); + printer.set_print_callee(true); + printer.set_oneshot_opt(true); + + const char* snippets[] = { + // No feedback vectors for top-level loads/store named property in an IIFE + R"( + (function() { + l = {}; + l.aa = 2; + l.bb = l.aa; + return arguments.callee; + })(); + )", + // Normal load/store within loops of an IIFE + R"( + (function() { + l = {}; + for (i = 0; i < 5; ++i) { + l.aa = 2; + l.bb = l.aa; + } + return arguments.callee; + })(); + )", + + R"( + (function() { + l = {}; + c = 4; + while(c > 4) { + l.aa = 2; + l.bb = l.aa; + c--; + } + return arguments.callee; + })(); + )", + + R"( + (function() { + l = {}; + c = 4; + do { + l.aa = 2; + l.bb = l.aa; + c--; + } while(c > 4) + return arguments.callee; + })(); + )", + // No feedback vectors for loads/stores in conditionals + R"( + (function() { + l = { + 'aa': 3.3, + 'bb': 4.4 + }; + if (l.aa < 3) { + l.aa = 3; + } else { + l.aa = l.bb; + } + return arguments.callee; + })(); + )", + + R"( + (function() { + a = [0, [1, 1,2,], 3]; + return arguments.callee; + })(); + )", + + R"( + (function() { + a = []; + return arguments.callee; + })(); + )", + }; + CHECK(CompareTexts(BuildActual(printer, snippets), + LoadGolden("IIFEWithOneshotOpt.golden"))); +} + +TEST(IIFEWithoutOneshotOpt) { + InitializedIgnitionHandleScope scope; + v8::Isolate* isolate = CcTest::isolate(); + BytecodeExpectationsPrinter printer(isolate); + printer.set_wrap(false); + printer.set_top_level(true); + printer.set_print_callee(true); + + const char* snippets[] = { + R"( + (function() { + l = {}; + l.a = 2; + l.b = l.a; + return arguments.callee; + })(); + )", + R"( + (function() { + l = { + 'a': 4.3, + 'b': 3.4 + }; + if (l.a < 3) { + l.a = 3; + } else { + l.a = l.b; + } + return arguments.callee; + })(); + )", + }; + CHECK(CompareTexts(BuildActual(printer, snippets), + LoadGolden("IIFEWithoutOneshotOpt.golden"))); +} + TEST(PropertyStores) { InitializedIgnitionHandleScope scope; BytecodeExpectationsPrinter printer(CcTest::isolate()); @@ -1202,6 +1459,12 @@ TEST(ArrayLiterals) { "return [ [ 1, 2 ], [ 3 ] ];\n", "var a = 1; return [ [ a, 2 ], [ a + 2 ] ];\n", + + "var a = [ 1, 2 ]; return [ ...a ];\n", + + "var a = [ 1, 2 ]; return [ 0, ...a ];\n", + + "var a = [ 1, 2 ]; return [ ...a, 3 ];\n", }; CHECK(CompareTexts(BuildActual(printer, snippets), |