Reviewers: arv, Igor Sheludko, Toon Verwaest,
Message:
FYI, before platform ports.
Take a look if you have time.
Description:
Implement the new semanticts for 'super(...)'
Per the latest ES6 draft, super(...) translates into a call
to function's prototype.
[email protected],[email protected],[email protected]
BUG=v8:3330
LOG=N
Please review this at https://codereview.chromium.org/661433002/
Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+18, -10 lines):
M src/ast.h
M src/ast.cc
M src/compiler/ast-graph-builder.cc
M src/ia32/full-codegen-ia32.cc
M test/mjsunit/harmony/super.js
Index: src/ast.cc
diff --git a/src/ast.cc b/src/ast.cc
index
fdf2d55763edaa8920332f6a04d24b2408139cf4..2acb2f5f365a0922c95e0e542439d11195b8fbc4
100644
--- a/src/ast.cc
+++ b/src/ast.cc
@@ -581,6 +581,8 @@ Call::CallType Call::GetCallType(Isolate* isolate)
const {
}
}
+ if (expression()->AsSuperReference() != NULL) return SUPER_CALL;
+
Property* property = expression()->AsProperty();
return property != NULL ? PROPERTY_CALL : OTHER_CALL;
}
Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index
61f97320945fcce5de42446bd64666640b3da114..847d9cae2b68bcbb93d8b4711a2b110ccd2b30e0
100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -1851,6 +1851,7 @@ class Call FINAL : public Expression {
GLOBAL_CALL,
LOOKUP_SLOT_CALL,
PROPERTY_CALL,
+ SUPER_CALL,
OTHER_CALL
};
@@ -3474,16 +3475,7 @@ class AstNodeFactory FINAL BASE_EMBEDDED {
Call* NewCall(Expression* expression,
ZoneList<Expression*>* arguments,
int pos) {
- SuperReference* super_ref = expression->AsSuperReference();
- Call* call;
- if (super_ref != NULL) {
- Literal* constructor =
- NewStringLiteral(ast_value_factory_->constructor_string(), pos);
- Property* superConstructor = NewProperty(super_ref, constructor,
pos);
- call = new (zone_) Call(zone_, superConstructor, arguments, pos,
id_gen_);
- } else {
- call = new (zone_) Call(zone_, expression, arguments, pos, id_gen_);
- }
+ Call* call = new (zone_) Call(zone_, expression, arguments, pos,
id_gen_);
VISIT_AND_RETURN(Call, call)
}
Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc
b/src/compiler/ast-graph-builder.cc
index
9c11c658a62763401f6f022078bd2b58751b8c62..ed4e689fe73a10f7bb0e61fc51e0ab505161de8a
100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -1261,6 +1261,11 @@ void AstGraphBuilder::VisitCall(Call* expr) {
flags = CALL_AS_METHOD;
break;
}
+ case Call::SUPER_CALL: {
+ // todo(dslomov): implement super calls in turbofan.
+ UNREACHABLE();
+ break;
+ }
case Call::POSSIBLY_EVAL_CALL:
possibly_eval = true;
// Fall through.
Index: src/ia32/full-codegen-ia32.cc
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
index
ad838b97951fdaea9feb144ab3b49200b8d87474..811680cbc5976da641445f2a08379090e0889061
100644
--- a/src/ia32/full-codegen-ia32.cc
+++ b/src/ia32/full-codegen-ia32.cc
@@ -2972,6 +2972,14 @@ void FullCodeGenerator::VisitCall(Call* expr) {
EmitKeyedCallWithLoadIC(expr, property->key());
}
}
+ } else if (call_type == Call::SUPER_CALL) {
+ SuperReference* super_ref = callee->AsSuperReference();
+ DCHECK(super_ref != NULL);
+ __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
+ __ CallRuntime(Runtime::kGetPrototype, 1);
+ __ push(result_register());
+ VisitForStackValue(super_ref->this_var());
+ EmitCall(expr, CallICState::METHOD);
} else {
DCHECK(call_type == Call::OTHER_CALL);
// Call to an arbitrary expression not handled specially above.
Index: test/mjsunit/harmony/super.js
diff --git a/test/mjsunit/harmony/super.js b/test/mjsunit/harmony/super.js
index
130c010a4db65f7e9d70e063c133317c55df72f4..82013ec39b893d205920b34f11d2897e940449ed
100644
--- a/test/mjsunit/harmony/super.js
+++ b/test/mjsunit/harmony/super.js
@@ -1194,6 +1194,7 @@
function Subclass(base, constructor) {
var homeObject = { __proto__ : base.prototype };
var result = constructor.toMethod(homeObject);
+ result.__proto__ = base;
homeObject.constructor = result;
result.prototype = homeObject;
return result;
--
--
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.