| 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 // TODO(jochen): Remove this after the setting is turned on globally. | 5 // TODO(jochen): Remove this after the setting is turned on globally. |
| 6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "src/compiler/pipeline.h" | 10 #include "src/compiler/pipeline.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 template <int N> | 149 template <int N> |
| 150 struct ExpectedSnippet { | 150 struct ExpectedSnippet { |
| 151 const char* code_snippet; | 151 const char* code_snippet; |
| 152 Handle<Object> return_value_and_parameters[N + 1]; | 152 Handle<Object> return_value_and_parameters[N + 1]; |
| 153 | 153 |
| 154 inline Handle<Object> return_value() const { | 154 inline Handle<Object> return_value() const { |
| 155 return return_value_and_parameters[0]; | 155 return return_value_and_parameters[0]; |
| 156 } | 156 } |
| 157 | 157 |
| 158 inline Handle<Object> parameter(int i) const { | 158 inline Handle<Object> parameter(int i) const { |
| 159 DCHECK_GE(i, 0); |
| 160 DCHECK_LT(i, N); |
| 159 return return_value_and_parameters[1 + i]; | 161 return return_value_and_parameters[1 + i]; |
| 160 } | 162 } |
| 161 }; | 163 }; |
| 162 | 164 |
| 163 | 165 |
| 164 TEST(BytecodeGraphBuilderReturnStatements) { | 166 TEST(BytecodeGraphBuilderReturnStatements) { |
| 165 HandleAndZoneScope scope; | 167 HandleAndZoneScope scope; |
| 166 Isolate* isolate = scope.main_isolate(); | 168 Isolate* isolate = scope.main_isolate(); |
| 167 Zone* zone = scope.main_zone(); | 169 Zone* zone = scope.main_zone(); |
| 168 Factory* factory = isolate->factory(); | 170 Factory* factory = isolate->factory(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 snippets[i].code_snippet, kFunctionName); | 361 snippets[i].code_snippet, kFunctionName); |
| 360 | 362 |
| 361 BytecodeGraphTester tester(isolate, zone, script.start()); | 363 BytecodeGraphTester tester(isolate, zone, script.start()); |
| 362 auto callable = tester.GetCallable<Handle<Object>>(); | 364 auto callable = tester.GetCallable<Handle<Object>>(); |
| 363 Handle<Object> return_value = | 365 Handle<Object> return_value = |
| 364 callable(snippets[i].parameter(0)).ToHandleChecked(); | 366 callable(snippets[i].parameter(0)).ToHandleChecked(); |
| 365 CHECK(return_value->SameValue(*snippets[i].return_value())); | 367 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 366 } | 368 } |
| 367 } | 369 } |
| 368 | 370 |
| 371 |
| 372 TEST(BytecodeGraphBuilderGlobals) { |
| 373 HandleAndZoneScope scope; |
| 374 Isolate* isolate = scope.main_isolate(); |
| 375 Zone* zone = scope.main_zone(); |
| 376 Factory* factory = isolate->factory(); |
| 377 |
| 378 ExpectedSnippet<0> snippets[] = { |
| 379 {"var global = 321;\n function f() { return global; };\n f();", |
| 380 {factory->NewNumberFromInt(321)}}, |
| 381 {"var global = 321;\n" |
| 382 "function f() { global = 123; return global };\n f();", |
| 383 {factory->NewNumberFromInt(123)}}, |
| 384 {"var global = function() { return 'abc'};\n" |
| 385 "function f() { return global(); };\n f();", |
| 386 {factory->NewStringFromStaticChars("abc")}}, |
| 387 {"var global = 456;\n" |
| 388 "function f() { 'use strict'; return global; };\n f();", |
| 389 {factory->NewNumberFromInt(456)}}, |
| 390 {"var global = 987;\n" |
| 391 "function f() { 'use strict'; global = 789; return global };\n f();", |
| 392 {factory->NewNumberFromInt(789)}}, |
| 393 {"var global = function() { return 'xyz'};\n" |
| 394 "function f() { 'use strict'; return global(); };\n f();", |
| 395 {factory->NewStringFromStaticChars("xyz")}}, |
| 396 {"var global = 'abc'; var global_obj = {val:123};\n" |
| 397 "function f() {\n" REPEAT_127( |
| 398 SPACE, " var b = global_obj.name;\n") "return global; };\n f();\n", |
| 399 {factory->NewStringFromStaticChars("abc")}}, |
| 400 {"var global = 'abc'; var global_obj = {val:123};\n" |
| 401 "function f() { 'use strict';\n" REPEAT_127( |
| 402 SPACE, " var b = global_obj.name;\n") "global = 'xyz'; return " |
| 403 "global };\n f();\n", |
| 404 {factory->NewStringFromStaticChars("xyz")}}, |
| 405 // TODO(rmcilroy): Add tests for typeof_mode once we have typeof support. |
| 406 }; |
| 407 |
| 408 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
| 409 for (size_t i = 0; i < num_snippets; i++) { |
| 410 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
| 411 auto callable = tester.GetCallable<>(); |
| 412 Handle<Object> return_value = callable().ToHandleChecked(); |
| 413 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 414 } |
| 415 } |
| 416 |
| 369 } // namespace compiler | 417 } // namespace compiler |
| 370 } // namespace internal | 418 } // namespace internal |
| 371 } // namespace v8 | 419 } // namespace v8 |
| OLD | NEW |