diff --git a/lib/Runtime/ByteCode/ByteCodeEmitter.cpp b/lib/Runtime/ByteCode/ByteCodeEmitter.cpp index f00764454a1..482f4503193 100644 --- a/lib/Runtime/ByteCode/ByteCodeEmitter.cpp +++ b/lib/Runtime/ByteCode/ByteCodeEmitter.cpp @@ -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); } diff --git a/test/Basics/SpecialSymbolCapture.js b/test/Basics/SpecialSymbolCapture.js index 14b2ad39455..7cf1c36b72c 100644 --- a/test/Basics/SpecialSymbolCapture.js +++ b/test/Basics/SpecialSymbolCapture.js @@ -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" });