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

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

Issue 1546643002: [Interpreter] Updates load/store global and named property to accept variable name. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 12 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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 Handle<i::TypeFeedbackVector> vector = 767 Handle<i::TypeFeedbackVector> vector =
768 i::NewTypeFeedbackVector(isolate, &feedback_spec); 768 i::NewTypeFeedbackVector(isolate, &feedback_spec);
769 769
770 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); 770 Handle<i::String> name = factory->NewStringFromAsciiChecked("val");
771 name = factory->string_table()->LookupString(isolate, name); 771 name = factory->string_table()->LookupString(isolate, name);
772 772
773 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 773 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
774 builder.set_locals_count(0); 774 builder.set_locals_count(0);
775 builder.set_context_count(0); 775 builder.set_context_count(0);
776 builder.set_parameter_count(1); 776 builder.set_parameter_count(1);
777 size_t name_index = builder.GetConstantPoolEntry(name); 777 builder.LoadNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot),
778 builder.LoadNamedProperty(builder.Parameter(0), name_index, 778 i::SLOPPY)
779 vector->GetIndex(slot), i::SLOPPY)
780 .Return(); 779 .Return();
781 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 780 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
782 781
783 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 782 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
784 auto callable = tester.GetCallable<Handle<Object>>(); 783 auto callable = tester.GetCallable<Handle<Object>>();
785 784
786 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); 785 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })");
787 // Test IC miss. 786 // Test IC miss.
788 Handle<Object> return_val = callable(object).ToHandleChecked(); 787 Handle<Object> return_val = callable(object).ToHandleChecked();
789 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); 788 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 Handle<i::TypeFeedbackVector> vector = 868 Handle<i::TypeFeedbackVector> vector =
870 i::NewTypeFeedbackVector(isolate, &feedback_spec); 869 i::NewTypeFeedbackVector(isolate, &feedback_spec);
871 870
872 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); 871 Handle<i::String> name = factory->NewStringFromAsciiChecked("val");
873 name = factory->string_table()->LookupString(isolate, name); 872 name = factory->string_table()->LookupString(isolate, name);
874 873
875 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 874 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
876 builder.set_locals_count(0); 875 builder.set_locals_count(0);
877 builder.set_context_count(0); 876 builder.set_context_count(0);
878 builder.set_parameter_count(1); 877 builder.set_parameter_count(1);
879 size_t name_index = builder.GetConstantPoolEntry(name);
880 builder.LoadLiteral(Smi::FromInt(999)) 878 builder.LoadLiteral(Smi::FromInt(999))
881 .StoreNamedProperty(builder.Parameter(0), name_index, 879 .StoreNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot),
882 vector->GetIndex(slot), i::STRICT) 880 i::STRICT)
883 .Return(); 881 .Return();
884 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 882 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
885 883
886 InterpreterTester tester(isolate, bytecode_array, vector); 884 InterpreterTester tester(isolate, bytecode_array, vector);
887 auto callable = tester.GetCallable<Handle<Object>>(); 885 auto callable = tester.GetCallable<Handle<Object>>();
888 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); 886 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })");
889 // Test IC miss. 887 // Test IC miss.
890 Handle<Object> result; 888 Handle<Object> result;
891 callable(object).ToHandleChecked(); 889 callable(object).ToHandleChecked();
892 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); 890 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 982
985 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); 983 Handle<i::String> name = factory->NewStringFromAsciiChecked("func");
986 name = factory->string_table()->LookupString(isolate, name); 984 name = factory->string_table()->LookupString(isolate, name);
987 985
988 // Check with no args. 986 // Check with no args.
989 { 987 {
990 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 988 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
991 builder.set_locals_count(1); 989 builder.set_locals_count(1);
992 builder.set_context_count(0); 990 builder.set_context_count(0);
993 builder.set_parameter_count(1); 991 builder.set_parameter_count(1);
994 size_t name_index = builder.GetConstantPoolEntry(name); 992 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index, i::SLOPPY)
995 builder.LoadNamedProperty(builder.Parameter(0), name_index, slot_index,
996 i::SLOPPY)
997 .StoreAccumulatorInRegister(Register(0)) 993 .StoreAccumulatorInRegister(Register(0))
998 .Call(Register(0), builder.Parameter(0), 0, 0) 994 .Call(Register(0), builder.Parameter(0), 0, 0)
999 .Return(); 995 .Return();
1000 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 996 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1001 997
1002 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 998 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
1003 auto callable = tester.GetCallable<Handle<Object>>(); 999 auto callable = tester.GetCallable<Handle<Object>>();
1004 1000
1005 Handle<Object> object = InterpreterTester::NewObject( 1001 Handle<Object> object = InterpreterTester::NewObject(
1006 "new (function Obj() { this.func = function() { return 0x265; }})()"); 1002 "new (function Obj() { this.func = function() { return 0x265; }})()");
1007 Handle<Object> return_val = callable(object).ToHandleChecked(); 1003 Handle<Object> return_val = callable(object).ToHandleChecked();
1008 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); 1004 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265));
1009 } 1005 }
1010 1006
1011 // Check that receiver is passed properly. 1007 // Check that receiver is passed properly.
1012 { 1008 {
1013 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 1009 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1014 builder.set_locals_count(1); 1010 builder.set_locals_count(1);
1015 builder.set_context_count(0); 1011 builder.set_context_count(0);
1016 builder.set_parameter_count(1); 1012 builder.set_parameter_count(1);
1017 size_t name_index = builder.GetConstantPoolEntry(name); 1013 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index, i::SLOPPY)
1018 builder.LoadNamedProperty(builder.Parameter(0), name_index, slot_index,
1019 i::SLOPPY)
1020 .StoreAccumulatorInRegister(Register(0)) 1014 .StoreAccumulatorInRegister(Register(0))
1021 .Call(Register(0), builder.Parameter(0), 0, 0) 1015 .Call(Register(0), builder.Parameter(0), 0, 0)
1022 .Return(); 1016 .Return();
1023 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1017 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1024 1018
1025 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 1019 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
1026 auto callable = tester.GetCallable<Handle<Object>>(); 1020 auto callable = tester.GetCallable<Handle<Object>>();
1027 1021
1028 Handle<Object> object = InterpreterTester::NewObject( 1022 Handle<Object> object = InterpreterTester::NewObject(
1029 "new (function Obj() {" 1023 "new (function Obj() {"
1030 " this.val = 1234;" 1024 " this.val = 1234;"
1031 " this.func = function() { return this.val; };" 1025 " this.func = function() { return this.val; };"
1032 "})()"); 1026 "})()");
1033 Handle<Object> return_val = callable(object).ToHandleChecked(); 1027 Handle<Object> return_val = callable(object).ToHandleChecked();
1034 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); 1028 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234));
1035 } 1029 }
1036 1030
1037 // Check with two parameters (+ receiver). 1031 // Check with two parameters (+ receiver).
1038 { 1032 {
1039 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 1033 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1040 builder.set_locals_count(4); 1034 builder.set_locals_count(4);
1041 builder.set_context_count(0); 1035 builder.set_context_count(0);
1042 builder.set_parameter_count(1); 1036 builder.set_parameter_count(1);
1043 size_t name_index = builder.GetConstantPoolEntry(name); 1037 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index, i::SLOPPY)
1044 builder.LoadNamedProperty(builder.Parameter(0), name_index, slot_index,
1045 i::SLOPPY)
1046 .StoreAccumulatorInRegister(Register(0)) 1038 .StoreAccumulatorInRegister(Register(0))
1047 .LoadAccumulatorWithRegister(builder.Parameter(0)) 1039 .LoadAccumulatorWithRegister(builder.Parameter(0))
1048 .StoreAccumulatorInRegister(Register(1)) 1040 .StoreAccumulatorInRegister(Register(1))
1049 .LoadLiteral(Smi::FromInt(51)) 1041 .LoadLiteral(Smi::FromInt(51))
1050 .StoreAccumulatorInRegister(Register(2)) 1042 .StoreAccumulatorInRegister(Register(2))
1051 .LoadLiteral(Smi::FromInt(11)) 1043 .LoadLiteral(Smi::FromInt(11))
1052 .StoreAccumulatorInRegister(Register(3)) 1044 .StoreAccumulatorInRegister(Register(3))
1053 .Call(Register(0), Register(1), 2, 0) 1045 .Call(Register(0), Register(1), 2, 0)
1054 .Return(); 1046 .Return();
1055 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1047 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1056 1048
1057 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 1049 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
1058 auto callable = tester.GetCallable<Handle<Object>>(); 1050 auto callable = tester.GetCallable<Handle<Object>>();
1059 1051
1060 Handle<Object> object = InterpreterTester::NewObject( 1052 Handle<Object> object = InterpreterTester::NewObject(
1061 "new (function Obj() { " 1053 "new (function Obj() { "
1062 " this.func = function(a, b) { return a - b; }" 1054 " this.func = function(a, b) { return a - b; }"
1063 "})()"); 1055 "})()");
1064 Handle<Object> return_val = callable(object).ToHandleChecked(); 1056 Handle<Object> return_val = callable(object).ToHandleChecked();
1065 CHECK(return_val->SameValue(Smi::FromInt(40))); 1057 CHECK(return_val->SameValue(Smi::FromInt(40)));
1066 } 1058 }
1067 1059
1068 // Check with 10 parameters (+ receiver). 1060 // Check with 10 parameters (+ receiver).
1069 { 1061 {
1070 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 1062 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1071 builder.set_locals_count(12); 1063 builder.set_locals_count(12);
1072 builder.set_context_count(0); 1064 builder.set_context_count(0);
1073 builder.set_parameter_count(1); 1065 builder.set_parameter_count(1);
1074 size_t name_index = builder.GetConstantPoolEntry(name); 1066 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index, i::SLOPPY)
1075 builder.LoadNamedProperty(builder.Parameter(0), name_index, slot_index,
1076 i::SLOPPY)
1077 .StoreAccumulatorInRegister(Register(0)) 1067 .StoreAccumulatorInRegister(Register(0))
1078 .LoadAccumulatorWithRegister(builder.Parameter(0)) 1068 .LoadAccumulatorWithRegister(builder.Parameter(0))
1079 .StoreAccumulatorInRegister(Register(1)) 1069 .StoreAccumulatorInRegister(Register(1))
1080 .LoadLiteral(factory->NewStringFromAsciiChecked("a")) 1070 .LoadLiteral(factory->NewStringFromAsciiChecked("a"))
1081 .StoreAccumulatorInRegister(Register(2)) 1071 .StoreAccumulatorInRegister(Register(2))
1082 .LoadLiteral(factory->NewStringFromAsciiChecked("b")) 1072 .LoadLiteral(factory->NewStringFromAsciiChecked("b"))
1083 .StoreAccumulatorInRegister(Register(3)) 1073 .StoreAccumulatorInRegister(Register(3))
1084 .LoadLiteral(factory->NewStringFromAsciiChecked("c")) 1074 .LoadLiteral(factory->NewStringFromAsciiChecked("c"))
1085 .StoreAccumulatorInRegister(Register(4)) 1075 .StoreAccumulatorInRegister(Register(4))
1086 .LoadLiteral(factory->NewStringFromAsciiChecked("d")) 1076 .LoadLiteral(factory->NewStringFromAsciiChecked("d"))
(...skipping 2072 matching lines...) Expand 10 before | Expand all | Expand 10 after
3159 auto callable = tester.GetCallable<>(); 3149 auto callable = tester.GetCallable<>();
3160 3150
3161 Handle<i::Object> return_value = callable().ToHandleChecked(); 3151 Handle<i::Object> return_value = callable().ToHandleChecked();
3162 CHECK(return_value->SameValue(*reg_tests[i].second)); 3152 CHECK(return_value->SameValue(*reg_tests[i].second));
3163 } 3153 }
3164 } 3154 }
3165 3155
3166 } // namespace interpreter 3156 } // namespace interpreter
3167 } // namespace internal 3157 } // namespace internal
3168 } // namespace v8 3158 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698