Skip to content

Commit 44068f0

Browse files
committed
Fix super() in constructor that contains object literal with a method or a get/set.
1 parent c95c450 commit 44068f0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/Parser/Parse.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4297,6 +4297,7 @@ ParseNodeBin * Parser::ParseMemberGetSet(OpCode nop, LPCOLESTR* ppNameHint)
42974297
flags |= fFncOneArg;
42984298
}
42994299

4300+
AutoParsingSuperRestrictionStateRestorer restorer(this);
43004301
this->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
43014302
ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(flags, *ppNameHint,
43024303
/*needsPIDOnRCurlyScan*/ false, /*resetParsingSuperRestrictionState*/ false);
@@ -4609,6 +4610,8 @@ ParseNodePtr Parser::ParseMemberList(LPCOLESTR pNameHint, uint32* pNameHintLengt
46094610

46104611
// Rewind to the PID and parse a function expression.
46114612
this->GetScanner()->SeekTo(atPid);
4613+
4614+
AutoParsingSuperRestrictionStateRestorer restorer(this);
46124615
this->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
46134616
ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isAsyncMethod ? fFncAsync : fFncNoFlgs), pFullNameHint,
46144617
/*needsPIDOnRCurlyScan*/ false, /*resetParsingSuperRestrictionState*/ false);

test/es6/classes.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,39 @@ var tests = [
486486
assert.isTrue(classB.lambdaIndex() === 'method A', "classB.lambdaIndex() === 'method A'");
487487
}
488488
},
489+
{
490+
name: "Super used after object literal in constructor",
491+
body: function () {
492+
class emptyLiteral extends Object{
493+
constructor(){
494+
const bar = {};
495+
super();
496+
}
497+
}
498+
class methodLiteral extends Object{
499+
constructor(){
500+
const bar = { c () {}};
501+
super();
502+
}
503+
}
504+
class functionLiteral extends Object{
505+
constructor(){
506+
const bar = { c : function () {}};
507+
super();
508+
}
509+
}
510+
class getSetLiteral extends Object{
511+
constructor(){
512+
const bar = { hid : 5, get c () {return hid;}, set c (x) { hid = x; }};
513+
super();
514+
}
515+
}
516+
assert.doesNotThrow(()=>{new emptyLiteral()}, "Super should be valid in constructor after literal.");
517+
assert.doesNotThrow(()=>{new methodLiteral()}, "Super should be valid in constructor after literal.");
518+
assert.doesNotThrow(()=>{new functionLiteral()}, "Super should be valid in constructor after literal.");
519+
assert.doesNotThrow(()=>{new getSetLiteral()}, "Super should be valid in constructor after literal.");
520+
}
521+
},
489522
{
490523
name: "Super used outside the class declaration function",
491524
body: function () {

0 commit comments

Comments
 (0)