| Index: src/hydrogen.cc
|
| ===================================================================
|
| --- src/hydrogen.cc (revision 7468)
|
| +++ src/hydrogen.cc (working copy)
|
| @@ -1980,7 +1980,10 @@
|
| // 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()) {
|
| + : owner_(owner),
|
| + kind_(kind),
|
| + outer_(owner->ast_context()),
|
| + for_typeof_(false) {
|
| owner->set_ast_context(this); // Push.
|
| #ifdef DEBUG
|
| original_length_ = owner->environment()->length();
|
| @@ -2124,6 +2127,14 @@
|
| }
|
|
|
|
|
| +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) {
|
| @@ -2833,29 +2844,21 @@
|
| }
|
|
|
|
|
| -void HGraphBuilder::LookupGlobalPropertyCell(Variable* var,
|
| - LookupResult* lookup,
|
| - bool is_store) {
|
| - if (var->is_this()) {
|
| - BAILOUT("global this reference");
|
| +HGraphBuilder::GlobalPropertyAccess HGraphBuilder::LookupGlobalProperty(
|
| + Variable* var, LookupResult* lookup, bool is_store) {
|
| + if (var->is_this() || !info()->has_global_object()) {
|
| + return kUseGeneric;
|
| }
|
| - 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()) {
|
| - BAILOUT("global variable cell not yet introduced");
|
| + if (!lookup->IsProperty() ||
|
| + lookup->type() != NORMAL ||
|
| + (is_store && lookup->IsReadOnly()) ||
|
| + lookup->holder() != *global) {
|
| + return kUseGeneric;
|
| }
|
| - 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");
|
| - }
|
| +
|
| + return kUseCell;
|
| }
|
|
|
|
|
| @@ -2891,19 +2894,33 @@
|
| ast_context()->ReturnInstruction(instr, expr->id());
|
| } else if (variable->is_global()) {
|
| LookupResult lookup;
|
| - LookupGlobalPropertyCell(variable, &lookup, false);
|
| - CHECK_BAILOUT;
|
| + GlobalPropertyAccess type = LookupGlobalProperty(variable, &lookup, false);
|
|
|
| - 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 &&
|
| + info()->global_object()->IsAccessCheckNeeded()) {
|
| + type = kUseGeneric;
|
| }
|
| - 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());
|
| +
|
| + 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());
|
| + instr->set_position(expr->position());
|
| + ASSERT(instr->HasSideEffects());
|
| + ast_context()->ReturnInstruction(instr, expr->id());
|
| + }
|
| } else {
|
| BAILOUT("reference to a variable which requires dynamic lookup");
|
| }
|
| @@ -3274,16 +3291,18 @@
|
| int position,
|
| int ast_id) {
|
| LookupResult lookup;
|
| - 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);
|
| + 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");
|
| + }
|
| }
|
|
|
|
|
| @@ -4311,10 +4330,12 @@
|
| // 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.
|
| - if (info()->has_global_object() &&
|
| + LookupResult lookup;
|
| + GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, false);
|
| + if (type == kUseCell &&
|
| !info()->global_object()->IsAccessCheckNeeded()) {
|
| Handle<GlobalObject> global(info()->global_object());
|
| - known_global_function = expr->ComputeGlobalTarget(global, var->name());
|
| + known_global_function = expr->ComputeGlobalTarget(global, &lookup);
|
| }
|
| if (known_global_function) {
|
| // Push the global object instead of the global receiver because
|
| @@ -4517,7 +4538,8 @@
|
| }
|
|
|
| } else if (op == Token::TYPEOF) {
|
| - VISIT_FOR_VALUE(expr->expression());
|
| + VisitForTypeOf(expr->expression());
|
| + if (HasStackOverflow()) return;
|
| HValue* value = Pop();
|
| ast_context()->ReturnInstruction(new HTypeof(value), expr->id());
|
|
|
| @@ -4920,7 +4942,8 @@
|
| 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()) {
|
| - VISIT_FOR_VALUE(left_unary->expression());
|
| + VisitForTypeOf(left_unary->expression());
|
| + if (HasStackOverflow()) return;
|
| HValue* left = Pop();
|
| HInstruction* instr = new HTypeofIs(left,
|
| Handle<String>::cast(right_literal->handle()));
|
|
|