From 7424c98dc759a905d1a025cce028c0a37d425e50 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 --- 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 8db79aa33fb32a..c8adb39e6b7b26 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -188,6 +188,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]');