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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 }; | 58 }; |
59 | 59 |
60 | 60 |
61 class BytecodeGraphTester { | 61 class BytecodeGraphTester { |
62 public: | 62 public: |
63 BytecodeGraphTester(Isolate* isolate, Zone* zone, const char* script) | 63 BytecodeGraphTester(Isolate* isolate, Zone* zone, const char* script) |
64 : isolate_(isolate), zone_(zone), script_(script) { | 64 : isolate_(isolate), zone_(zone), script_(script) { |
65 i::FLAG_ignition = true; | 65 i::FLAG_ignition = true; |
66 i::FLAG_always_opt = false; | 66 i::FLAG_always_opt = false; |
67 i::FLAG_vector_stores = true; | 67 i::FLAG_vector_stores = true; |
| 68 i::FLAG_allow_natives_syntax = true; |
68 // Set ignition filter flag via SetFlagsFromString to avoid double-free | 69 // Set ignition filter flag via SetFlagsFromString to avoid double-free |
69 // (or potential leak with StrDup() based on ownership confusion). | 70 // (or potential leak with StrDup() based on ownership confusion). |
70 ScopedVector<char> ignition_filter(64); | 71 ScopedVector<char> ignition_filter(64); |
71 SNPrintF(ignition_filter, "--ignition-filter=%s", kFunctionName); | 72 SNPrintF(ignition_filter, "--ignition-filter=%s", kFunctionName); |
72 FlagList::SetFlagsFromString(ignition_filter.start(), | 73 FlagList::SetFlagsFromString(ignition_filter.start(), |
73 ignition_filter.length()); | 74 ignition_filter.length()); |
74 // Ensure handler table is generated. | 75 // Ensure handler table is generated. |
75 isolate->interpreter()->Initialize(); | 76 isolate->interpreter()->Initialize(); |
76 } | 77 } |
77 virtual ~BytecodeGraphTester() {} | 78 virtual ~BytecodeGraphTester() {} |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 363 |
363 BytecodeGraphTester tester(isolate, zone, script.start()); | 364 BytecodeGraphTester tester(isolate, zone, script.start()); |
364 auto callable = tester.GetCallable<Handle<Object>>(); | 365 auto callable = tester.GetCallable<Handle<Object>>(); |
365 Handle<Object> return_value = | 366 Handle<Object> return_value = |
366 callable(snippets[i].parameter(0)).ToHandleChecked(); | 367 callable(snippets[i].parameter(0)).ToHandleChecked(); |
367 CHECK(return_value->SameValue(*snippets[i].return_value())); | 368 CHECK(return_value->SameValue(*snippets[i].return_value())); |
368 } | 369 } |
369 } | 370 } |
370 | 371 |
371 | 372 |
| 373 TEST(BytecodeGraphBuilderCallNew) { |
| 374 HandleAndZoneScope scope; |
| 375 Isolate* isolate = scope.main_isolate(); |
| 376 Zone* zone = scope.main_zone(); |
| 377 Factory* factory = isolate->factory(); |
| 378 |
| 379 ExpectedSnippet<0> snippets[] = { |
| 380 {"function counter() { this.count = 20; }\n" |
| 381 "function f() {\n" |
| 382 " var c = new counter();\n" |
| 383 " return c.count;\n" |
| 384 "}; f()", |
| 385 {factory->NewNumberFromInt(20)}}, |
| 386 {"function counter(arg0) { this.count = 17; this.x = arg0; }\n" |
| 387 "function f() {\n" |
| 388 " var c = new counter(6);\n" |
| 389 " return c.count + c.x;\n" |
| 390 "}; f()", |
| 391 {factory->NewNumberFromInt(23)}}, |
| 392 {"function counter(arg0, arg1) {\n" |
| 393 " this.count = 17; this.x = arg0; this.y = arg1;\n" |
| 394 "}\n" |
| 395 "function f() {\n" |
| 396 " var c = new counter(3, 5);\n" |
| 397 " return c.count + c.x + c.y;\n" |
| 398 "}; f()", |
| 399 {factory->NewNumberFromInt(25)}}, |
| 400 }; |
| 401 |
| 402 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
| 403 for (size_t i = 0; i < num_snippets; i++) { |
| 404 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
| 405 auto callable = tester.GetCallable<>(); |
| 406 Handle<Object> return_value = callable().ToHandleChecked(); |
| 407 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 408 } |
| 409 } |
| 410 |
| 411 |
| 412 TEST(BytecodeGraphBuilderCallRuntime) { |
| 413 HandleAndZoneScope scope; |
| 414 Isolate* isolate = scope.main_isolate(); |
| 415 Zone* zone = scope.main_zone(); |
| 416 Factory* factory = isolate->factory(); |
| 417 |
| 418 ExpectedSnippet<1> snippets[] = { |
| 419 {"function f(arg0) { return %MaxSmi(); }\nf()", |
| 420 {factory->NewNumberFromInt(Smi::kMaxValue), factory->undefined_value()}}, |
| 421 {"function f(arg0) { return %IsArray(arg0) }\nf(undefined)", |
| 422 {factory->true_value(), BytecodeGraphTester::NewObject("[1, 2, 3]")}}, |
| 423 {"function f(arg0) { return %Add(arg0, 2) }\nf(1)", |
| 424 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(3)}}, |
| 425 {"function f(arg0) { return %spread_arguments(arg0).length }\nf([])", |
| 426 {factory->NewNumberFromInt(3), |
| 427 BytecodeGraphTester::NewObject("[1, 2, 3]")}}, |
| 428 }; |
| 429 |
| 430 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
| 431 for (size_t i = 0; i < num_snippets; i++) { |
| 432 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
| 433 auto callable = tester.GetCallable<Handle<Object>>(); |
| 434 Handle<Object> return_value = |
| 435 callable(snippets[i].parameter(0)).ToHandleChecked(); |
| 436 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 437 } |
| 438 } |
| 439 |
| 440 |
372 TEST(BytecodeGraphBuilderGlobals) { | 441 TEST(BytecodeGraphBuilderGlobals) { |
373 HandleAndZoneScope scope; | 442 HandleAndZoneScope scope; |
374 Isolate* isolate = scope.main_isolate(); | 443 Isolate* isolate = scope.main_isolate(); |
375 Zone* zone = scope.main_zone(); | 444 Zone* zone = scope.main_zone(); |
376 Factory* factory = isolate->factory(); | 445 Factory* factory = isolate->factory(); |
377 | 446 |
378 ExpectedSnippet<0> snippets[] = { | 447 ExpectedSnippet<0> snippets[] = { |
379 {"var global = 321;\n function f() { return global; };\n f();", | 448 {"var global = 321;\n function f() { return global; };\n f();", |
380 {factory->NewNumberFromInt(321)}}, | 449 {factory->NewNumberFromInt(321)}}, |
381 {"var global = 321;\n" | 450 {"var global = 321;\n" |
(...skipping 13 matching lines...) Expand all Loading... |
395 {factory->NewStringFromStaticChars("xyz")}}, | 464 {factory->NewStringFromStaticChars("xyz")}}, |
396 {"var global = 'abc'; var global_obj = {val:123};\n" | 465 {"var global = 'abc'; var global_obj = {val:123};\n" |
397 "function f() {\n" REPEAT_127( | 466 "function f() {\n" REPEAT_127( |
398 SPACE, " var b = global_obj.name;\n") "return global; };\n f();\n", | 467 SPACE, " var b = global_obj.name;\n") "return global; };\n f();\n", |
399 {factory->NewStringFromStaticChars("abc")}}, | 468 {factory->NewStringFromStaticChars("abc")}}, |
400 {"var global = 'abc'; var global_obj = {val:123};\n" | 469 {"var global = 'abc'; var global_obj = {val:123};\n" |
401 "function f() { 'use strict';\n" REPEAT_127( | 470 "function f() { 'use strict';\n" REPEAT_127( |
402 SPACE, " var b = global_obj.name;\n") "global = 'xyz'; return " | 471 SPACE, " var b = global_obj.name;\n") "global = 'xyz'; return " |
403 "global };\n f();\n", | 472 "global };\n f();\n", |
404 {factory->NewStringFromStaticChars("xyz")}}, | 473 {factory->NewStringFromStaticChars("xyz")}}, |
405 // TODO(rmcilroy): Add tests for typeof_mode once we have typeof support. | 474 // TODO(rmcilroy): Add tests for typeof_mode once we have typeof support. |
406 }; | 475 }; |
407 | 476 |
408 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); | 477 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
409 for (size_t i = 0; i < num_snippets; i++) { | 478 for (size_t i = 0; i < num_snippets; i++) { |
410 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); | 479 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
411 auto callable = tester.GetCallable<>(); | 480 auto callable = tester.GetCallable<>(); |
412 Handle<Object> return_value = callable().ToHandleChecked(); | 481 Handle<Object> return_value = callable().ToHandleChecked(); |
413 CHECK(return_value->SameValue(*snippets[i].return_value())); | 482 CHECK(return_value->SameValue(*snippets[i].return_value())); |
414 } | 483 } |
415 } | 484 } |
416 | 485 |
417 } // namespace compiler | 486 } // namespace compiler |
418 } // namespace internal | 487 } // namespace internal |
419 } // namespace v8 | 488 } // namespace v8 |
OLD | NEW |