Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1378523005: [Interpreter] Add support for global declarations and load/store of global variables (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_toplevel
Patch Set: Fix test Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); 548 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate());
549 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); 549 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate());
550 // Check for Smis. 550 // Check for Smis.
551 Handle<Object> return_val = 551 Handle<Object> return_val =
552 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) 552 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
553 .ToHandleChecked(); 553 .ToHandleChecked();
554 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); 554 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36));
555 } 555 }
556 556
557 557
558 TEST(InterpreterParameter1Assign) {
559 HandleAndZoneScope handles;
560 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
561 builder.set_locals_count(0);
562 builder.set_parameter_count(1);
563 builder.LoadLiteral(Smi::FromInt(5))
564 .StoreAccumulatorInRegister(builder.Parameter(0))
565 .LoadAccumulatorWithRegister(builder.Parameter(0))
566 .Return();
567 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
568
569 InterpreterTester tester(handles.main_isolate(), bytecode_array);
570 auto callable = tester.GetCallable<Handle<Object>>();
571
572 Handle<Object> return_val =
573 callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate()))
574 .ToHandleChecked();
575 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5));
576 }
577
578
558 TEST(InterpreterLoadGlobal) { 579 TEST(InterpreterLoadGlobal) {
559 HandleAndZoneScope handles; 580 HandleAndZoneScope handles;
560 581
561 // Test loading a global. 582 // Test loading a global.
562 std::string source( 583 std::string source(
563 "var global = 321;\n" 584 "var global = 321;\n"
564 "function " + InterpreterTester::function_name() + "() {\n" 585 "function " + InterpreterTester::function_name() + "() {\n"
565 " return global;\n" 586 " return global;\n"
566 "}"); 587 "}");
567 InterpreterTester tester(handles.main_isolate(), source.c_str()); 588 InterpreterTester tester(handles.main_isolate(), source.c_str());
568 auto callable = tester.GetCallable<>(); 589 auto callable = tester.GetCallable<>();
569 590
570 Handle<Object> return_val = callable().ToHandleChecked(); 591 Handle<Object> return_val = callable().ToHandleChecked();
571 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321)); 592 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321));
572 } 593 }
573 594
574 595
596 TEST(InterpreterStoreGlobal) {
597 HandleAndZoneScope handles;
598 i::Isolate* isolate = handles.main_isolate();
599 i::Factory* factory = isolate->factory();
600
601 // Test storing to a global.
602 std::string source(
603 "var global = 321;\n"
604 "function " + InterpreterTester::function_name() + "() {\n"
605 " global = 999;\n"
606 "}");
607 InterpreterTester tester(handles.main_isolate(), source.c_str());
608 auto callable = tester.GetCallable<>();
609
610 callable().ToHandleChecked();
611 Handle<i::String> name = factory->InternalizeUtf8String("global");
612 Handle<i::Object> global_obj =
613 Object::GetProperty(isolate->global_object(), name).ToHandleChecked();
614 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999));
615 }
616
617
575 TEST(InterpreterCallGlobal) { 618 TEST(InterpreterCallGlobal) {
576 HandleAndZoneScope handles; 619 HandleAndZoneScope handles;
577 620
578 // Test calling a global function. 621 // Test calling a global function.
579 std::string source( 622 std::string source(
580 "function g_add(a, b) { return a + b; }\n" 623 "function g_add(a, b) { return a + b; }\n"
581 "function " + InterpreterTester::function_name() + "() {\n" 624 "function " + InterpreterTester::function_name() + "() {\n"
582 " return g_add(5, 10);\n" 625 " return g_add(5, 10);\n"
583 "}"); 626 "}");
584 InterpreterTester tester(handles.main_isolate(), source.c_str()); 627 InterpreterTester tester(handles.main_isolate(), source.c_str());
585 auto callable = tester.GetCallable<>(); 628 auto callable = tester.GetCallable<>();
586 629
587 Handle<Object> return_val = callable().ToHandleChecked(); 630 Handle<Object> return_val = callable().ToHandleChecked();
588 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); 631 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15));
589 } 632 }
590 633
591 634
635 TEST(InterpreterLoadUnallocated) {
636 HandleAndZoneScope handles;
637
638 // Test loading an unallocated global.
639 std::string source(
640 "unallocated = 123;\n"
641 "function " + InterpreterTester::function_name() + "() {\n"
642 " return unallocated;\n"
643 "}");
644 InterpreterTester tester(handles.main_isolate(), source.c_str());
645 auto callable = tester.GetCallable<>();
646
647 Handle<Object> return_val = callable().ToHandleChecked();
648 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123));
649 }
650
651
652 TEST(InterpreterStoreUnallocated) {
653 HandleAndZoneScope handles;
654 i::Isolate* isolate = handles.main_isolate();
655 i::Factory* factory = isolate->factory();
656
657 // Test storing to an unallocated global.
658 std::string source(
659 "unallocated = 321;\n"
660 "function " + InterpreterTester::function_name() + "() {\n"
661 " unallocated = 999;\n"
662 "}");
663 InterpreterTester tester(handles.main_isolate(), source.c_str());
664 auto callable = tester.GetCallable<>();
665
666 callable().ToHandleChecked();
667 Handle<i::String> name = factory->InternalizeUtf8String("unallocated");
668 Handle<i::Object> global_obj =
669 Object::GetProperty(isolate->global_object(), name).ToHandleChecked();
670 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999));
671 }
672
673
592 TEST(InterpreterLoadNamedProperty) { 674 TEST(InterpreterLoadNamedProperty) {
593 HandleAndZoneScope handles; 675 HandleAndZoneScope handles;
594 i::Isolate* isolate = handles.main_isolate(); 676 i::Isolate* isolate = handles.main_isolate();
595 i::Factory* factory = isolate->factory(); 677 i::Factory* factory = isolate->factory();
596 i::Zone zone; 678 i::Zone zone;
597 679
598 i::FeedbackVectorSpec feedback_spec(&zone); 680 i::FeedbackVectorSpec feedback_spec(&zone);
599 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); 681 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot();
600 682
601 Handle<i::TypeFeedbackVector> vector = 683 Handle<i::TypeFeedbackVector> vector =
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 .CallRuntime(Runtime::kAdd, Register(0), 2) 1546 .CallRuntime(Runtime::kAdd, Register(0), 2)
1465 .Return(); 1547 .Return();
1466 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1548 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1467 1549
1468 InterpreterTester tester(handles.main_isolate(), bytecode_array); 1550 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1469 auto callable = tester.GetCallable<>(); 1551 auto callable = tester.GetCallable<>();
1470 1552
1471 Handle<Object> return_val = callable().ToHandleChecked(); 1553 Handle<Object> return_val = callable().ToHandleChecked();
1472 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); 1554 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55));
1473 } 1555 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/compiler/interpreter-assembler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698