Skip to content

Commit

Permalink
console: make console consistent with the standard - overridable
Browse files Browse the repository at this point in the history
make console overridable by custom console( without delete )
add test suite from w3c/web-platform-tests( console-is-a-namespace )
few test cases 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 1fe0741 commit ea237b2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,15 @@
NativeModule.require('console') :
installInspectorConsole(originalConsole);
}
// Object.defineProperty(global, 'console', {
// configurable: true,
// writable: true,
// value: console
// });
return console;
},
set: function(customConsole) {
console = customConsole;
}
});
setupInspectorCommandLineAPI();
Expand Down
44 changes: 44 additions & 0 deletions test/parallel/test-console-is-a-namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';
// https://heycam.github.io/webidl/#es-namespaces
// https://console.spec.whatwg.org/#console-namespace
// https://github.com/w3c/web-platform-tests/blob/master/console/console-is-a-namespace.any.js

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');

test(() => {
assert_true(global.hasOwnProperty('console'));
}, 'console exists on the global object');

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.configurable, true, 'must be configurable');
// assert_equals(propDesc.value, console, 'must have the right value');
}, 'console has the right property descriptors');

test(() => {
assert_false('Console' in global);
}, 'Console (uppercase, as if it were an interface) must not exist');

test(() => {
const prototype1 = Object.getPrototypeOf(console);
const prototype2 = Object.getPrototypeOf(prototype1);
// console.log('console',Object.getOwnPropertyNames(console));
// console.log('prototype1',Object.getOwnPropertyNames(prototype1));
// assert_equals(Object.getOwnPropertyNames(prototype1).length, 0,
// 'The [[Prototype]] must have no properties');
assert_equals(prototype2, Object.prototype,
'The [[Prototype]]\'s [[Prototype]] must be Object Prototype');

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

0 comments on commit ea237b2

Please sign in to comment.