Skip to content

Commit

Permalink
console: make console consistent - writable, not enumerable
Browse files Browse the repository at this point in the history
according to the standard
property descriptor of console
should be writable, have value and be not enumerable
adjust test suite imported from w3c/web-platform-tests( console-is-a-namespace )
one test case still is commented out from the test suite
to make nodejs console even more consistent further changes needed
which will come in the next commit
which could be more breaking than this one

Fixes: nodejs#11805
  • Loading branch information
Wandalen authored and Trott committed Aug 15, 2017
1 parent ea237b2 commit d98c130
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 7 additions & 6 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,19 @@
let console;
Object.defineProperty(global, 'console', {
configurable: true,
enumerable: true,
enumerable: false,
get: function() {
if (!console) {
console = (originalConsole === undefined) ?
NativeModule.require('console') :
installInspectorConsole(originalConsole);
}
// Object.defineProperty(global, 'console', {
// configurable: true,
// writable: true,
// value: console
// });
Object.defineProperty(global, 'console', {
configurable: true,
writable: true,
enumerable: false,
value: console
});
return console;
},
set: function(customConsole) {
Expand Down
14 changes: 7 additions & 7 deletions test/parallel/test-console-is-a-namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ const common = require('../common');
const assert = require('assert');
const { test, assert_equals, assert_true, assert_false } = common.WPT;

assert.doesNotThrow(() => {
global.console = global.console;
});

test(() => {
assert_true(global.hasOwnProperty('console'));
}, 'console exists on the global object');
Expand All @@ -21,10 +17,10 @@ test(() => {

test(() => {
const propDesc = Object.getOwnPropertyDescriptor(global, 'console');
// assert_equals(propDesc.writable, true, 'must be writable');
// assert_equals(propDesc.enumerable, false, 'must not be enumerable');
assert_equals(propDesc.writable, true, 'must be writable');
assert_equals(propDesc.enumerable, false, 'must not be enumerable');
assert_equals(propDesc.configurable, true, 'must be configurable');
// assert_equals(propDesc.value, console, 'must have the right value');
assert_equals(propDesc.value, console, 'must have the right value');
}, 'console has the right property descriptors');

test(() => {
Expand All @@ -42,3 +38,7 @@ test(() => {
'The [[Prototype]]\'s [[Prototype]] must be Object Prototype');

}, 'The prototype chain must be correct');

assert.doesNotThrow(() => {
global.console = global.console;
});

0 comments on commit d98c130

Please sign in to comment.