Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit e3d6b28

Browse files
boingoingchakrabot
authored andcommitted
deps: update ChakraCore to chakra-core/ChakraCore@488faf3350
[1.8>1.9] [MERGE #4618 @boingoing] OS#14568840: Remove 'this' binding for indirect eval Merge pull request #4618 from boingoing:RemoveThisBindingIndirectEval Having a 'this' binding in the indirect eval leads to problems if there is a lambda capturing 'this' in the indirect eval. The lambda would try to load 'this' from a scope slot in the global scope of the indirect eval which asserts. Seems we can simplify the above by just removing the 'this' binding from the indirect eval. Then we'll simply load 'this' like an ordinary lambda at global scope would. Fixes: https://microsoft.visualstudio.com/web/wi.aspx?id=14568840 Reviewed-By: chakrabot <chakrabot@users.noreply.github.com>
1 parent 1316d0b commit e3d6b28

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

deps/chakrashim/core/lib/Parser/Parse.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,19 +1711,17 @@ ParseNodePtr Parser::CreateSpecialVarDeclIfNeeded(ParseNodePtr pnodeFnc, IdentPt
17111711
return nullptr;
17121712
}
17131713

1714-
void Parser::CreateSpecialSymbolDeclarations(ParseNodePtr pnodeFnc, bool isGlobal)
1714+
void Parser::CreateSpecialSymbolDeclarations(ParseNodePtr pnodeFnc)
17151715
{
17161716
// Lambda function cannot have any special bindings.
17171717
if (pnodeFnc->sxFnc.IsLambda())
17181718
{
17191719
return;
17201720
}
1721-
Assert(!(isGlobal && (this->m_grfscr & fscrEval)));
1722-
Assert(!isGlobal || (this->m_grfscr & fscrEvalCode));
17231721

17241722
bool isTopLevelEventHandler = (this->m_grfscr & fscrImplicitThis || this->m_grfscr & fscrImplicitParents) && !pnodeFnc->sxFnc.IsNested();
17251723

1726-
// Create a 'this' symbol for indirect eval, non-lambda functions with references to 'this', and all class constructors and top level event hanlders.
1724+
// Create a 'this' symbol for non-lambda functions with references to 'this', and all class constructors and top level event hanlders.
17271725
ParseNodePtr varDeclNode = CreateSpecialVarDeclIfNeeded(pnodeFnc, wellKnownPropertyPids._this, pnodeFnc->sxFnc.IsClassConstructor() || isTopLevelEventHandler);
17281726
if (varDeclNode)
17291727
{
@@ -1735,12 +1733,6 @@ void Parser::CreateSpecialSymbolDeclarations(ParseNodePtr pnodeFnc, bool isGloba
17351733
}
17361734
}
17371735

1738-
// Global code cannot have 'new.target' or 'super' bindings.
1739-
if (isGlobal)
1740-
{
1741-
return;
1742-
}
1743-
17441736
// Create a 'new.target' symbol for any ordinary function with a reference and all class constructors.
17451737
varDeclNode = CreateSpecialVarDeclIfNeeded(pnodeFnc, wellKnownPropertyPids._newTarget, pnodeFnc->sxFnc.IsClassConstructor());
17461738
if (varDeclNode)
@@ -5760,7 +5752,7 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
57605752
UpdateArgumentsNode(pnodeFnc, argNode);
57615753
}
57625754

5763-
CreateSpecialSymbolDeclarations(pnodeFnc, false);
5755+
CreateSpecialSymbolDeclarations(pnodeFnc);
57645756

57655757
// Restore the lists of scopes that contain function expressions.
57665758

@@ -7082,7 +7074,7 @@ ParseNodePtr Parser::GenerateEmptyConstructor(bool extends)
70827074

70837075
FinishParseBlock(pnodeInnerBlock);
70847076

7085-
CreateSpecialSymbolDeclarations(pnodeFnc, false);
7077+
CreateSpecialSymbolDeclarations(pnodeFnc);
70867078

70877079
FinishParseBlock(pnodeBlock);
70887080

@@ -11352,7 +11344,7 @@ void Parser::FinishDeferredFunction(ParseNodePtr pnodeScopeList)
1135211344
UpdateArgumentsNode(pnodeFnc, argNode);
1135311345
}
1135411346

11355-
CreateSpecialSymbolDeclarations(pnodeFnc, false);
11347+
CreateSpecialSymbolDeclarations(pnodeFnc);
1135611348

1135711349
this->FinishParseBlock(pnodeBlock);
1135811350
if (pnodeFncExprBlock)
@@ -11762,12 +11754,6 @@ ParseNodePtr Parser::Parse(LPCUTF8 pszSrc, size_t offset, size_t length, charcou
1176211754
if (tkEOF != m_token.tk)
1176311755
Error(ERRsyntax);
1176411756

11765-
// We only need to create special symbol bindings for 'this' for indirect eval
11766-
if ((this->m_grfscr & fscrEvalCode) && !(this->m_grfscr & fscrEval))
11767-
{
11768-
CreateSpecialSymbolDeclarations(pnodeProg, true);
11769-
}
11770-
1177111757
// Append an EndCode node.
1177211758
AddToNodeList(&pnodeProg->sxFnc.pnodeBody, &lastNodeRef,
1177311759
CreateNodeWithScanner<knopEndCode>());

deps/chakrashim/core/lib/Parser/Parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ class Parser
755755
void FinishParseFncExprScope(ParseNodePtr pnodeFnc, ParseNodePtr pnodeFncExprScope);
756756

757757
bool IsSpecialName(IdentPtr pid);
758-
void CreateSpecialSymbolDeclarations(ParseNodePtr pnodeFnc, bool isGlobal);
758+
void CreateSpecialSymbolDeclarations(ParseNodePtr pnodeFnc);
759759
ParseNodePtr ReferenceSpecialName(IdentPtr pid, charcount_t ichMin = 0, charcount_t ichLim = 0, bool createNode = false);
760760
ParseNodePtr CreateSpecialVarDeclIfNeeded(ParseNodePtr pnodeFnc, IdentPtr pid, bool forceCreate = false);
761761

deps/chakrashim/core/test/Basics/SpecialSymbolCapture.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,19 @@ var tests = [
961961
assert.throws(() => WScript.LoadScript(`(class classExpr {}())`), TypeError, "Class expression called at global scope", "Class constructor cannot be called without the new keyword");
962962
assert.throws(() => WScript.LoadScript(`(() => (class classExpr {}()))()`), TypeError, "Class expression called in global lambda", "Class constructor cannot be called without the new keyword");
963963
}
964+
},
965+
{
966+
name: "Indirect eval should not create a 'this' binding",
967+
body: function() {
968+
WScript.LoadScript(`
969+
this.eval("(() => assert.areEqual('global', this.o, 'Lambda in indirect eval called off of this capturing this'))()");
970+
this['eval']("(() => assert.areEqual('global', this.o, 'Lambda in indirect eval called from a property index capturing this'))()");
971+
var _eval = 'eval';
972+
this[_eval]("(() => assert.areEqual('global', this.o, 'Lambda in indirect eval called from a property index capturing this'))()");
973+
_eval = eval;
974+
_eval("(() => assert.areEqual('global', this.o, 'Lambda in indirect eval capturing this'))()");
975+
`);
976+
}
964977
}
965978
]
966979

0 commit comments

Comments
 (0)