OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
| 7 #include "src/base/utils/random-number-generator.h" |
7 #include "src/execution.h" | 8 #include "src/execution.h" |
8 #include "src/handles.h" | 9 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 10 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/interpreter.h" | 11 #include "src/interpreter/interpreter.h" |
11 #include "test/cctest/cctest.h" | 12 #include "test/cctest/cctest.h" |
12 #include "test/cctest/test-feedback-vector.h" | 13 #include "test/cctest/test-feedback-vector.h" |
13 | 14 |
14 namespace v8 { | 15 namespace v8 { |
15 namespace internal { | 16 namespace internal { |
16 namespace interpreter { | 17 namespace interpreter { |
(...skipping 3139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3156 | 3157 |
3157 for (size_t i = 0; i < arraysize(reg_tests); i++) { | 3158 for (size_t i = 0; i < arraysize(reg_tests); i++) { |
3158 InterpreterTester tester(handles.main_isolate(), reg_tests[i].first); | 3159 InterpreterTester tester(handles.main_isolate(), reg_tests[i].first); |
3159 auto callable = tester.GetCallable<>(); | 3160 auto callable = tester.GetCallable<>(); |
3160 | 3161 |
3161 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3162 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3162 CHECK(return_value->SameValue(*reg_tests[i].second)); | 3163 CHECK(return_value->SameValue(*reg_tests[i].second)); |
3163 } | 3164 } |
3164 } | 3165 } |
3165 | 3166 |
| 3167 |
| 3168 TEST(JumpWithConstantsAndWideConstants) { |
| 3169 HandleAndZoneScope handles; |
| 3170 auto isolate = handles.main_isolate(); |
| 3171 auto factory = isolate->factory(); |
| 3172 const int kStep = 19; |
| 3173 int start = isolate->random_number_generator()->NextInt(kStep); |
| 3174 for (int constants = start; constants < 256 + 3 * kStep; constants += kStep) { |
| 3175 std::stringstream os; |
| 3176 // Generate a string that consumes constant pool entries and |
| 3177 // spread out branch distances in script below. |
| 3178 for (int i = 0; i < constants; i++) { |
| 3179 os << "var x_ = 'x_" << i << "';\n"; |
| 3180 } |
| 3181 std::string filler(os.str()); |
| 3182 os.str(""); |
| 3183 os << "function " << InterpreterTester::function_name() << "(a) {\n"; |
| 3184 os << " " << filler; |
| 3185 os << " for (var i = a; i < 2; i++) {\n"; |
| 3186 os << " " << filler; |
| 3187 os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; |
| 3188 os << " else if (i == a) { " << filler << "i = 12; break; }\n"; |
| 3189 os << " else { " << filler << " }\n"; |
| 3190 os << " }\n"; |
| 3191 os << " return i;\n"; |
| 3192 os << "}\n"; |
| 3193 std::string script(os.str()); |
| 3194 for (int a = 0; a < 3; a++) { |
| 3195 InterpreterTester tester(handles.main_isolate(), script.c_str()); |
| 3196 auto callable = tester.GetCallable<Handle<Object>>(); |
| 3197 Handle<Object> return_val = |
| 3198 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); |
| 3199 static const int results[] = {11, 12, 2}; |
| 3200 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
| 3201 } |
| 3202 } |
| 3203 } |
| 3204 |
3166 } // namespace interpreter | 3205 } // namespace interpreter |
3167 } // namespace internal | 3206 } // namespace internal |
3168 } // namespace v8 | 3207 } // namespace v8 |
OLD | NEW |