From 0fb21df6e692bef9f55b9bfa876f3c59dc590332 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 25 Oct 2016 22:13:24 +0200 Subject: [PATCH] lib: make `String(global) === '[object global]'` This inadvertently changed to `[object Object]` with the V8 upgrade in 8a24728...96933df. Use `Symbol.toStringTag` to undo this particular change. Fixes: https://github.com/nodejs/node/issues/9274 PR-URL: https://github.com/nodejs/node/pull/9279 Reviewed-By: Prince John Wesley Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Franziska Hinkelmann --- lib/internal/bootstrap_node.js | 6 ++++++ test/parallel/test-global.js | 2 ++ 2 files changed, 8 insertions(+) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 2b7e010214d258..4e1e2aa9018b5a 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -190,6 +190,12 @@ } function setupGlobalVariables() { + Object.defineProperty(global, Symbol.toStringTag, { + value: 'global', + writable: false, + enumerable: false, + configurable: true + }); global.process = process; const util = NativeModule.require('util'); diff --git a/test/parallel/test-global.js b/test/parallel/test-global.js index 1bf1bd7cd69303..270faf1b7768a6 100644 --- a/test/parallel/test-global.js +++ b/test/parallel/test-global.js @@ -21,3 +21,5 @@ const fooBar = module.fooBar; assert.strictEqual('foo', fooBar.foo, 'x -> global.x in sub level not working'); assert.strictEqual('bar', fooBar.bar, 'global.x -> x in sub level not working'); + +assert.strictEqual(Object.prototype.toString.call(global), '[object global]');