Skip to content

Commit 815f91c

Browse files
hferreiroCommit bot
authored andcommitted
[es6] Perform the IsConstructor test in GetSuperConstructor.
This is so that a NotSuperConstructor error is thrown before evaluating the arguments to the super constructor. Besides updating the runtime function, a new bytecode GetSuperConstructor is introduced. BUG=v8:5336 Review-Url: https://codereview.chromium.org/2504553003 Cr-Commit-Position: refs/heads/master@{#41788}
1 parent b695c38 commit 815f91c

35 files changed

Lines changed: 196 additions & 40 deletions

src/builtins/builtins-object.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,5 +1078,17 @@ void Builtins::Generate_OrdinaryHasInstance(
10781078
assembler.Return(assembler.OrdinaryHasInstance(context, constructor, object));
10791079
}
10801080

1081+
void Builtins::Generate_GetSuperConstructor(
1082+
compiler::CodeAssemblerState* state) {
1083+
typedef compiler::Node Node;
1084+
typedef TypeofDescriptor Descriptor;
1085+
CodeStubAssembler assembler(state);
1086+
1087+
Node* object = assembler.Parameter(Descriptor::kObject);
1088+
Node* context = assembler.Parameter(Descriptor::kContext);
1089+
1090+
assembler.Return(assembler.GetSuperConstructor(object, context));
1091+
}
1092+
10811093
} // namespace internal
10821094
} // namespace v8

src/builtins/builtins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ namespace internal {
179179
TFS(ToInteger, BUILTIN, kNoExtraICState, TypeConversion) \
180180
TFS(ToLength, BUILTIN, kNoExtraICState, TypeConversion) \
181181
TFS(Typeof, BUILTIN, kNoExtraICState, Typeof) \
182+
TFS(GetSuperConstructor, BUILTIN, kNoExtraICState, TypeConversion) \
182183
\
183184
/* Handlers */ \
184185
TFS(KeyedLoadIC_Megamorphic_TF, KEYED_LOAD_IC, kNoExtraICState, \

src/code-factory.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ TFS_BUILTIN(ForInFilter)
251251
TFS_BUILTIN(NewUnmappedArgumentsElements)
252252
TFS_BUILTIN(NewRestParameterElements)
253253
TFS_BUILTIN(PromiseHandleReject)
254+
TFS_BUILTIN(GetSuperConstructor)
254255

255256
#undef TFS_BUILTIN
256257

src/code-factory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class V8_EXPORT_PRIVATE CodeFactory final {
128128
static Callable SubString(Isolate* isolate);
129129

130130
static Callable Typeof(Isolate* isolate);
131+
static Callable GetSuperConstructor(Isolate* isolate);
131132

132133
static Callable FastCloneRegExp(Isolate* isolate);
133134
static Callable FastCloneShallowArray(Isolate* isolate);

src/code-stub-assembler.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,13 @@ Node* CodeStubAssembler::IsCallableMap(Node* map) {
28962896
Int32Constant(0));
28972897
}
28982898

2899+
Node* CodeStubAssembler::IsConstructorMap(Node* map) {
2900+
CSA_ASSERT(this, IsMap(map));
2901+
return Word32NotEqual(
2902+
Word32And(LoadMapBitField(map), Int32Constant(1 << Map::kIsConstructor)),
2903+
Int32Constant(0));
2904+
}
2905+
28992906
Node* CodeStubAssembler::IsSpecialReceiverInstanceType(Node* instance_type) {
29002907
STATIC_ASSERT(JS_GLOBAL_OBJECT_TYPE <= LAST_SPECIAL_RECEIVER_TYPE);
29012908
return Int32LessThanOrEqual(instance_type,
@@ -2992,6 +2999,10 @@ Node* CodeStubAssembler::IsUnseededNumberDictionary(Node* object) {
29922999
LoadRoot(Heap::kUnseededNumberDictionaryMapRootIndex));
29933000
}
29943001

3002+
Node* CodeStubAssembler::IsJSFunction(Node* object) {
3003+
return HasInstanceType(object, JS_FUNCTION_TYPE);
3004+
}
3005+
29953006
Node* CodeStubAssembler::StringCharCodeAt(Node* string, Node* index) {
29963007
CSA_ASSERT(this, IsString(string));
29973008
// Translate the {index} into a Word.
@@ -7846,6 +7857,32 @@ Node* CodeStubAssembler::Typeof(Node* value, Node* context) {
78467857
return result_var.value();
78477858
}
78487859

7860+
Node* CodeStubAssembler::GetSuperConstructor(Node* active_function,
7861+
Node* context) {
7862+
CSA_ASSERT(this, IsJSFunction(active_function));
7863+
7864+
Label is_not_constructor(this, Label::kDeferred), out(this);
7865+
Variable result(this, MachineRepresentation::kTagged);
7866+
7867+
Node* map = LoadMap(active_function);
7868+
Node* prototype = LoadMapPrototype(map);
7869+
Node* prototype_map = LoadMap(prototype);
7870+
GotoUnless(IsConstructorMap(prototype_map), &is_not_constructor);
7871+
7872+
result.Bind(prototype);
7873+
Goto(&out);
7874+
7875+
Bind(&is_not_constructor);
7876+
{
7877+
result.Bind(CallRuntime(Runtime::kThrowNotSuperConstructor, context,
7878+
prototype, active_function));
7879+
Goto(&out);
7880+
}
7881+
7882+
Bind(&out);
7883+
return result.value();
7884+
}
7885+
78497886
Node* CodeStubAssembler::InstanceOf(Node* object, Node* callable,
78507887
Node* context) {
78517888
Label return_runtime(this, Label::kDeferred), end(this);

src/code-stub-assembler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
658658
Node* IsHashTable(Node* object);
659659
Node* IsDictionary(Node* object);
660660
Node* IsUnseededNumberDictionary(Node* object);
661+
Node* IsConstructorMap(Node* map);
662+
Node* IsJSFunction(Node* object);
661663

662664
// ElementsKind helpers:
663665
Node* IsFastElementsKind(Node* elements_kind);
@@ -1078,6 +1080,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
10781080

10791081
Node* Typeof(Node* value, Node* context);
10801082

1083+
Node* GetSuperConstructor(Node* value, Node* context);
1084+
10811085
Node* InstanceOf(Node* object, Node* callable, Node* context);
10821086

10831087
// Debug helpers

src/compiler/bytecode-graph-builder.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,13 @@ void BytecodeGraphBuilder::VisitDeletePropertySloppy() {
16261626
BuildDelete(LanguageMode::SLOPPY);
16271627
}
16281628

1629+
void BytecodeGraphBuilder::VisitGetSuperConstructor() {
1630+
Node* node = NewNode(javascript()->GetSuperConstructor(),
1631+
environment()->LookupAccumulator());
1632+
environment()->BindRegister(bytecode_iterator().GetRegisterOperand(0), node,
1633+
Environment::kAttachFrameState);
1634+
}
1635+
16291636
void BytecodeGraphBuilder::BuildCompareOp(const Operator* js_op) {
16301637
PrepareEagerCheckpoint();
16311638
Node* left =

src/compiler/js-generic-lowering.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ void JSGenericLowering::LowerJSDeleteProperty(Node* node) {
273273
: Runtime::kDeleteProperty_Sloppy);
274274
}
275275

276+
void JSGenericLowering::LowerJSGetSuperConstructor(Node* node) {
277+
CallDescriptor::Flags flags = FrameStateFlagForCall(node);
278+
Callable callable = CodeFactory::GetSuperConstructor(isolate());
279+
ReplaceWithStubCall(node, callable, flags);
280+
}
281+
276282
void JSGenericLowering::LowerJSInstanceOf(Node* node) {
277283
CallDescriptor::Flags flags = FrameStateFlagForCall(node);
278284
Callable callable = CodeFactory::InstanceOf(isolate());

src/compiler/js-operator.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ CompareOperationHint CompareOperationHintOf(const Operator* op) {
480480
V(StoreMessage, Operator::kNoThrow, 1, 0) \
481481
V(GeneratorRestoreContinuation, Operator::kNoThrow, 1, 1) \
482482
V(StackCheck, Operator::kNoWrite, 0, 0) \
483+
V(GetSuperConstructor, Operator::kNoWrite, 1, 1) \
483484
V(StoreDataPropertyInLiteral, Operator::kNoProperties, 5, 0)
484485

485486
#define BINARY_OP_LIST(V) \

src/compiler/js-operator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ class V8_EXPORT_PRIVATE JSOperatorBuilder final
521521

522522
const Operator* HasProperty();
523523

524+
const Operator* GetSuperConstructor();
525+
524526
const Operator* LoadGlobal(const Handle<Name>& name,
525527
const VectorSlotPair& feedback,
526528
TypeofMode typeof_mode = NOT_INSIDE_TYPEOF);

0 commit comments

Comments
 (0)