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

Commit

Permalink
[Merge chakra-core/ChakraCore@d234b08fd9] [MERGE #3904 @boingoing] St…
Browse files Browse the repository at this point in the history
…rict mode global lambda functions should use LdThis instead of StrictLdThis

Merge pull request #3904 from boingoing:LdThisForStrictLambda
  • Loading branch information
chakrabot committed Oct 10, 2017
1 parent 2ae996d commit adbea0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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 deps/chakrashim/core/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 adbea0f

Please sign in to comment.