Skip to content

Commit 3fd052e

Browse files
committed
[MERGE chakra-core#5036 @rhuanjl] Restore SuperRestrictionState after methods fix chakra-core#5030
Merge pull request chakra-core#5036 from rhuanjl:fixSuper Wanted to learn more about how parsing works so thought I'd have a look at chakra-core#5030 And unless I've got this wrong the fix is very simple. When parsing a class member or a function the SuperRestrictionState is restored using AutoParsingSuperRestrictionStateRestorer after parsing the member or function is complete. This was not being done for getters/setters or methods within object literals. This had not previously been noticed as it's only relevant for getters/setters/methods that are declared in an object literal inside a class constructor before super is called - a somewhat niche case I assume.
2 parents 1e1a76b + 44068f0 commit 3fd052e

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)