Skip to content

Commit

Permalink
[MERGE #3904 @boingoing] Strict mode global lambda functions should u…
Browse files Browse the repository at this point in the history
…se LdThis instead of StrictLdThis

Merge pull request #3904 from boingoing:LdThisForStrictLambda
  • Loading branch information
boingoing committed Oct 9, 2017
2 parents 13e0e02 + d0b6949 commit d234b08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Runtime/ByteCode/ByteCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,7 @@ void ByteCodeGenerator::GetEnclosingNonLambdaScope(FuncInfo *funcInfo, Scope * &

void ByteCodeGenerator::EmitThis(FuncInfo *funcInfo, Js::RegSlot fromRegister)
{
if (funcInfo->byteCodeFunction->GetIsStrictMode() && !funcInfo->IsGlobalFunction())
if (funcInfo->byteCodeFunction->GetIsStrictMode() && !funcInfo->IsGlobalFunction() && !funcInfo->IsLambda())
{
m_writer.Reg2(Js::OpCode::StrictLdThis, funcInfo->GetThisSymbol()->GetLocation(), fromRegister);
}
Expand Down
18 changes: 17 additions & 1 deletion test/Basics/SpecialSymbolCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,23 @@ var tests = [
}
foo('arguments');
}
}
},
{
name: "Global 'this' binding captured by strict-mode arrow",
body: function() {
WScript.LoadScript(`"use strict";
assert.areEqual(this, (() => this)(), "Lambda should load the global 'this' value itself via LdThis (not StrictLdThis)");
`);

WScript.LoadScript(`
assert.areEqual(this, (() => { "use strict"; return this; })(), "Lambda which has a 'use strict' clause inside");
`);

WScript.LoadScript(`"use strict";
assert.areEqual('object', typeof (() => this)(), "Verify lambda can load global 'this' value even if the global body itself does not have a 'this' binding");
`);
}
},
]

testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 comments on commit d234b08

Please sign in to comment.