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

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

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

Powered by Google App Engine
This is Rietveld 408576698