From 186ffc2fb125cbe7bb4912d0dd208df50429ff43 Mon Sep 17 00:00:00 2001 From: Bradley Meck Date: Thu, 24 Mar 2016 10:17:38 -0500 Subject: [PATCH] lib: remove Object from global's prototype Removes some strange behavior from having Object in the global object's prototype chain. No longer introducing global variables coming from `Object.prototype`. --- lib/internal/bootstrap_node.js | 7 ++++--- src/node.cc | 6 ++++++ test/common.js | 1 - 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 0a688a1b0f915a..f4232c9d8abcea 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -208,7 +208,6 @@ function setupGlobalVariables() { global.process = process; - global.global = global; const util = NativeModule.require('util'); // Deprecate GLOBAL and root @@ -246,8 +245,10 @@ } function setupGlobalConsole() { - global.__defineGetter__('console', function() { - return NativeModule.require('console'); + Object.defineProperty(global, 'console', { + get() { + return NativeModule.require('console'); + } }); } diff --git a/src/node.cc b/src/node.cc index f9a0519e43af13..0b766cfd5a6564 100644 --- a/src/node.cc +++ b/src/node.cc @@ -4195,6 +4195,12 @@ static void StartNodeInstance(void* arg) { Isolate::Scope isolate_scope(isolate); HandleScope handle_scope(isolate); Local context = Context::New(isolate); + // note that Global() returns the proxy, which has a prototype + // that is the actual global + Local global_obj = + context->Global()->GetPrototype().As(); + global_obj->SetPrototype(context, Null(isolate)); + Environment* env = CreateEnvironment(isolate, context, instance_data); array_buffer_allocator->set_env(env); Context::Scope context_scope(context); diff --git a/test/common.js b/test/common.js index 28e7972e223602..36d1cb407d5c9f 100644 --- a/test/common.js +++ b/test/common.js @@ -260,7 +260,6 @@ var knownGlobals = [setTimeout, clearInterval, clearImmediate, console, - constructor, // Enumerable in V8 3.21. Buffer, process, global];