OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 bool Expression::IsStringLiteral() { | 63 bool Expression::IsStringLiteral() { |
64 return AsLiteral() != NULL && AsLiteral()->handle()->IsString(); | 64 return AsLiteral() != NULL && AsLiteral()->handle()->IsString(); |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 bool Expression::IsNullLiteral() { | 68 bool Expression::IsNullLiteral() { |
69 return AsLiteral() != NULL && AsLiteral()->handle()->IsNull(); | 69 return AsLiteral() != NULL && AsLiteral()->handle()->IsNull(); |
70 } | 70 } |
71 | 71 |
72 | 72 |
| 73 bool Expression::IsUndefinedLiteral() { |
| 74 return AsLiteral() != NULL && AsLiteral()->handle()->IsUndefined(); |
| 75 } |
| 76 |
| 77 |
73 VariableProxy::VariableProxy(Isolate* isolate, Variable* var) | 78 VariableProxy::VariableProxy(Isolate* isolate, Variable* var) |
74 : Expression(isolate), | 79 : Expression(isolate), |
75 name_(var->name()), | 80 name_(var->name()), |
76 var_(NULL), // Will be set by the call to BindTo. | 81 var_(NULL), // Will be set by the call to BindTo. |
77 is_this_(var->is_this()), | 82 is_this_(var->is_this()), |
78 is_trivial_(false), | 83 is_trivial_(false), |
79 is_lvalue_(false), | 84 is_lvalue_(false), |
80 position_(RelocInfo::kNoPosition), | 85 position_(RelocInfo::kNoPosition), |
81 interface_(var->interface()) { | 86 interface_(var->interface()) { |
82 BindTo(var); | 87 BindTo(var); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 350 |
346 | 351 |
347 static bool IsVoidOfLiteral(Expression* expr) { | 352 static bool IsVoidOfLiteral(Expression* expr) { |
348 UnaryOperation* maybe_unary = expr->AsUnaryOperation(); | 353 UnaryOperation* maybe_unary = expr->AsUnaryOperation(); |
349 return maybe_unary != NULL && | 354 return maybe_unary != NULL && |
350 maybe_unary->op() == Token::VOID && | 355 maybe_unary->op() == Token::VOID && |
351 maybe_unary->expression()->AsLiteral() != NULL; | 356 maybe_unary->expression()->AsLiteral() != NULL; |
352 } | 357 } |
353 | 358 |
354 | 359 |
355 // Check for the pattern: void <literal> equals <expression> | 360 // Check for the pattern: void <literal> equals <expression> or |
| 361 // undefined equals <expression> |
356 static bool MatchLiteralCompareUndefined(Expression* left, | 362 static bool MatchLiteralCompareUndefined(Expression* left, |
357 Token::Value op, | 363 Token::Value op, |
358 Expression* right, | 364 Expression* right, |
359 Expression** expr) { | 365 Expression** expr) { |
360 if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) { | 366 if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) { |
361 *expr = right; | 367 *expr = right; |
362 return true; | 368 return true; |
363 } | 369 } |
| 370 if (left->IsUndefinedLiteral() && Token::IsEqualityOp(op)) { |
| 371 *expr = right; |
| 372 return true; |
| 373 } |
364 return false; | 374 return false; |
365 } | 375 } |
366 | 376 |
367 | 377 |
368 bool CompareOperation::IsLiteralCompareUndefined(Expression** expr) { | 378 bool CompareOperation::IsLiteralCompareUndefined(Expression** expr) { |
369 return MatchLiteralCompareUndefined(left_, op_, right_, expr) || | 379 return MatchLiteralCompareUndefined(left_, op_, right_, expr) || |
370 MatchLiteralCompareUndefined(right_, op_, left_, expr); | 380 MatchLiteralCompareUndefined(right_, op_, left_, expr); |
371 } | 381 } |
372 | 382 |
373 | 383 |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); | 1124 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); |
1115 str = arr; | 1125 str = arr; |
1116 } else { | 1126 } else { |
1117 str = DoubleToCString(handle_->Number(), buffer); | 1127 str = DoubleToCString(handle_->Number(), buffer); |
1118 } | 1128 } |
1119 return FACTORY->NewStringFromAscii(CStrVector(str)); | 1129 return FACTORY->NewStringFromAscii(CStrVector(str)); |
1120 } | 1130 } |
1121 | 1131 |
1122 | 1132 |
1123 } } // namespace v8::internal | 1133 } } // namespace v8::internal |
OLD | NEW |