OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/ast/prettyprinter.h" | 5 #include "src/ast/prettyprinter.h" |
6 | 6 |
7 #include <stdarg.h> | 7 #include <stdarg.h> |
8 | 8 |
9 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
11 #include "src/base/platform/platform.h" | 11 #include "src/base/platform/platform.h" |
12 #include "src/globals.h" | 12 #include "src/globals.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 CallPrinter::CallPrinter(Isolate* isolate, bool is_builtin) | 17 CallPrinter::CallPrinter(Isolate* isolate, bool is_user_js) |
18 : builder_(isolate) { | 18 : builder_(isolate) { |
19 isolate_ = isolate; | 19 isolate_ = isolate; |
20 position_ = 0; | 20 position_ = 0; |
21 num_prints_ = 0; | 21 num_prints_ = 0; |
22 found_ = false; | 22 found_ = false; |
23 done_ = false; | 23 done_ = false; |
24 is_builtin_ = is_builtin; | 24 is_user_js_ = is_user_js; |
25 InitializeAstVisitor(isolate); | 25 InitializeAstVisitor(isolate); |
26 } | 26 } |
27 | 27 |
28 Handle<String> CallPrinter::Print(FunctionLiteral* program, int position) { | 28 Handle<String> CallPrinter::Print(FunctionLiteral* program, int position) { |
29 num_prints_ = 0; | 29 num_prints_ = 0; |
30 position_ = position; | 30 position_ = position; |
31 Find(program); | 31 Find(program); |
32 return builder_.Finish().ToHandleChecked(); | 32 return builder_.Finish().ToHandleChecked(); |
33 } | 33 } |
34 | 34 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 Print("["); | 232 Print("["); |
233 for (int i = 0; i < node->values()->length(); i++) { | 233 for (int i = 0; i < node->values()->length(); i++) { |
234 if (i != 0) Print(","); | 234 if (i != 0) Print(","); |
235 Find(node->values()->at(i), true); | 235 Find(node->values()->at(i), true); |
236 } | 236 } |
237 Print("]"); | 237 Print("]"); |
238 } | 238 } |
239 | 239 |
240 | 240 |
241 void CallPrinter::VisitVariableProxy(VariableProxy* node) { | 241 void CallPrinter::VisitVariableProxy(VariableProxy* node) { |
242 if (is_builtin_) { | 242 if (is_user_js_) { |
243 // Variable names of builtins are meaningless due to minification. | 243 PrintLiteral(node->name(), false); |
| 244 } else { |
| 245 // Variable names of non-user code are meaningless due to minification. |
244 Print("(var)"); | 246 Print("(var)"); |
245 } else { | |
246 PrintLiteral(node->name(), false); | |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 | 250 |
251 void CallPrinter::VisitAssignment(Assignment* node) { | 251 void CallPrinter::VisitAssignment(Assignment* node) { |
252 Find(node->target()); | 252 Find(node->target()); |
253 Find(node->value()); | 253 Find(node->value()); |
254 } | 254 } |
255 | 255 |
256 | 256 |
(...skipping 15 matching lines...) Expand all Loading... |
272 Print("["); | 272 Print("["); |
273 Find(key, true); | 273 Find(key, true); |
274 Print("]"); | 274 Print("]"); |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 | 278 |
279 void CallPrinter::VisitCall(Call* node) { | 279 void CallPrinter::VisitCall(Call* node) { |
280 bool was_found = !found_ && node->position() == position_; | 280 bool was_found = !found_ && node->position() == position_; |
281 if (was_found) { | 281 if (was_found) { |
282 // Bail out if the error is caused by a direct call to a variable in builtin | 282 // Bail out if the error is caused by a direct call to a variable in |
283 // code. The variable name is meaningless due to minification. | 283 // non-user JS code. The variable name is meaningless due to minification. |
284 if (is_builtin_ && node->expression()->IsVariableProxy()) { | 284 if (!is_user_js_ && node->expression()->IsVariableProxy()) { |
285 done_ = true; | 285 done_ = true; |
286 return; | 286 return; |
287 } | 287 } |
288 found_ = true; | 288 found_ = true; |
289 } | 289 } |
290 Find(node->expression(), true); | 290 Find(node->expression(), true); |
291 if (!was_found) Print("(...)"); | 291 if (!was_found) Print("(...)"); |
292 FindArguments(node->arguments()); | 292 FindArguments(node->arguments()); |
293 if (was_found) done_ = true; | 293 if (was_found) done_ = true; |
294 } | 294 } |
295 | 295 |
296 | 296 |
297 void CallPrinter::VisitCallNew(CallNew* node) { | 297 void CallPrinter::VisitCallNew(CallNew* node) { |
298 bool was_found = !found_ && node->position() == position_; | 298 bool was_found = !found_ && node->position() == position_; |
299 if (was_found) { | 299 if (was_found) { |
300 // Bail out if the error is caused by a direct call to a variable in builtin | 300 // Bail out if the error is caused by a direct call to a variable in |
301 // code. The variable name is meaningless due to minification. | 301 // non-user JS code. The variable name is meaningless due to minification. |
302 if (is_builtin_ && node->expression()->IsVariableProxy()) { | 302 if (!is_user_js_ && node->expression()->IsVariableProxy()) { |
303 done_ = true; | 303 done_ = true; |
304 return; | 304 return; |
305 } | 305 } |
306 found_ = true; | 306 found_ = true; |
307 } | 307 } |
308 Find(node->expression(), was_found); | 308 Find(node->expression(), was_found); |
309 FindArguments(node->arguments()); | 309 FindArguments(node->arguments()); |
310 if (was_found) done_ = true; | 310 if (was_found) done_ = true; |
311 } | 311 } |
312 | 312 |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 | 1199 |
1200 void AstPrinter::VisitRewritableExpression(RewritableExpression* node) { | 1200 void AstPrinter::VisitRewritableExpression(RewritableExpression* node) { |
1201 Visit(node->expression()); | 1201 Visit(node->expression()); |
1202 } | 1202 } |
1203 | 1203 |
1204 | 1204 |
1205 #endif // DEBUG | 1205 #endif // DEBUG |
1206 | 1206 |
1207 } // namespace internal | 1207 } // namespace internal |
1208 } // namespace v8 | 1208 } // namespace v8 |
OLD | NEW |