Index: src/ast.cc |
diff --git a/src/ast.cc b/src/ast.cc |
index 964f5bc76e2ea88b9b0f16fac9f167ed3d5bd927..f34c7bb24aac7d500016acb4d62a846eadf82ce1 100644 |
--- a/src/ast.cc |
+++ b/src/ast.cc |
@@ -71,8 +71,14 @@ bool Expression::IsNullLiteral() { |
} |
-bool Expression::IsUndefinedLiteral() { |
- return AsLiteral() != NULL && AsLiteral()->value()->IsUndefined(); |
+bool Expression::IsUndefinedLiteral(Isolate* isolate) { |
+ VariableProxy* var_proxy = AsVariableProxy(); |
+ if (var_proxy == NULL) return false; |
+ Variable* var = var_proxy->var(); |
+ // The global identifier "undefined" is immutable. Everything |
+ // else could be reassigned. |
+ return var != NULL && var->location() == Variable::UNALLOCATED && |
+ var_proxy->name()->Equals(isolate->heap()->undefined_string()); |
} |
@@ -385,12 +391,13 @@ static bool IsVoidOfLiteral(Expression* expr) { |
static bool MatchLiteralCompareUndefined(Expression* left, |
Token::Value op, |
Expression* right, |
- Expression** expr) { |
+ Expression** expr, |
+ Isolate* isolate) { |
if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) { |
*expr = right; |
return true; |
} |
- if (left->IsUndefinedLiteral() && Token::IsEqualityOp(op)) { |
+ if (left->IsUndefinedLiteral(isolate) && Token::IsEqualityOp(op)) { |
*expr = right; |
return true; |
} |
@@ -398,9 +405,10 @@ static bool MatchLiteralCompareUndefined(Expression* left, |
} |
-bool CompareOperation::IsLiteralCompareUndefined(Expression** expr) { |
- return MatchLiteralCompareUndefined(left_, op_, right_, expr) || |
- MatchLiteralCompareUndefined(right_, op_, left_, expr); |
+bool CompareOperation::IsLiteralCompareUndefined( |
+ Expression** expr, Isolate* isolate) { |
+ return MatchLiteralCompareUndefined(left_, op_, right_, expr, isolate) || |
+ MatchLiteralCompareUndefined(right_, op_, left_, expr, isolate); |
} |