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/execution.h" | 7 #include "src/execution.h" |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); | 506 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); |
507 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); | 507 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); |
508 // Check for Smis. | 508 // Check for Smis. |
509 Handle<Object> return_val = | 509 Handle<Object> return_val = |
510 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) | 510 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) |
511 .ToHandleChecked(); | 511 .ToHandleChecked(); |
512 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); | 512 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); |
513 } | 513 } |
514 | 514 |
515 | 515 |
| 516 TEST(InterpreterParameter1Assign) { |
| 517 HandleAndZoneScope handles; |
| 518 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 519 builder.set_locals_count(0); |
| 520 builder.set_parameter_count(1); |
| 521 builder.LoadLiteral(Smi::FromInt(5)) |
| 522 .StoreAccumulatorInRegister(builder.Parameter(0)) |
| 523 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
| 524 .Return(); |
| 525 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 526 |
| 527 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 528 auto callable = tester.GetCallable<Handle<Object>>(); |
| 529 |
| 530 Handle<Object> return_val = |
| 531 callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) |
| 532 .ToHandleChecked(); |
| 533 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); |
| 534 } |
| 535 |
| 536 |
516 TEST(InterpreterLoadGlobal) { | 537 TEST(InterpreterLoadGlobal) { |
517 HandleAndZoneScope handles; | 538 HandleAndZoneScope handles; |
518 | 539 |
519 // Test loading a global. | 540 // Test loading a global. |
520 std::string source( | 541 std::string source( |
521 "var global = 321;\n" | 542 "var global = 321;\n" |
522 "function " + InterpreterTester::function_name() + "() {\n" | 543 "function " + InterpreterTester::function_name() + "() {\n" |
523 " return global;\n" | 544 " return global;\n" |
524 "}"); | 545 "}"); |
525 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 546 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
526 auto callable = tester.GetCallable<>(); | 547 auto callable = tester.GetCallable<>(); |
527 | 548 |
528 Handle<Object> return_val = callable().ToHandleChecked(); | 549 Handle<Object> return_val = callable().ToHandleChecked(); |
529 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321)); | 550 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321)); |
530 } | 551 } |
531 | 552 |
532 | 553 |
| 554 TEST(InterpreterStoreGlobal) { |
| 555 HandleAndZoneScope handles; |
| 556 i::Isolate* isolate = handles.main_isolate(); |
| 557 i::Factory* factory = isolate->factory(); |
| 558 |
| 559 // Test storing to a global. |
| 560 std::string source( |
| 561 "var global = 321;\n" |
| 562 "function " + InterpreterTester::function_name() + "() {\n" |
| 563 " global = 999;\n" |
| 564 "}"); |
| 565 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 566 auto callable = tester.GetCallable<>(); |
| 567 |
| 568 callable().ToHandleChecked(); |
| 569 Handle<i::String> name = factory->InternalizeUtf8String("global"); |
| 570 Handle<i::Object> global_obj = |
| 571 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); |
| 572 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); |
| 573 } |
| 574 |
| 575 |
533 TEST(InterpreterCallGlobal) { | 576 TEST(InterpreterCallGlobal) { |
534 HandleAndZoneScope handles; | 577 HandleAndZoneScope handles; |
535 | 578 |
536 // Test calling a global function. | 579 // Test calling a global function. |
537 std::string source( | 580 std::string source( |
538 "function g_add(a, b) { return a + b; }\n" | 581 "function g_add(a, b) { return a + b; }\n" |
539 "function " + InterpreterTester::function_name() + "() {\n" | 582 "function " + InterpreterTester::function_name() + "() {\n" |
540 " return g_add(5, 10);\n" | 583 " return g_add(5, 10);\n" |
541 "}"); | 584 "}"); |
542 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 585 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
543 auto callable = tester.GetCallable<>(); | 586 auto callable = tester.GetCallable<>(); |
544 | 587 |
545 Handle<Object> return_val = callable().ToHandleChecked(); | 588 Handle<Object> return_val = callable().ToHandleChecked(); |
546 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); | 589 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
547 } | 590 } |
548 | 591 |
549 | 592 |
| 593 TEST(InterpreterLoadUnallocated) { |
| 594 HandleAndZoneScope handles; |
| 595 |
| 596 // Test loading an unallocated global. |
| 597 std::string source( |
| 598 "unallocated = 123;\n" |
| 599 "function " + InterpreterTester::function_name() + "() {\n" |
| 600 " return unallocated;\n" |
| 601 "}"); |
| 602 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 603 auto callable = tester.GetCallable<>(); |
| 604 |
| 605 Handle<Object> return_val = callable().ToHandleChecked(); |
| 606 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
| 607 } |
| 608 |
| 609 |
| 610 TEST(InterpreterStoreUnallocated) { |
| 611 HandleAndZoneScope handles; |
| 612 i::Isolate* isolate = handles.main_isolate(); |
| 613 i::Factory* factory = isolate->factory(); |
| 614 |
| 615 // Test storing to an unallocated global. |
| 616 std::string source( |
| 617 "unallocated = 321;\n" |
| 618 "function " + InterpreterTester::function_name() + "() {\n" |
| 619 " unallocated = 999;\n" |
| 620 "}"); |
| 621 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 622 auto callable = tester.GetCallable<>(); |
| 623 |
| 624 callable().ToHandleChecked(); |
| 625 Handle<i::String> name = factory->InternalizeUtf8String("unallocated"); |
| 626 Handle<i::Object> global_obj = |
| 627 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); |
| 628 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); |
| 629 } |
| 630 |
| 631 |
550 TEST(InterpreterLoadNamedProperty) { | 632 TEST(InterpreterLoadNamedProperty) { |
551 HandleAndZoneScope handles; | 633 HandleAndZoneScope handles; |
552 i::Isolate* isolate = handles.main_isolate(); | 634 i::Isolate* isolate = handles.main_isolate(); |
553 i::Factory* factory = isolate->factory(); | 635 i::Factory* factory = isolate->factory(); |
554 | 636 |
555 i::Code::Kind ic_kinds[] = {i::Code::LOAD_IC}; | 637 i::Code::Kind ic_kinds[] = {i::Code::LOAD_IC}; |
556 i::FeedbackVectorSpec feedback_spec(0, 1, ic_kinds); | 638 i::FeedbackVectorSpec feedback_spec(0, 1, ic_kinds); |
557 Handle<i::TypeFeedbackVector> vector = | 639 Handle<i::TypeFeedbackVector> vector = |
558 factory->NewTypeFeedbackVector(&feedback_spec); | 640 factory->NewTypeFeedbackVector(&feedback_spec); |
559 | 641 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1071 .CallRuntime(Runtime::kAdd, Register(0), 2) |
990 .Return(); | 1072 .Return(); |
991 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1073 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
992 | 1074 |
993 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1075 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
994 auto callable = tester.GetCallable<>(); | 1076 auto callable = tester.GetCallable<>(); |
995 | 1077 |
996 Handle<Object> return_val = callable().ToHandleChecked(); | 1078 Handle<Object> return_val = callable().ToHandleChecked(); |
997 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1079 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
998 } | 1080 } |
OLD | NEW |