Index: src/hydrogen.cc |
=================================================================== |
--- src/hydrogen.cc (revision 7218) |
+++ src/hydrogen.cc (working copy) |
@@ -1961,10 +1961,7 @@ |
// Implementation of utility classes to represent an expression's context in |
// the AST. |
AstContext::AstContext(HGraphBuilder* owner, Expression::Context kind) |
- : owner_(owner), |
- kind_(kind), |
- outer_(owner->ast_context()), |
- for_typeof_(false) { |
+ : owner_(owner), kind_(kind), outer_(owner->ast_context()) { |
owner->set_ast_context(this); // Push. |
#ifdef DEBUG |
original_length_ = owner->environment()->length(); |
@@ -2108,14 +2105,6 @@ |
} |
-void HGraphBuilder::VisitForTypeOf(Expression* expr) { |
- ValueContext for_value(this); |
- for_value.set_for_typeof(true); |
- Visit(expr); |
-} |
- |
- |
- |
void HGraphBuilder::VisitForControl(Expression* expr, |
HBasicBlock* true_block, |
HBasicBlock* false_block) { |
@@ -2808,21 +2797,29 @@ |
} |
-HGraphBuilder::GlobalPropertyAccess HGraphBuilder::LookupGlobalProperty( |
- Variable* var, LookupResult* lookup, bool is_store) { |
- if (var->is_this() || !info()->has_global_object()) { |
- return kUseGeneric; |
+void HGraphBuilder::LookupGlobalPropertyCell(Variable* var, |
+ LookupResult* lookup, |
+ bool is_store) { |
+ if (var->is_this()) { |
+ BAILOUT("global this reference"); |
} |
+ if (!info()->has_global_object()) { |
+ BAILOUT("no global object to optimize VariableProxy"); |
+ } |
Handle<GlobalObject> global(info()->global_object()); |
global->Lookup(*var->name(), lookup); |
- if (!lookup->IsProperty() || |
- lookup->type() != NORMAL || |
- (is_store && lookup->IsReadOnly()) || |
- lookup->holder() != *global) { |
- return kUseGeneric; |
+ if (!lookup->IsProperty()) { |
+ BAILOUT("global variable cell not yet introduced"); |
} |
- |
- return kUseCell; |
+ if (lookup->type() != NORMAL) { |
+ BAILOUT("global variable has accessors"); |
+ } |
+ if (is_store && lookup->IsReadOnly()) { |
+ BAILOUT("read-only global variable"); |
+ } |
+ if (lookup->holder() != *global) { |
+ BAILOUT("global property on prototype of global object"); |
+ } |
} |
@@ -2858,31 +2855,19 @@ |
ast_context()->ReturnInstruction(instr, expr->id()); |
} else if (variable->is_global()) { |
LookupResult lookup; |
- GlobalPropertyAccess type = LookupGlobalProperty(variable, &lookup, false); |
+ LookupGlobalPropertyCell(variable, &lookup, false); |
+ CHECK_BAILOUT; |
- if (type == kUseCell && |
- info()->global_object()->IsAccessCheckNeeded()) { |
- type = kUseGeneric; |
+ Handle<GlobalObject> global(info()->global_object()); |
+ // TODO(3039103): Handle global property load through an IC call when access |
+ // checks are enabled. |
+ if (global->IsAccessCheckNeeded()) { |
+ BAILOUT("global object requires access check"); |
} |
- |
- if (type == kUseCell) { |
- Handle<GlobalObject> global(info()->global_object()); |
- Handle<JSGlobalPropertyCell> cell(global->GetPropertyCell(&lookup)); |
- bool check_hole = !lookup.IsDontDelete() || lookup.IsReadOnly(); |
- HLoadGlobalCell* instr = new HLoadGlobalCell(cell, check_hole); |
- ast_context()->ReturnInstruction(instr, expr->id()); |
- } else { |
- HContext* context = new HContext; |
- AddInstruction(context); |
- HGlobalObject* global_object = new HGlobalObject(context); |
- AddInstruction(global_object); |
- HLoadGlobalGeneric* instr = |
- new HLoadGlobalGeneric(context, |
- global_object, |
- variable->name(), |
- ast_context()->is_for_typeof()); |
- ast_context()->ReturnInstruction(instr, expr->id()); |
- } |
+ Handle<JSGlobalPropertyCell> cell(global->GetPropertyCell(&lookup)); |
+ bool check_hole = !lookup.IsDontDelete() || lookup.IsReadOnly(); |
+ HLoadGlobal* instr = new HLoadGlobal(cell, check_hole); |
+ ast_context()->ReturnInstruction(instr, expr->id()); |
} else { |
BAILOUT("reference to a variable which requires dynamic lookup"); |
} |
@@ -3239,18 +3224,16 @@ |
int position, |
int ast_id) { |
LookupResult lookup; |
- GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, true); |
- if (type == kUseCell) { |
- bool check_hole = !lookup.IsDontDelete() || lookup.IsReadOnly(); |
- Handle<GlobalObject> global(info()->global_object()); |
- Handle<JSGlobalPropertyCell> cell(global->GetPropertyCell(&lookup)); |
- HInstruction* instr = new HStoreGlobal(value, cell, check_hole); |
- instr->set_position(position); |
- AddInstruction(instr); |
- if (instr->HasSideEffects()) AddSimulate(ast_id); |
- } else { |
- BAILOUT("global store only supported for cells"); |
- } |
+ LookupGlobalPropertyCell(var, &lookup, true); |
+ CHECK_BAILOUT; |
+ |
+ bool check_hole = !lookup.IsDontDelete() || lookup.IsReadOnly(); |
+ Handle<GlobalObject> global(info()->global_object()); |
+ Handle<JSGlobalPropertyCell> cell(global->GetPropertyCell(&lookup)); |
+ HInstruction* instr = new HStoreGlobal(value, cell, check_hole); |
+ instr->set_position(position); |
+ AddInstruction(instr); |
+ if (instr->HasSideEffects()) AddSimulate(ast_id); |
} |
@@ -4345,12 +4328,10 @@ |
// If there is a global property cell for the name at compile time and |
// access check is not enabled we assume that the function will not change |
// and generate optimized code for calling the function. |
- LookupResult lookup; |
- GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, false); |
- if (type == kUseCell && |
+ if (info()->has_global_object() && |
!info()->global_object()->IsAccessCheckNeeded()) { |
Handle<GlobalObject> global(info()->global_object()); |
- known_global_function = expr->ComputeGlobalTarget(global, &lookup); |
+ known_global_function = expr->ComputeGlobalTarget(global, var->name()); |
} |
if (known_global_function) { |
// Push the global object instead of the global receiver because |
@@ -4553,8 +4534,7 @@ |
} |
} else if (op == Token::TYPEOF) { |
- VisitForTypeOf(expr->expression()); |
- if (HasStackOverflow()) return; |
+ VISIT_FOR_VALUE(expr->expression()); |
HValue* value = Pop(); |
ast_context()->ReturnInstruction(new HTypeof(value), expr->id()); |
@@ -4957,8 +4937,7 @@ |
if ((expr->op() == Token::EQ || expr->op() == Token::EQ_STRICT) && |
left_unary != NULL && left_unary->op() == Token::TYPEOF && |
right_literal != NULL && right_literal->handle()->IsString()) { |
- VisitForTypeOf(left_unary->expression()); |
- if (HasStackOverflow()) return; |
+ VISIT_FOR_VALUE(left_unary->expression()); |
HValue* left = Pop(); |
HInstruction* instr = new HTypeofIs(left, |
Handle<String>::cast(right_literal->handle())); |