Index: test/cctest/interpreter/test-interpreter.cc |
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc |
index 3e7a1c470a57c1c73d9e51188827d8eea4837c54..cf936cf88645e4d5a0c51857bb0b2c52a742a2ea 100644 |
--- a/test/cctest/interpreter/test-interpreter.cc |
+++ b/test/cctest/interpreter/test-interpreter.cc |
@@ -4,6 +4,7 @@ |
#include "src/v8.h" |
+#include "src/base/utils/random-number-generator.h" |
#include "src/execution.h" |
#include "src/handles.h" |
#include "src/interpreter/bytecode-array-builder.h" |
@@ -3194,6 +3195,44 @@ TEST(InterpreterDeleteLookupSlot) { |
} |
} |
+ |
+TEST(JumpWithConstantsAndWideConstants) { |
+ HandleAndZoneScope handles; |
+ auto isolate = handles.main_isolate(); |
+ auto factory = isolate->factory(); |
+ const int kStep = 19; |
+ int start = isolate->random_number_generator()->NextInt(kStep); |
+ for (int constants = start; constants < 256 + 3 * kStep; constants += kStep) { |
+ std::stringstream os; |
+ // Generate a string that consumes constant pool entries and |
+ // spread out branch distances in script below. |
+ for (int i = 0; i < constants; i++) { |
+ os << "var x_ = 'x_" << i << "';\n"; |
+ } |
+ std::string filler(os.str()); |
+ os.str(""); |
+ os << "function " << InterpreterTester::function_name() << "(a) {\n"; |
+ os << " " << filler; |
+ os << " for (var i = a; i < 2; i++) {\n"; |
+ os << " " << filler; |
+ os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; |
+ os << " else if (i == a) { " << filler << "i = 12; break; }\n"; |
+ os << " else { " << filler << " }\n"; |
+ os << " }\n"; |
+ os << " return i;\n"; |
+ os << "}\n"; |
+ std::string script(os.str()); |
+ for (int a = 0; a < 3; a++) { |
+ InterpreterTester tester(handles.main_isolate(), script.c_str()); |
+ auto callable = tester.GetCallable<Handle<Object>>(); |
+ Handle<Object> return_val = |
+ callable(factory->NewNumberFromInt(a)).ToHandleChecked(); |
+ static const int results[] = {11, 12, 2}; |
+ CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
+ } |
+ } |
+} |
+ |
} // namespace interpreter |
} // namespace internal |
} // namespace v8 |