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

Side by Side Diff: test/cctest/compiler/function-tester.h

Issue 1995453002: [stubs] Extend HasProperty stub with dictionary-mode and double-elements objects support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Drive-by fix: replace Load()s with LoadObjectField()s Created 4 years, 6 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
« no previous file with comments | « src/utils.cc ('k') | test/cctest/test-code-stub-assembler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ 5 #ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
6 #define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ 6 #define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
7 7
8 #include "src/ast/ast-numbering.h" 8 #include "src/ast/ast-numbering.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/compiler.h" 10 #include "src/compiler.h"
(...skipping 24 matching lines...) Expand all
35 CHECK_EQ(0u, flags_ & ~supported_flags); 35 CHECK_EQ(0u, flags_ & ~supported_flags);
36 } 36 }
37 37
38 FunctionTester(Graph* graph, int param_count) 38 FunctionTester(Graph* graph, int param_count)
39 : isolate(main_isolate()), 39 : isolate(main_isolate()),
40 function(NewFunction(BuildFunction(param_count).c_str())), 40 function(NewFunction(BuildFunction(param_count).c_str())),
41 flags_(0) { 41 flags_(0) {
42 CompileGraph(graph); 42 CompileGraph(graph);
43 } 43 }
44 44
45 FunctionTester(const CallInterfaceDescriptor& descriptor, Handle<Code> code) 45 FunctionTester(Handle<Code> code, int param_count)
46 : isolate(main_isolate()), 46 : isolate(main_isolate()),
47 function( 47 function((FLAG_allow_natives_syntax = true,
48 (FLAG_allow_natives_syntax = true, 48 NewFunction(BuildFunction(param_count).c_str()))),
49 NewFunction(BuildFunctionFromDescriptor(descriptor).c_str()))),
50 flags_(0) { 49 flags_(0) {
51 Compile(function); 50 Compile(function);
52 function->ReplaceCode(*code); 51 function->ReplaceCode(*code);
53 } 52 }
54 53
54 FunctionTester(const CallInterfaceDescriptor& descriptor, Handle<Code> code)
55 : FunctionTester(code, descriptor.GetParameterCount()) {}
56
55 Isolate* isolate; 57 Isolate* isolate;
56 Handle<JSFunction> function; 58 Handle<JSFunction> function;
57 59
58 MaybeHandle<Object> Call() { 60 MaybeHandle<Object> Call() {
59 return Execution::Call(isolate, function, undefined(), 0, nullptr); 61 return Execution::Call(isolate, function, undefined(), 0, nullptr);
60 } 62 }
61 63
62 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b) { 64 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b) {
63 Handle<Object> args[] = {a, b}; 65 Handle<Object> args[] = {a, b};
64 return Execution::Call(isolate, function, undefined(), 2, args); 66 return Execution::Call(isolate, function, undefined(), 2, args);
65 } 67 }
66 68
69 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b,
70 Handle<Object> c) {
71 Handle<Object> args[] = {a, b, c};
72 return Execution::Call(isolate, function, undefined(), 3, args);
73 }
74
67 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c, 75 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c,
68 Handle<Object> d) { 76 Handle<Object> d) {
69 Handle<Object> args[] = {a, b, c, d}; 77 Handle<Object> args[] = {a, b, c, d};
70 return Execution::Call(isolate, function, undefined(), 4, args); 78 return Execution::Call(isolate, function, undefined(), 4, args);
71 } 79 }
72 80
73 void CheckThrows(Handle<Object> a, Handle<Object> b) { 81 void CheckThrows(Handle<Object> a, Handle<Object> b) {
74 TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate)); 82 TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
75 MaybeHandle<Object> no_result = Call(a, b); 83 MaybeHandle<Object> no_result = Call(a, b);
76 CHECK(isolate->has_pending_exception()); 84 CHECK(isolate->has_pending_exception());
77 CHECK(try_catch.HasCaught()); 85 CHECK(try_catch.HasCaught());
78 CHECK(no_result.is_null()); 86 CHECK(no_result.is_null());
79 isolate->OptionalRescheduleException(true); 87 isolate->OptionalRescheduleException(true);
80 } 88 }
81 89
82 v8::Local<v8::Message> CheckThrowsReturnMessage(Handle<Object> a, 90 v8::Local<v8::Message> CheckThrowsReturnMessage(Handle<Object> a,
83 Handle<Object> b) { 91 Handle<Object> b) {
84 TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate)); 92 TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
85 MaybeHandle<Object> no_result = Call(a, b); 93 MaybeHandle<Object> no_result = Call(a, b);
86 CHECK(isolate->has_pending_exception()); 94 CHECK(isolate->has_pending_exception());
87 CHECK(try_catch.HasCaught()); 95 CHECK(try_catch.HasCaught());
88 CHECK(no_result.is_null()); 96 CHECK(no_result.is_null());
89 isolate->OptionalRescheduleException(true); 97 isolate->OptionalRescheduleException(true);
90 CHECK(!try_catch.Message().IsEmpty()); 98 CHECK(!try_catch.Message().IsEmpty());
91 return try_catch.Message(); 99 return try_catch.Message();
92 } 100 }
93 101
102 void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
103 Handle<Object> c, Handle<Object> d) {
104 Handle<Object> result = Call(a, b, c, d).ToHandleChecked();
105 CHECK(expected->SameValue(*result));
106 }
107
108 void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
109 Handle<Object> c) {
110 return CheckCall(expected, a, b, c, undefined());
111 }
112
94 void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b) { 113 void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b) {
95 Handle<Object> result = Call(a, b).ToHandleChecked(); 114 return CheckCall(expected, a, b, undefined());
96 CHECK(expected->SameValue(*result));
97 } 115 }
98 116
99 void CheckCall(Handle<Object> expected, Handle<Object> a) { 117 void CheckCall(Handle<Object> expected, Handle<Object> a) {
100 CheckCall(expected, a, undefined()); 118 CheckCall(expected, a, undefined());
101 } 119 }
102 120
103 void CheckCall(Handle<Object> expected) { 121 void CheckCall(Handle<Object> expected) { CheckCall(expected, undefined()); }
104 CheckCall(expected, undefined(), undefined());
105 }
106 122
107 void CheckCall(double expected, double a, double b) { 123 void CheckCall(double expected, double a, double b) {
108 CheckCall(Val(expected), Val(a), Val(b)); 124 CheckCall(Val(expected), Val(a), Val(b));
109 } 125 }
110 126
127 void CheckTrue(Handle<Object> a) { CheckCall(true_value(), a); }
128
111 void CheckTrue(Handle<Object> a, Handle<Object> b) { 129 void CheckTrue(Handle<Object> a, Handle<Object> b) {
112 CheckCall(true_value(), a, b); 130 CheckCall(true_value(), a, b);
113 } 131 }
114 132
115 void CheckTrue(Handle<Object> a) { CheckCall(true_value(), a, undefined()); } 133 void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c) {
134 CheckCall(true_value(), a, b, c);
135 }
136
137 void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c,
138 Handle<Object> d) {
139 CheckCall(true_value(), a, b, c, d);
140 }
116 141
117 void CheckTrue(double a, double b) { 142 void CheckTrue(double a, double b) {
118 CheckCall(true_value(), Val(a), Val(b)); 143 CheckCall(true_value(), Val(a), Val(b));
119 } 144 }
120 145
146 void CheckFalse(Handle<Object> a) { CheckCall(false_value(), a); }
147
121 void CheckFalse(Handle<Object> a, Handle<Object> b) { 148 void CheckFalse(Handle<Object> a, Handle<Object> b) {
122 CheckCall(false_value(), a, b); 149 CheckCall(false_value(), a, b);
123 } 150 }
124 151
125 void CheckFalse(Handle<Object> a) {
126 CheckCall(false_value(), a, undefined());
127 }
128
129 void CheckFalse(double a, double b) { 152 void CheckFalse(double a, double b) {
130 CheckCall(false_value(), Val(a), Val(b)); 153 CheckCall(false_value(), Val(a), Val(b));
131 } 154 }
132 155
133 Handle<JSFunction> NewFunction(const char* source) { 156 Handle<JSFunction> NewFunction(const char* source) {
134 return Handle<JSFunction>::cast(v8::Utils::OpenHandle( 157 return Handle<JSFunction>::cast(v8::Utils::OpenHandle(
135 *v8::Local<v8::Function>::Cast(CompileRun(source)))); 158 *v8::Local<v8::Function>::Cast(CompileRun(source))));
136 } 159 }
137 160
138 Handle<JSObject> NewObject(const char* source) { 161 Handle<JSObject> NewObject(const char* source) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 function_string += 'a'; 233 function_string += 'a';
211 for (int i = 1; i < param_count; i++) { 234 for (int i = 1; i < param_count; i++) {
212 function_string += ','; 235 function_string += ',';
213 function_string += static_cast<char>('a' + i); 236 function_string += static_cast<char>('a' + i);
214 } 237 }
215 } 238 }
216 function_string += "){})"; 239 function_string += "){})";
217 return function_string; 240 return function_string;
218 } 241 }
219 242
220 std::string BuildFunctionFromDescriptor(
221 const CallInterfaceDescriptor& descriptor) {
222 return BuildFunction(descriptor.GetParameterCount());
223 }
224
225 // Compile the given machine graph instead of the source of the function 243 // Compile the given machine graph instead of the source of the function
226 // and replace the JSFunction's code with the result. 244 // and replace the JSFunction's code with the result.
227 Handle<JSFunction> CompileGraph(Graph* graph) { 245 Handle<JSFunction> CompileGraph(Graph* graph) {
228 Zone zone(function->GetIsolate()->allocator()); 246 Zone zone(function->GetIsolate()->allocator());
229 ParseInfo parse_info(&zone, function); 247 ParseInfo parse_info(&zone, function);
230 CompilationInfo info(&parse_info, function); 248 CompilationInfo info(&parse_info, function);
231 249
232 CHECK(Parser::ParseStatic(info.parse_info())); 250 CHECK(Parser::ParseStatic(info.parse_info()));
233 info.SetOptimizing(); 251 info.SetOptimizing();
234 252
235 Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph); 253 Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph);
236 CHECK(!code.is_null()); 254 CHECK(!code.is_null());
237 function->ReplaceCode(*code); 255 function->ReplaceCode(*code);
238 return function; 256 return function;
239 } 257 }
240 }; 258 };
241 } // namespace compiler 259 } // namespace compiler
242 } // namespace internal 260 } // namespace internal
243 } // namespace v8 261 } // namespace v8
244 262
245 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ 263 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
OLDNEW
« no previous file with comments | « src/utils.cc ('k') | test/cctest/test-code-stub-assembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698