Skip to content

Commit 5d83d3e

Browse files
committed
[MERGE #5885 @rhuanjl] Implement stage 3 proposal globalThis
Merge pull request #5885 from rhuanjl:globalThis This PR implements the stage 3 proposal globalThis. 1. Actual implementation is 2 lines of code 2. I've added a default enabled flag so it can be flagged off if ever necessary 3. I've added a few tests which I think should be sufficient 4. The large size of the diff is only due to it needing a byte code regen cc: @ljharb @pleath closes: #1658
2 parents 5f2962c + 22940fd commit 5d83d3e

16 files changed

+3976
-3914
lines changed

bin/ch/DbgController.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var controllerObj = (function () {
6262
// Discard all known globals to reduce baseline noise.
6363
[
6464
"#__proto__",
65+
"globalThis",
6566
"Array",
6667
"ArrayBuffer",
6768
"Atomics",

lib/Common/ConfigFlagsList.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,10 @@ PHASE(All)
655655
#define DEFAULT_CONFIG_ES6UnicodeVerbose (true)
656656
#define DEFAULT_CONFIG_ES6Unscopables (true)
657657
#define DEFAULT_CONFIG_ES6RegExSticky (true)
658-
#define DEFAULT_CONFIG_ES2018RegExDotAll (true)
659-
#define DEFAULT_CONFIG_ESBigInt (false)
658+
#define DEFAULT_CONFIG_ES2018RegExDotAll (true)
659+
#define DEFAULT_CONFIG_ESBigInt (false)
660660
#define DEFAULT_CONFIG_ESSymbolDescription (true)
661+
#define DEFAULT_CONFIG_ESGlobalThis (true)
661662
#ifdef COMPILE_DISABLE_ES6RegExPrototypeProperties
662663
// If ES6RegExPrototypeProperties needs to be disabled by compile flag, DEFAULT_CONFIG_ES6RegExPrototypeProperties should be false
663664
#define DEFAULT_CONFIG_ES6RegExPrototypeProperties (false)
@@ -1195,6 +1196,9 @@ FLAGR(Boolean, ESBigInt, "Enable ESBigInt flag", DEFAULT_CONFIG_ESBigInt)
11951196
// ES Symbol.prototype.description flag
11961197
FLAGR(Boolean, ESSymbolDescription, "Enable Symbol.prototype.description", DEFAULT_CONFIG_ESSymbolDescription)
11971198

1199+
//ES globalThis flag
1200+
FLAGR(Boolean, ESGlobalThis, "Enable globalThis", DEFAULT_CONFIG_ESGlobalThis)
1201+
11981202
// This flag to be removed once JITing generator functions is stable
11991203
FLAGNR(Boolean, JitES6Generators , "Enable JITing of ES6 generators", false)
12001204

lib/Runtime/Base/JnDirectFields.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ ENTRY(defineProperties)
424424
ENTRY(toGMTString)
425425
ENTRY(compile)
426426
ENTRY(global)
427+
ENTRY(globalThis)
427428
ENTRY(lastIndex)
428429
ENTRY(multiline)
429430
ENTRY(dotAll)

lib/Runtime/Base/ThreadConfigFlagsList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ FLAG_RELEASE(IsESDynamicImportEnabled, ESDynamicImport)
5050
FLAG_RELEASE(IsESBigIntEnabled, ESBigInt)
5151
FLAG_RELEASE(IsESExportNsAsEnabled, ESExportNsAs)
5252
FLAG_RELEASE(IsESSymbolDescriptionEnabled, ESSymbolDescription)
53+
FLAG_RELEASE(IsESGlobalThisEnabled, ESGlobalThis)
5354
#ifdef ENABLE_PROJECTION
5455
FLAG(AreWinRTDelegatesInterfaces, WinRTDelegateInterfaces)
5556
FLAG_RELEASE(IsWinRTAdaptiveAppsEnabled, WinRTAdaptiveApps)

lib/Runtime/ByteCode/ByteCodeCacheReleaseFileVersion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
//-------------------------------------------------------------------------------------------------------
55
// NOTE: If there is a merge conflict the correct fix is to make a new GUID.
66

7-
// {E4B5202C-0ACB-48C6-A96F-8A4A29848ED0}
7+
// {11BA1CDD-86FC-4489-95EB-355A78E78EF8}
88
const GUID byteCodeCacheReleaseFileVersion =
9-
{ 0xE4B5202C, 0x0ACB, 0x48C6, { 0xA9, 0x6F, 0x8A, 0x4A, 0x29, 0x84, 0x8E, 0xD0 } };
9+
{ 0x11ba1cdd, 0x86fc, 0x4489, { 0x95, 0xeb, 0x35, 0x5a, 0x78, 0xe7, 0x8e, 0xf8 } };

lib/Runtime/Library/InJavascript/Intl.js.bc.32b.h

Lines changed: 872 additions & 872 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.bc.64b.h

Lines changed: 875 additions & 875 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.32b.h

Lines changed: 887 additions & 887 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.64b.h

Lines changed: 862 additions & 862 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,10 @@ namespace Js
12771277
randSeed0 = 0;
12781278
randSeed1 = 0;
12791279

1280+
if (globalObject->GetScriptContext()->GetConfig()->IsESGlobalThisEnabled())
1281+
{
1282+
AddMember(globalObject, PropertyIds::globalThis, globalObject, PropertyConfigurable | PropertyWritable);
1283+
}
12801284
AddMember(globalObject, PropertyIds::NaN, nan, PropertyNone);
12811285
AddMember(globalObject, PropertyIds::Infinity, positiveInfinite, PropertyNone);
12821286
AddMember(globalObject, PropertyIds::undefined, undefinedValue, PropertyNone);

0 commit comments

Comments
 (0)