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

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

Issue 1425633002: [Interpreter] Add support for loading from / storing to outer context variables. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_conditional
Patch Set: Fix interpreter-assembler-unittests Created 5 years, 1 month 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 }; 51 };
52 52
53 53
54 static const char* kFunctionName = "f"; 54 static const char* kFunctionName = "f";
55 55
56 56
57 class InterpreterTester { 57 class InterpreterTester {
58 public: 58 public:
59 InterpreterTester(Isolate* isolate, const char* source, 59 InterpreterTester(Isolate* isolate, const char* source,
60 MaybeHandle<BytecodeArray> bytecode, 60 MaybeHandle<BytecodeArray> bytecode,
61 MaybeHandle<TypeFeedbackVector> feedback_vector) 61 MaybeHandle<TypeFeedbackVector> feedback_vector,
62 const char* filter)
62 : isolate_(isolate), 63 : isolate_(isolate),
63 source_(source), 64 source_(source),
64 bytecode_(bytecode), 65 bytecode_(bytecode),
65 feedback_vector_(feedback_vector) { 66 feedback_vector_(feedback_vector) {
66 i::FLAG_vector_stores = true; 67 i::FLAG_vector_stores = true;
67 i::FLAG_ignition = true; 68 i::FLAG_ignition = true;
68 i::FLAG_ignition_fake_try_catch = true; 69 i::FLAG_ignition_fake_try_catch = true;
69 i::FLAG_always_opt = false; 70 i::FLAG_always_opt = false;
70 // Set ignition filter flag via SetFlagsFromString to avoid double-free 71 // Set ignition filter flag via SetFlagsFromString to avoid double-free
71 // (or potential leak with StrDup() based on ownership confusion). 72 // (or potential leak with StrDup() based on ownership confusion).
72 ScopedVector<char> ignition_filter(64); 73 ScopedVector<char> ignition_filter(64);
73 SNPrintF(ignition_filter, "--ignition-filter=%s", kFunctionName); 74 SNPrintF(ignition_filter, "--ignition-filter=%s", filter);
74 FlagList::SetFlagsFromString(ignition_filter.start(), 75 FlagList::SetFlagsFromString(ignition_filter.start(),
75 ignition_filter.length()); 76 ignition_filter.length());
76 // Ensure handler table is generated. 77 // Ensure handler table is generated.
77 isolate->interpreter()->Initialize(); 78 isolate->interpreter()->Initialize();
78 } 79 }
79 80
80 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode, 81 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode,
81 MaybeHandle<TypeFeedbackVector> feedback_vector = 82 MaybeHandle<TypeFeedbackVector> feedback_vector =
82 MaybeHandle<TypeFeedbackVector>()) 83 MaybeHandle<TypeFeedbackVector>(),
83 : InterpreterTester(isolate, nullptr, bytecode, feedback_vector) {} 84 const char* filter = kFunctionName)
85 : InterpreterTester(isolate, nullptr, bytecode, feedback_vector, filter) {
86 }
84 87
85 88
86 InterpreterTester(Isolate* isolate, const char* source) 89 InterpreterTester(Isolate* isolate, const char* source,
90 const char* filter = kFunctionName)
87 : InterpreterTester(isolate, source, MaybeHandle<BytecodeArray>(), 91 : InterpreterTester(isolate, source, MaybeHandle<BytecodeArray>(),
88 MaybeHandle<TypeFeedbackVector>()) {} 92 MaybeHandle<TypeFeedbackVector>(), filter) {}
89 93
90 virtual ~InterpreterTester() {} 94 virtual ~InterpreterTester() {}
91 95
92 template <class... A> 96 template <class... A>
93 InterpreterCallable<A...> GetCallable() { 97 InterpreterCallable<A...> GetCallable() {
94 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>()); 98 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>());
95 } 99 }
96 100
97 static Handle<Object> NewObject(const char* script) { 101 static Handle<Object> NewObject(const char* script) {
98 return v8::Utils::OpenHandle(*CompileRun(script)); 102 return v8::Utils::OpenHandle(*CompileRun(script));
(...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 1916
1913 Handle<Object> a1 = handle(Smi::FromInt(1), isolate); 1917 Handle<Object> a1 = handle(Smi::FromInt(1), isolate);
1914 Handle<Object> a2 = handle(Smi::FromInt(2), isolate); 1918 Handle<Object> a2 = handle(Smi::FromInt(2), isolate);
1915 Handle<Object> a3 = handle(Smi::FromInt(3), isolate); 1919 Handle<Object> a3 = handle(Smi::FromInt(3), isolate);
1916 Handle<i::Object> return_value = callable(a1, a2, a3).ToHandleChecked(); 1920 Handle<i::Object> return_value = callable(a1, a2, a3).ToHandleChecked();
1917 CHECK(return_value->SameValue(*context_params[i].second)); 1921 CHECK(return_value->SameValue(*context_params[i].second));
1918 } 1922 }
1919 } 1923 }
1920 1924
1921 1925
1926 TEST(InterpreterOuterContextVariables) {
1927 HandleAndZoneScope handles;
1928 i::Isolate* isolate = handles.main_isolate();
1929
1930 std::pair<const char*, Handle<Object>> context_vars[2] = {
1931 std::make_pair("return outerVar * innerArg;",
1932 handle(Smi::FromInt(200), isolate)),
1933 std::make_pair("outerVar = innerArg; return outerVar",
1934 handle(Smi::FromInt(20), isolate)),
1935 };
1936
1937 std::string header(
1938 "function Outer() {"
1939 " var outerVar = 10;"
1940 " function Inner(innerArg) {"
1941 " this.innerFunc = function() { ");
1942 std::string footer(
1943 " }}"
1944 " this.getInnerFunc = function() { return new Inner(20).innerFunc; }"
1945 "}"
1946 "var f = new Outer().getInnerFunc();");
1947
1948 for (size_t i = 0; i < arraysize(context_vars); i++) {
1949 std::string source = header + context_vars[i].first + footer;
1950 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*");
1951 auto callable = tester.GetCallable<>();
1952
1953 Handle<i::Object> return_value = callable().ToHandleChecked();
1954 CHECK(return_value->SameValue(*context_vars[i].second));
1955 }
1956 }
1957
1958
1922 TEST(InterpreterComma) { 1959 TEST(InterpreterComma) {
1923 HandleAndZoneScope handles; 1960 HandleAndZoneScope handles;
1924 i::Isolate* isolate = handles.main_isolate(); 1961 i::Isolate* isolate = handles.main_isolate();
1925 i::Factory* factory = isolate->factory(); 1962 i::Factory* factory = isolate->factory();
1926 1963
1927 std::pair<const char*, Handle<Object>> literals[6] = { 1964 std::pair<const char*, Handle<Object>> literals[6] = {
1928 std::make_pair("var a; return 0, a;\n", factory->undefined_value()), 1965 std::make_pair("var a; return 0, a;\n", factory->undefined_value()),
1929 std::make_pair("return 'a', 2.2, 3;\n", 1966 std::make_pair("return 'a', 2.2, 3;\n",
1930 handle(Smi::FromInt(3), isolate)), 1967 handle(Smi::FromInt(3), isolate)),
1931 std::make_pair("return 'a', 'b', 'c';\n", 1968 std::make_pair("return 'a', 'b', 'c';\n",
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 2328
2292 for (size_t i = 0; i < arraysize(conditional); i++) { 2329 for (size_t i = 0; i < arraysize(conditional); i++) {
2293 std::string source(InterpreterTester::SourceForBody(conditional[i].first)); 2330 std::string source(InterpreterTester::SourceForBody(conditional[i].first));
2294 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2331 InterpreterTester tester(handles.main_isolate(), source.c_str());
2295 auto callable = tester.GetCallable<>(); 2332 auto callable = tester.GetCallable<>();
2296 2333
2297 Handle<i::Object> return_value = callable().ToHandleChecked(); 2334 Handle<i::Object> return_value = callable().ToHandleChecked();
2298 CHECK(return_value->SameValue(*conditional[i].second)); 2335 CHECK(return_value->SameValue(*conditional[i].second));
2299 } 2336 }
2300 } 2337 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/compiler/arm/instruction-selector-arm-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698