From ea237b22fd7aeeb29eaa2398df623c5c70b82fc5 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 03:58:01 +0300 Subject: [PATCH 01/21] console: make console consistent with the standard - overridable 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: https://github.com/nodejs/node/issues/11805 --- lib/internal/bootstrap_node.js | 8 ++++ test/parallel/test-console-is-a-namespace.js | 44 ++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 test/parallel/test-console-is-a-namespace.js diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index a576eeb5e579f6..0406ed67fc69e5 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -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(); diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js new file mode 100644 index 00000000000000..25749980253559 --- /dev/null +++ b/test/parallel/test-console-is-a-namespace.js @@ -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'); From d98c130f72131ef51e380379e58645f467a13aa8 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 04:36:45 +0300 Subject: [PATCH 02/21] console: make console consistent - writable, not enumerable 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: https://github.com/nodejs/node/issues/11805 --- lib/internal/bootstrap_node.js | 13 +++++++------ test/parallel/test-console-is-a-namespace.js | 14 +++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 0406ed67fc69e5..2a01daa0a61990 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -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) { diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index 25749980253559..036425ee8143ec 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -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'); @@ -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(() => { @@ -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; +}); From 4a0669d877218edc24b717bf87eea0b450b73f43 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 05:18:41 +0300 Subject: [PATCH 03/21] console: add WPT footer as requested --- test/parallel/test-console-is-a-namespace.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index 036425ee8143ec..414dd687c07b89 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -38,7 +38,9 @@ test(() => { 'The [[Prototype]]\'s [[Prototype]] must be Object Prototype'); }, 'The prototype chain must be correct'); +/* eslint-enable */ +// Tests below are not from WPT. assert.doesNotThrow(() => { global.console = global.console; }); From fad67258002497ede54e95e2bada8e6a27411fec Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 05:22:01 +0300 Subject: [PATCH 04/21] console: remove extra comments as requested --- test/parallel/test-console-is-a-namespace.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index 414dd687c07b89..9c7b8c2ced2e03 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -30,8 +30,6 @@ test(() => { 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, From 6e86bca358928f9d9b5d2872eb8b285c242b954d Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 05:43:39 +0300 Subject: [PATCH 05/21] console : add WPT header as requested --- test/parallel/test-console-is-a-namespace.js | 23 +++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index 9c7b8c2ced2e03..efa24806aae1d3 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -1,4 +1,5 @@ '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 @@ -7,6 +8,22 @@ const common = require('../common'); const assert = require('assert'); const { test, assert_equals, assert_true, assert_false } = common.WPT; +assert.doesNotThrow(() => { + global.console = global.console; +}); + +// Tests above are not from WPT. + +/* eslint-disable */ +/* WPT Refs: + https://github.com/w3c/web-platform-tests/blob/master/console/console-is-a-namespace.any.js + License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html +*/ + +assert.doesNotThrow(() => { + global.console = global.console; +}); + test(() => { assert_true(global.hasOwnProperty('console')); }, 'console exists on the global object'); @@ -36,9 +53,5 @@ test(() => { 'The [[Prototype]]\'s [[Prototype]] must be Object Prototype'); }, 'The prototype chain must be correct'); -/* eslint-enable */ -// Tests below are not from WPT. -assert.doesNotThrow(() => { - global.console = global.console; -}); +/* eslint-enable */ From 79dc6291dc6f5fc69268a20de912c6d19ae96364 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 06:02:37 +0300 Subject: [PATCH 06/21] console: take care of console set undefined case If global.console write undefined would come earlier than global.console read then lazy read in get would happen, despite write was done. This commit fix the problem. Fixes: https://github.com/nodejs/node/issues/11805 --- lib/internal/bootstrap_node.js | 9 +++++++- .../parallel/test-console-assing-undefined.js | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-console-assing-undefined.js diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 2a01daa0a61990..5ee664396defce 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -272,6 +272,7 @@ configurable: true, enumerable: false, get: function() { + NativeModule.require('console').log( 'console get' ); if (!console) { console = (originalConsole === undefined) ? NativeModule.require('console') : @@ -286,7 +287,13 @@ return console; }, set: function(customConsole) { - console = customConsole; + NativeModule.require('console').log( 'console set' ); + Object.defineProperty(global, 'console', { + configurable: true, + writable: true, + enumerable: false, + value: console + }); } }); setupInspectorCommandLineAPI(); diff --git a/test/parallel/test-console-assing-undefined.js b/test/parallel/test-console-assing-undefined.js new file mode 100644 index 00000000000000..6a67dc57e8b204 --- /dev/null +++ b/test/parallel/test-console-assing-undefined.js @@ -0,0 +1,21 @@ +'use strict'; + +// Should be above require, because code in require read console +// what we are trying to avoid +// set should be earlier than get + +global.console = undefined; + +// Initially, the `console` variable is `undefined`, since console will be +// lazily loaded in the getter. + +const common = require('../common'); +const assert = require('assert'); + +// global.console's getter is called +// Since the `console` cache variable is `undefined` and therefore false-y, +// the getter still calls NativeModule.require() and returns the object +// obtained from it, instead of returning `undefined` as expected. + +assert.strictEqual(global.console, undefined, 'first read'); +assert.strictEqual(global.console, undefined, 'second read'); From e10a6dd3423289a841c3a66aae811b3245c0aff7 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 06:09:06 +0300 Subject: [PATCH 07/21] console : remove diagnostic information output --- lib/internal/bootstrap_node.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 5ee664396defce..36950911e5397b 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -272,7 +272,6 @@ configurable: true, enumerable: false, get: function() { - NativeModule.require('console').log( 'console get' ); if (!console) { console = (originalConsole === undefined) ? NativeModule.require('console') : @@ -287,7 +286,6 @@ return console; }, set: function(customConsole) { - NativeModule.require('console').log( 'console set' ); Object.defineProperty(global, 'console', { configurable: true, writable: true, From 28c32a2e893c3904666c743911afd37054ce24f2 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 06:12:10 +0300 Subject: [PATCH 08/21] console : fix typo --- lib/internal/bootstrap_node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 36950911e5397b..ed5dbd2a28c29e 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -290,7 +290,7 @@ configurable: true, writable: true, enumerable: false, - value: console + value: customConsole }); } }); From 02768c03afee097a532cebc67bd8bb885cd09955 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 06:21:18 +0300 Subject: [PATCH 09/21] console : few more test cases --- test/parallel/test-console-assing-undefined.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-console-assing-undefined.js b/test/parallel/test-console-assing-undefined.js index 6a67dc57e8b204..faf291e3825197 100644 --- a/test/parallel/test-console-assing-undefined.js +++ b/test/parallel/test-console-assing-undefined.js @@ -9,7 +9,6 @@ global.console = undefined; // Initially, the `console` variable is `undefined`, since console will be // lazily loaded in the getter. -const common = require('../common'); const assert = require('assert'); // global.console's getter is called @@ -19,3 +18,9 @@ const assert = require('assert'); assert.strictEqual(global.console, undefined, 'first read'); assert.strictEqual(global.console, undefined, 'second read'); + +global.console = 1; +assert.strictEqual(global.console, 1, 'set true-like primitive'); + +global.console = 0; +assert.strictEqual(global.console, 0, 'set false-like primitive, again'); From 5f9d30fae33804d18cc4d81bf2cb6f2e7991c383 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 12:44:50 +0300 Subject: [PATCH 10/21] console : stadard remove redundandt test case --- test/parallel/test-console-is-a-namespace.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index efa24806aae1d3..bb518d01ab870f 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -20,10 +20,6 @@ assert.doesNotThrow(() => { License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html */ -assert.doesNotThrow(() => { - global.console = global.console; -}); - test(() => { assert_true(global.hasOwnProperty('console')); }, 'console exists on the global object'); From bb267181d6ef570399810145ab82fa2b4ade0809 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 13:11:07 +0300 Subject: [PATCH 11/21] console : reference specific commit instead of master in test suite --- test/parallel/test-console-is-a-namespace.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index bb518d01ab870f..2f7aae6041b74a 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -2,7 +2,7 @@ // 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 +// https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js const common = require('../common'); const assert = require('assert'); @@ -16,7 +16,7 @@ assert.doesNotThrow(() => { /* eslint-disable */ /* WPT Refs: - https://github.com/w3c/web-platform-tests/blob/master/console/console-is-a-namespace.any.js + https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html */ From 352d50422e0017ef48055a5f2d7ca9784591b517 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 19:59:32 +0300 Subject: [PATCH 12/21] console : fix jsling issue --- test/parallel/test-console-assing-undefined.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-console-assing-undefined.js b/test/parallel/test-console-assing-undefined.js index faf291e3825197..5f43c5db5192f8 100644 --- a/test/parallel/test-console-assing-undefined.js +++ b/test/parallel/test-console-assing-undefined.js @@ -10,6 +10,7 @@ global.console = undefined; // lazily loaded in the getter. const assert = require('assert'); +require('../common'); // global.console's getter is called // Since the `console` cache variable is `undefined` and therefore false-y, From 197ec075bff4c6a064cbc60ac0446705c769c06e Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 17 Apr 2017 20:20:25 +0300 Subject: [PATCH 13/21] console : reverse requires in test as requested --- test/parallel/test-console-assing-undefined.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-console-assing-undefined.js b/test/parallel/test-console-assing-undefined.js index 5f43c5db5192f8..83afcb70c36c70 100644 --- a/test/parallel/test-console-assing-undefined.js +++ b/test/parallel/test-console-assing-undefined.js @@ -9,8 +9,8 @@ global.console = undefined; // Initially, the `console` variable is `undefined`, since console will be // lazily loaded in the getter. -const assert = require('assert'); require('../common'); +const assert = require('assert'); // global.console's getter is called // Since the `console` cache variable is `undefined` and therefore false-y, From c653812301aa425137abd9ae7b3c1b69eb8131de Mon Sep 17 00:00:00 2001 From: wandalen Date: Sat, 22 Apr 2017 20:21:44 +0400 Subject: [PATCH 14/21] console : => shorthand --- lib/internal/bootstrap_node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index ed5dbd2a28c29e..80fe33e03e560a 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -271,7 +271,7 @@ Object.defineProperty(global, 'console', { configurable: true, enumerable: false, - get: function() { + get: () => { if (!console) { console = (originalConsole === undefined) ? NativeModule.require('console') : @@ -285,7 +285,7 @@ }); return console; }, - set: function(customConsole) { + set: (customConsole) => { Object.defineProperty(global, 'console', { configurable: true, writable: true, From 5a411bc849be8aa9abdae5a0008466b4ea7d34f0 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 1 May 2017 20:02:30 +0400 Subject: [PATCH 15/21] console : requested comment --- test/parallel/test-console-is-a-namespace.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index 2f7aae6041b74a..1ccbdbc3ac0cd3 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -13,6 +13,7 @@ assert.doesNotThrow(() => { }); // Tests above are not from WPT. +// avoid to modify it /* eslint-disable */ /* WPT Refs: From c9c572a69e43bba0fcfe58d6a21e71d8f3bb901d Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 1 May 2017 20:03:38 +0400 Subject: [PATCH 16/21] console : requested comment --- test/parallel/test-console-is-a-namespace.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index 1ccbdbc3ac0cd3..9d05093e2dce8d 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -13,7 +13,8 @@ assert.doesNotThrow(() => { }); // Tests above are not from WPT. -// avoid to modify it +// Tests below are from WPT. +// avoid to modify them /* eslint-disable */ /* WPT Refs: From b553b4921ed6c0fe2d1320d9db592593b92638ad Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 1 May 2017 21:09:30 +0400 Subject: [PATCH 17/21] console : requested comment --- test/parallel/test-console-is-a-namespace.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index 9d05093e2dce8d..a7f26aebc0411f 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -17,6 +17,7 @@ assert.doesNotThrow(() => { // avoid to modify them /* eslint-disable */ +/* The following tests are copied from. Do not modify. */ /* WPT Refs: https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html From b7d9771784952934847a18018b642266bcc8bc5f Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 1 May 2017 22:44:37 +0400 Subject: [PATCH 18/21] console : requested comment --- test/parallel/test-console-is-a-namespace.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index a7f26aebc0411f..4b57e15d8a9be9 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -14,7 +14,6 @@ assert.doesNotThrow(() => { // Tests above are not from WPT. // Tests below are from WPT. -// avoid to modify them /* eslint-disable */ /* The following tests are copied from. Do not modify. */ From 80237284405b680a3a3428ea79af748e8e18d081 Mon Sep 17 00:00:00 2001 From: wandalen Date: Mon, 1 May 2017 22:46:06 +0400 Subject: [PATCH 19/21] console : requested comment --- test/parallel/test-console-is-a-namespace.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index 4b57e15d8a9be9..2a3a5194d9762a 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -16,11 +16,12 @@ assert.doesNotThrow(() => { // Tests below are from WPT. /* eslint-disable */ -/* The following tests are copied from. Do not modify. */ +/* The following tests are copied from */ /* WPT Refs: https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html */ +/* Do not modify. */ test(() => { assert_true(global.hasOwnProperty('console')); From 490374fd75c01196b4c2654e904d8f0bf5535797 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 15 Aug 2017 17:07:06 -0700 Subject: [PATCH 20/21] squash: update test-console-is-a-namespace Update the test from the most recent WPT contents. Copyedit some existing comments. --- test/parallel/test-console-is-a-namespace.js | 51 +++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js index 2a3a5194d9762a..f4130008051ed8 100644 --- a/test/parallel/test-console-is-a-namespace.js +++ b/test/parallel/test-console-is-a-namespace.js @@ -1,19 +1,16 @@ 'use strict'; -// https://heycam.github.io/webidl/#es-namespaces -// https://console.spec.whatwg.org/#console-namespace -// https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js +require('../common'); -const common = require('../common'); const assert = require('assert'); -const { test, assert_equals, assert_true, assert_false } = common.WPT; +const { test, assert_equals, assert_true, assert_false } = + require('../common/wpt'); assert.doesNotThrow(() => { global.console = global.console; }); -// Tests above are not from WPT. -// Tests below are from WPT. +const self = global; /* eslint-disable */ /* The following tests are copied from */ @@ -21,36 +18,32 @@ assert.doesNotThrow(() => { https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html */ -/* Do not modify. */ -test(() => { - assert_true(global.hasOwnProperty('console')); -}, 'console exists on the global object'); +// https://heycam.github.io/webidl/#es-namespaces +// https://console.spec.whatwg.org/#console-namespace test(() => { - assert_true(global.hasOwnProperty('console')); -}, 'console exists on the global object'); + assert_true(self.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'); + const propDesc = Object.getOwnPropertyDescriptor(self, "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'); + assert_false("Console" in self); +}, "Console (uppercase, as if it were an interface) must not exist"); -test(() => { - const prototype1 = Object.getPrototypeOf(console); - const prototype2 = Object.getPrototypeOf(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'); +// test(() => { +// const prototype1 = Object.getPrototypeOf(console); +// const prototype2 = Object.getPrototypeOf(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 %ObjectPrototype%"); +// }, "The prototype chain must be correct"); /* eslint-enable */ From 2f43d8d85ef07f6f50cd98de4361f7bd3d8294d5 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 15 Aug 2017 21:25:55 -0700 Subject: [PATCH 21/21] squash: rename test --- ...nsole-assing-undefined.js => test-console-assign-undefined.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/parallel/{test-console-assing-undefined.js => test-console-assign-undefined.js} (100%) diff --git a/test/parallel/test-console-assing-undefined.js b/test/parallel/test-console-assign-undefined.js similarity index 100% rename from test/parallel/test-console-assing-undefined.js rename to test/parallel/test-console-assign-undefined.js