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

Implement stage 3 proposal globalThis #4

Open
wants to merge 3 commits 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
1 change: 1 addition & 0 deletions bin/ch/DbgController.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var controllerObj = (function () {
// Discard all known globals to reduce baseline noise.
[
"#__proto__",
"globalThis",
"Array",
"ArrayBuffer",
"Atomics",
Expand Down
8 changes: 6 additions & 2 deletions lib/Common/ConfigFlagsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,10 @@ PHASE(All)
#define DEFAULT_CONFIG_ES6UnicodeVerbose (true)
#define DEFAULT_CONFIG_ES6Unscopables (true)
#define DEFAULT_CONFIG_ES6RegExSticky (true)
#define DEFAULT_CONFIG_ES2018RegExDotAll (true)
#define DEFAULT_CONFIG_ESBigInt (false)
#define DEFAULT_CONFIG_ES2018RegExDotAll (true)
#define DEFAULT_CONFIG_ESBigInt (false)
#define DEFAULT_CONFIG_ESSymbolDescription (true)
#define DEFAULT_CONFIG_ESGlobalThis (true)
#ifdef COMPILE_DISABLE_ES6RegExPrototypeProperties
// If ES6RegExPrototypeProperties needs to be disabled by compile flag, DEFAULT_CONFIG_ES6RegExPrototypeProperties should be false
#define DEFAULT_CONFIG_ES6RegExPrototypeProperties (false)
Expand Down Expand Up @@ -1195,6 +1196,9 @@ FLAGR(Boolean, ESBigInt, "Enable ESBigInt flag", DEFAULT_CONFIG_ESBigInt)
// ES Symbol.prototype.description flag
FLAGR(Boolean, ESSymbolDescription, "Enable Symbol.prototype.description", DEFAULT_CONFIG_ESSymbolDescription)

//ES globalThis flag
FLAGR(Boolean, ESGlobalThis, "Enable globalThis", DEFAULT_CONFIG_ESGlobalThis)

// This flag to be removed once JITing generator functions is stable
FLAGNR(Boolean, JitES6Generators , "Enable JITing of ES6 generators", false)

Expand Down
1 change: 1 addition & 0 deletions lib/Runtime/Base/JnDirectFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ ENTRY(defineProperties)
ENTRY(toGMTString)
ENTRY(compile)
ENTRY(global)
ENTRY(globalThis)
ENTRY(lastIndex)
ENTRY(multiline)
ENTRY(dotAll)
Expand Down
1 change: 1 addition & 0 deletions lib/Runtime/Base/ThreadConfigFlagsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ FLAG_RELEASE(IsESDynamicImportEnabled, ESDynamicImport)
FLAG_RELEASE(IsESBigIntEnabled, ESBigInt)
FLAG_RELEASE(IsESExportNsAsEnabled, ESExportNsAs)
FLAG_RELEASE(IsESSymbolDescriptionEnabled, ESSymbolDescription)
FLAG_RELEASE(IsESGlobalThisEnabled, ESGlobalThis)
#ifdef ENABLE_PROJECTION
FLAG(AreWinRTDelegatesInterfaces, WinRTDelegateInterfaces)
FLAG_RELEASE(IsWinRTAdaptiveAppsEnabled, WinRTAdaptiveApps)
Expand Down
1,744 changes: 872 additions & 872 deletions lib/Runtime/Library/InJavascript/Intl.js.bc.32b.h

Large diffs are not rendered by default.

1,750 changes: 875 additions & 875 deletions lib/Runtime/Library/InJavascript/Intl.js.bc.64b.h

Large diffs are not rendered by default.

1,774 changes: 887 additions & 887 deletions lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.32b.h

Large diffs are not rendered by default.

1,724 changes: 862 additions & 862 deletions lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.64b.h

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions lib/Runtime/Library/JavascriptLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,10 @@ namespace Js
randSeed0 = 0;
randSeed1 = 0;

if (globalObject->GetScriptContext()->GetConfig()->IsESGlobalThisEnabled())
{
AddMember(globalObject, PropertyIds::globalThis, globalObject, PropertyConfigurable | PropertyWritable);
}
AddMember(globalObject, PropertyIds::NaN, nan, PropertyNone);
AddMember(globalObject, PropertyIds::Infinity, positiveInfinite, PropertyNone);
AddMember(globalObject, PropertyIds::undefined, undefinedValue, PropertyNone);
Expand Down
204 changes: 102 additions & 102 deletions lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js.bc.32b.h

Large diffs are not rendered by default.

204 changes: 102 additions & 102 deletions lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js.bc.64b.h

Large diffs are not rendered by default.

210 changes: 105 additions & 105 deletions lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js.nojit.bc.32b.h

Large diffs are not rendered by default.

210 changes: 105 additions & 105 deletions lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js.nojit.bc.64b.h

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions test/es7/globalThis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");

var global = this;
var bar = 5;

const tests = [
{
name: "globalThis is the global",
body() {
assert.areEqual(global, globalThis, "globalThis should be the global object");
}
},
{
name: "globalThis has global properties",
body() {
assert.areEqual(Array, globalThis.Array, "globalThis should have all global properties");
assert.areEqual(JSON, globalThis.JSON, "globalThis should have all global properties");
assert.areEqual(Object, globalThis.Object, "globalThis should have all global properties");
assert.areEqual(5, globalThis.bar, "globalThis should have all global properties");
assert.areEqual(global, globalThis.global, "globalThis should have all global properties");
assert.areEqual(global, globalThis.globalThis, "globalThis should have itself as a property");
}
},
{
name: "globalThis has correct attributes",
body() {
const descriptor = Object.getOwnPropertyDescriptor(globalThis, "globalThis");
assert.isFalse(descriptor.enumerable, "globalThis should not be enumerable");
assert.isTrue(descriptor.configurable, "globalThis should be configurable");
assert.isTrue(descriptor.writable, "globalThis should be writable");

assert.doesNotThrow(()=>{globalThis = 5;}, "Overwriting globalThis should not throw");
assert.areEqual(5, global.globalThis, "Overwriting globalThis should succeed");
assert.doesNotThrow(()=>{delete global.globalThis;}, "Deleting globalThis should not throw");
assert.areEqual(undefined, global.globalThis, "Deleting globalThis should succeed");
}
},
];

testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
6 changes: 6 additions & 0 deletions test/es7/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,10 @@
<compile-flags>-ESSymbolDescription -args summary -endargs</compile-flags>
</default>
</test>
<test>
<default>
<files>globalThis.js</files>
<compile-flags>-ESGlobalThis -args summary -endargs</compile-flags>
</default>
</test>
</regress-exe>