Skip to content

Commit b3899e9

Browse files
committed
fixes #5513 add toStringTag for global object
1 parent 361df65 commit b3899e9

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,8 @@ namespace Js
11411141
AddMember(globalObject, PropertyIds::NaN, nan, PropertyNone);
11421142
AddMember(globalObject, PropertyIds::Infinity, positiveInfinite, PropertyNone);
11431143
AddMember(globalObject, PropertyIds::undefined, undefinedValue, PropertyNone);
1144+
// Note: for global object, we need to set toStringTag to global like other engines (v8)
1145+
AddMember(globalObject, PropertyIds::_symbolToStringTag, scriptContext->GetPropertyString(PropertyIds::global) , PropertyNone);
11441146

11451147
// Note: Any global function added/removed/changed here should also be updated in JavascriptLibrary::ProfilerRegisterBuiltinFunctions
11461148
// so that the new functions show up in the profiler too.

test/Object/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,10 @@
486486
<compile-flags>-args summary -endargs -ES2018ObjectRestSpread -off:simplejit</compile-flags>
487487
</default>
488488
</test>
489+
<test>
490+
<default>
491+
<files>toStringWithGlobalObject.js</files>
492+
<baseline>toStringWithGlobalObject.baseline</baseline>
493+
</default>
494+
</test>
489495
</regress-exe>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[object global]
2+
global
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
let global = new Function('return this;')();
7+
console.log(global.toString());
8+
console.log(global[Symbol.toStringTag]);

0 commit comments

Comments
 (0)