Chromium Code Reviews| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 template <int N> | 150 template <int N> |
| 151 struct ExpectedSnippet { | 151 struct ExpectedSnippet { |
| 152 const char* code_snippet; | 152 const char* code_snippet; |
| 153 Handle<Object> return_value_and_parameters[N + 1]; | 153 Handle<Object> return_value_and_parameters[N + 1]; |
| 154 | 154 |
| 155 inline Handle<Object> return_value() const { | 155 inline Handle<Object> return_value() const { |
| 156 return return_value_and_parameters[0]; | 156 return return_value_and_parameters[0]; |
| 157 } | 157 } |
| 158 | 158 |
| 159 inline Handle<Object> parameter(int i) const { | 159 inline Handle<Object> parameter(int i) const { |
| 160 DCHECK_LT(i, N); | |
|
oth
2015/11/12 12:35:21
Probably best to bounds checking at both ends of t
rmcilroy
2015/11/12 13:02:47
Done.
| |
| 160 return return_value_and_parameters[1 + i]; | 161 return return_value_and_parameters[1 + i]; |
| 161 } | 162 } |
| 162 }; | 163 }; |
| 163 | 164 |
| 164 | 165 |
| 165 TEST(BytecodeGraphBuilderReturnStatements) { | 166 TEST(BytecodeGraphBuilderReturnStatements) { |
| 166 HandleAndZoneScope scope; | 167 HandleAndZoneScope scope; |
| 167 Isolate* isolate = scope.main_isolate(); | 168 Isolate* isolate = scope.main_isolate(); |
| 168 Zone* zone = scope.main_zone(); | 169 Zone* zone = scope.main_zone(); |
| 169 Factory* factory = isolate->factory(); | 170 Factory* factory = isolate->factory(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 snippets[i].code_snippet, kFunctionName); | 361 snippets[i].code_snippet, kFunctionName); |
| 361 | 362 |
| 362 BytecodeGraphTester tester(isolate, zone, script.start()); | 363 BytecodeGraphTester tester(isolate, zone, script.start()); |
| 363 auto callable = tester.GetCallable<Handle<Object>>(); | 364 auto callable = tester.GetCallable<Handle<Object>>(); |
| 364 Handle<Object> return_value = | 365 Handle<Object> return_value = |
| 365 callable(snippets[i].parameter(0)).ToHandleChecked(); | 366 callable(snippets[i].parameter(0)).ToHandleChecked(); |
| 366 CHECK(return_value->SameValue(*snippets[i].return_value())); | 367 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 367 } | 368 } |
| 368 } | 369 } |
| 369 | 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 | |
| 370 } // namespace compiler | 417 } // namespace compiler |
| 371 } // namespace internal | 418 } // namespace internal |
| 372 } // namespace v8 | 419 } // namespace v8 |
| OLD | NEW |