| 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() { | 73 bool Expression::IsUndefinedLiteral(Isolate* isolate) { |
| 74 return AsLiteral() != NULL && AsLiteral()->handle()->IsUndefined(); | 74 VariableProxy* var_proxy = AsVariableProxy(); |
| 75 if (var_proxy == NULL) return false; |
| 76 Variable* var = var_proxy->var(); |
| 77 // The global identifier "undefined" is immutable. Everything |
| 78 // else could be reassigned. |
| 79 return var != NULL && var->location() == Variable::UNALLOCATED && |
| 80 var_proxy->name()->Equals(isolate->heap()->undefined_string()); |
| 75 } | 81 } |
| 76 | 82 |
| 77 | 83 |
| 78 VariableProxy::VariableProxy(Isolate* isolate, Variable* var) | 84 VariableProxy::VariableProxy(Isolate* isolate, Variable* var) |
| 79 : Expression(isolate), | 85 : Expression(isolate), |
| 80 name_(var->name()), | 86 name_(var->name()), |
| 81 var_(NULL), // Will be set by the call to BindTo. | 87 var_(NULL), // Will be set by the call to BindTo. |
| 82 is_this_(var->is_this()), | 88 is_this_(var->is_this()), |
| 83 is_trivial_(false), | 89 is_trivial_(false), |
| 84 is_lvalue_(false), | 90 is_lvalue_(false), |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 maybe_unary->op() == Token::VOID && | 361 maybe_unary->op() == Token::VOID && |
| 356 maybe_unary->expression()->AsLiteral() != NULL; | 362 maybe_unary->expression()->AsLiteral() != NULL; |
| 357 } | 363 } |
| 358 | 364 |
| 359 | 365 |
| 360 // Check for the pattern: void <literal> equals <expression> or | 366 // Check for the pattern: void <literal> equals <expression> or |
| 361 // undefined equals <expression> | 367 // undefined equals <expression> |
| 362 static bool MatchLiteralCompareUndefined(Expression* left, | 368 static bool MatchLiteralCompareUndefined(Expression* left, |
| 363 Token::Value op, | 369 Token::Value op, |
| 364 Expression* right, | 370 Expression* right, |
| 365 Expression** expr) { | 371 Expression** expr, |
| 372 Isolate* isolate) { |
| 366 if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) { | 373 if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) { |
| 367 *expr = right; | 374 *expr = right; |
| 368 return true; | 375 return true; |
| 369 } | 376 } |
| 370 if (left->IsUndefinedLiteral() && Token::IsEqualityOp(op)) { | 377 if (left->IsUndefinedLiteral(isolate) && Token::IsEqualityOp(op)) { |
| 371 *expr = right; | 378 *expr = right; |
| 372 return true; | 379 return true; |
| 373 } | 380 } |
| 374 return false; | 381 return false; |
| 375 } | 382 } |
| 376 | 383 |
| 377 | 384 |
| 378 bool CompareOperation::IsLiteralCompareUndefined(Expression** expr) { | 385 bool CompareOperation::IsLiteralCompareUndefined( |
| 379 return MatchLiteralCompareUndefined(left_, op_, right_, expr) || | 386 Expression** expr, Isolate* isolate) { |
| 380 MatchLiteralCompareUndefined(right_, op_, left_, expr); | 387 return MatchLiteralCompareUndefined(left_, op_, right_, expr, isolate) || |
| 388 MatchLiteralCompareUndefined(right_, op_, left_, expr, isolate); |
| 381 } | 389 } |
| 382 | 390 |
| 383 | 391 |
| 384 // Check for the pattern: null equals <expression> | 392 // Check for the pattern: null equals <expression> |
| 385 static bool MatchLiteralCompareNull(Expression* left, | 393 static bool MatchLiteralCompareNull(Expression* left, |
| 386 Token::Value op, | 394 Token::Value op, |
| 387 Expression* right, | 395 Expression* right, |
| 388 Expression** expr) { | 396 Expression** expr) { |
| 389 if (left->IsNullLiteral() && Token::IsEqualityOp(op)) { | 397 if (left->IsNullLiteral() && Token::IsEqualityOp(op)) { |
| 390 *expr = right; | 398 *expr = right; |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); | 1132 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); |
| 1125 str = arr; | 1133 str = arr; |
| 1126 } else { | 1134 } else { |
| 1127 str = DoubleToCString(handle_->Number(), buffer); | 1135 str = DoubleToCString(handle_->Number(), buffer); |
| 1128 } | 1136 } |
| 1129 return FACTORY->NewStringFromAscii(CStrVector(str)); | 1137 return FACTORY->NewStringFromAscii(CStrVector(str)); |
| 1130 } | 1138 } |
| 1131 | 1139 |
| 1132 | 1140 |
| 1133 } } // namespace v8::internal | 1141 } } // namespace v8::internal |
| OLD | NEW |