Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Param scope and body scope should not be merged on this case. #6290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/Parser/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ struct Ident
return prevRef;
}

// Since the pidrefstack is not sorted in the function id order. We need to scan it and find out if
// any of the reference exist in the nested func.
bool HasReferencedInNestedFunction(Js::LocalFunctionId functionId)
{
PidRefStack *ref;
for (ref = m_pidRefStack; ref; ref = ref->prev)
{
if (ref->GetFuncScopeId() > functionId)
{
return true;
}
}
return false;
}

PidRefStack * FindOrAddPidRef(ArenaAllocator *alloc, int scopeId, Js::LocalFunctionId funcId)
{
// If the stack is empty, or we are pushing to the innermost scope already,
Expand Down
2 changes: 1 addition & 1 deletion lib/Parser/Parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5890,7 +5890,7 @@ void Parser::ParseFncDeclHelper(ParseNodeFnc * pnodeFnc, LPCOLESTR pNameHint, us
else if (pnodeFnc->HasNonSimpleParameterList() && pnodeFnc->IsBodyAndParamScopeMerged())
{
paramScope->ForEachSymbolUntil([this, paramScope, pnodeFnc](Symbol* sym) {
if (sym->GetPid()->GetTopRef()->GetFuncScopeId() > pnodeFnc->functionId)
if (sym->GetPid()->HasReferencedInNestedFunction(pnodeFnc->functionId))
{
// One of the symbol has non local reference. Mark the param scope as we can't merge it with body scope.
pnodeFnc->ResetBodyAndParamScopeMerged();
Expand Down
21 changes: 21 additions & 0 deletions test/Bugs/os_23446064.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

function test0() {
var obj1 = {};
var arrObj0 = obj1;
var func0 = function(a,
b = (Object.defineProperty(arrObj0, 'prop0', {set: function(_x) { a; } }), (1 - {1: a }) )
)
{
};

func0();
obj1.prop0 = {};
eval('');
};

test0();
print("Pass");
6 changes: 6 additions & 0 deletions test/Bugs/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@
<compile-flags>-maxinterpretcount:1 -bgjit- -oopjit- -loopinterpretcount:1 -maxsimplejitruncount:2</compile-flags>
</default>
</test>
<test>
<default>
<files>os_23446064.js</files>
<compile-flags>-force:deferparse</compile-flags>
</default>
</test>
<test>
<default>
<files>Bug19948792.js</files>
Expand Down