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

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

Issue 2347143002: [interpreter] Add fast path for dynamic global lookups (Closed)
Patch Set: Rebase on master and rebaseline tests Created 4 years, 3 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 <tuple> 5 #include <tuple>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/execution.h" 9 #include "src/execution.h"
10 #include "src/handles.h" 10 #include "src/handles.h"
(...skipping 3888 matching lines...) Expand 10 before | Expand all | Expand 10 after
3899 std::string script = InterpreterTester::SourceForBody(body.c_str()); 3899 std::string script = InterpreterTester::SourceForBody(body.c_str());
3900 3900
3901 InterpreterTester tester(isolate, script.c_str()); 3901 InterpreterTester tester(isolate, script.c_str());
3902 auto callable = tester.GetCallable<>(); 3902 auto callable = tester.GetCallable<>();
3903 3903
3904 Handle<i::Object> return_value = callable().ToHandleChecked(); 3904 Handle<i::Object> return_value = callable().ToHandleChecked();
3905 CHECK(return_value->SameValue(*std::get<2>(lookup_slot[i]))); 3905 CHECK(return_value->SameValue(*std::get<2>(lookup_slot[i])));
3906 } 3906 }
3907 } 3907 }
3908 3908
3909 TEST(InterpreterLookupGlobalSlot) {
3910 HandleAndZoneScope handles;
3911 Isolate* isolate = handles.main_isolate();
3912
3913 const char* inner_function_prologue = "function inner() {";
3914 const char* inner_function_epilogue = "};";
3915 const char* outer_function_epilogue = "return inner();";
3916
3917 std::tuple<const char*, const char*, Handle<Object>> lookup_slot[] = {
3918 // Eval in inner context.
3919 std::make_tuple("x = 0;", "eval(''); return x;",
3920 handle(Smi::FromInt(0), isolate)),
3921 std::make_tuple("x = 0;", "eval('var x = 1'); return x;",
3922 handle(Smi::FromInt(1), isolate)),
3923 std::make_tuple("x = 0;", "'use strict'; eval('var x = 1'); return x;",
3924 handle(Smi::FromInt(0), isolate)),
3925 // Eval in outer context.
3926 std::make_tuple("x = 0; eval('');", "return x;",
3927 handle(Smi::FromInt(0), isolate)),
3928 std::make_tuple("x = 0; eval('var x = 1');", "return x;",
3929 handle(Smi::FromInt(1), isolate)),
3930 std::make_tuple("'use strict'; x = 0; eval('var x = 1');", "return x;",
3931 handle(Smi::FromInt(0), isolate)),
3932 };
3933
3934 for (size_t i = 0; i < arraysize(lookup_slot); i++) {
3935 std::string body = std::string(std::get<0>(lookup_slot[i])) +
3936 std::string(inner_function_prologue) +
3937 std::string(std::get<1>(lookup_slot[i])) +
3938 std::string(inner_function_epilogue) +
3939 std::string(outer_function_epilogue);
3940 std::string script = InterpreterTester::SourceForBody(body.c_str());
3941
3942 InterpreterTester tester(isolate, script.c_str());
3943 auto callable = tester.GetCallable<>();
3944
3945 Handle<i::Object> return_value = callable().ToHandleChecked();
3946 CHECK(return_value->SameValue(*std::get<2>(lookup_slot[i])));
3947 }
3948 }
3949
3909 TEST(InterpreterCallLookupSlot) { 3950 TEST(InterpreterCallLookupSlot) {
3910 HandleAndZoneScope handles; 3951 HandleAndZoneScope handles;
3911 Isolate* isolate = handles.main_isolate(); 3952 Isolate* isolate = handles.main_isolate();
3912 3953
3913 std::pair<const char*, Handle<Object>> call_lookup[] = { 3954 std::pair<const char*, Handle<Object>> call_lookup[] = {
3914 {"g = function(){ return 2 }; eval(''); return g();", 3955 {"g = function(){ return 2 }; eval(''); return g();",
3915 handle(Smi::FromInt(2), isolate)}, 3956 handle(Smi::FromInt(2), isolate)},
3916 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" 3957 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n"
3917 "return g();", 3958 "return g();",
3918 handle(Smi::FromInt(3), isolate)}, 3959 handle(Smi::FromInt(3), isolate)},
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
4764 auto callable = tester.GetCallable<>(); 4805 auto callable = tester.GetCallable<>();
4765 4806
4766 Handle<i::Object> return_value = callable().ToHandleChecked(); 4807 Handle<i::Object> return_value = callable().ToHandleChecked();
4767 CHECK(return_value->SameValue(*tests[i].second)); 4808 CHECK(return_value->SameValue(*tests[i].second));
4768 } 4809 }
4769 } 4810 }
4770 4811
4771 } // namespace interpreter 4812 } // namespace interpreter
4772 } // namespace internal 4813 } // namespace internal
4773 } // namespace v8 4814 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698