Reviewers: rossberg,

Message:
Note that this is not yet intended to be landed, it should just serve as food
for thought on how to cleanup the initialization of "this" in derived
constructors. Let me know if you have ideas on how to get this cleaned up.

Description:
[turbofan] [WIP] Implement super call support in TurboFan.

[email protected]

Please review this at https://codereview.chromium.org/1238743002/

Base URL: https://chromium.googlesource.com/v8/v8.git@local_turbofan-super-2

Affected files (+40, -11 lines):
  M src/compiler/ast-graph-builder.cc
  M src/compiler/js-generic-lowering.cc


Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc index f442017cd86b8fcdc4b463ea5e38ea242183dcc3..284088176792013529cf4f15cd835c82bcf1bee3 100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -2513,7 +2513,7 @@ void AstGraphBuilder::VisitCallSuper(Call* expr) {
   ZoneList<Expression*>* args = expr->arguments();
   VisitForValues(args);

-  // Original receiver is loaded from the {new.target} variable.
+  // Original constructor is loaded from the {new.target} variable.
   VisitForValue(super->new_target_var());

   // Create node to perform the super call.
@@ -2521,14 +2521,43 @@ void AstGraphBuilder::VisitCallSuper(Call* expr) {
   Node* value = ProcessArguments(call, args->length() + 2);
   PrepareFrameState(value, expr->id(), ast_context()->GetStateCombine());

- // TODO(mstarzinger): It sure would be nice if this were desugared. Also we
-  // are still missing the hole-check in the assignment below, fix that.
-  FrameStateBeforeAndAfter states(this, BailoutId::None());
- BuildVariableAssignment(super->this_var()->var(), value, Token::INIT_CONST,
-                          VectorSlotPair(), BailoutId::None(), states);
-
-  // TODO(mstarzinger): Remove bailout once lowering is correct.
-  SetStackOverflow();
+ // TODO(mstarzinger): It sure would be nice if this were desugared. In fact,
+  // the entire block below makes me want to stand in the corner and cry.
+  {
+    Variable* variable = super->this_var()->var();
+    Node* previous = jsgraph()->TheHoleConstant();
+    switch (variable->location()) {
+      case VariableLocation::PARAMETER:
+        previous = environment()->Lookup(variable);
+        break;
+      case VariableLocation::CONTEXT: {
+        int index = variable->index();
+        int depth = current_scope()->ContextChainLength(variable->scope());
+        bool immutable = variable->maybe_assigned() == kNotAssigned;
+ const Operator* op = javascript()->LoadContext(depth, index, immutable);
+        previous = NewNode(op, current_context());
+        break;
+      }
+      default:
+        UNREACHABLE();
+    }
+    {
+      IfBuilder hole_check(this);
+      Node* the_hole = jsgraph()->TheHoleConstant();
+ Node* check = NewNode(javascript()->StrictEqual(), previous, the_hole);
+      hole_check.If(check);
+      hole_check.Then();
+      environment()->Push(value);
+      hole_check.Else();
+      Node* error = BuildThrowReferenceError(variable, expr->id());
+      environment()->Push(error);
+      hole_check.End();
+      value = environment()->Pop();
+    }
+    FrameStateBeforeAndAfter states(this, BailoutId::None());
+    BuildVariableAssignment(variable, value, Token::INIT_CONST,
+                            VectorSlotPair(), BailoutId::None(), states);
+  }

   ast_context()->ProduceValue(value);
 }
@@ -2541,7 +2570,7 @@ void AstGraphBuilder::VisitCallNew(CallNew* expr) {
   ZoneList<Expression*>* args = expr->arguments();
   VisitForValues(args);

-  // Original receiver is the same as the callee.
+  // Original constructor is the same as the callee.
   environment()->Push(environment()->Peek(args->length()));

   // Create node to perform the construct call.
Index: src/compiler/js-generic-lowering.cc
diff --git a/src/compiler/js-generic-lowering.cc b/src/compiler/js-generic-lowering.cc index 84ee3933e22a28ba715417ed7222fdca7aa117bd..e3e4cddd8a3697723d31b376527f2b876153ca56 100644
--- a/src/compiler/js-generic-lowering.cc
+++ b/src/compiler/js-generic-lowering.cc
@@ -537,7 +537,7 @@ void JSGenericLowering::LowerJSCreateCatchContext(Node* node) {

 void JSGenericLowering::LowerJSCallConstruct(Node* node) {
   int arity = OpParameter<int>(node);
-  CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS);
+  CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL);
   CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor();
   CallDescriptor::Flags flags = AdjustFrameStatesForCall(node);
   CallDescriptor* desc =


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to