diff options
author | Anto Aravinth <anto.aravinth.cse@gmail.com> | 2019-01-09 18:49:14 +0530 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-01-10 03:24:31 +0100 |
commit | 81b25eac21c15aa8fffda92f1501b9ffd593df5e (patch) | |
tree | 4a31222dd09f983193e3b515f2463b74a45abf83 /test | |
parent | baa4b9b4255922f63ea2b0e3ac92005ae273e3dc (diff) | |
download | android-node-v8-81b25eac21c15aa8fffda92f1501b9ffd593df5e.tar.gz android-node-v8-81b25eac21c15aa8fffda92f1501b9ffd593df5e.tar.bz2 android-node-v8-81b25eac21c15aa8fffda92f1501b9ffd593df5e.zip |
util: add null prototype support for date
PR-URL: https://github.com/nodejs/node/pull/25144
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-assert-deep.js | 6 | ||||
-rw-r--r-- | test/parallel/test-util-inspect.js | 48 |
2 files changed, 50 insertions, 4 deletions
diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index b16b0f3ffc..f495e51ef6 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -117,8 +117,8 @@ assert.throws( { code: 'ERR_ASSERTION', message: `${defaultMsgStartFull}\n\n` + - '+ 2016-01-01T00:00:00.000Z\n- 2016-01-01T00:00:00.000Z {\n' + - "- '0': '1'\n- }" + '+ 2016-01-01T00:00:00.000Z\n- MyDate 2016-01-01T00:00:00.000Z' + + " {\n- '0': '1'\n- }" } ); assert.throws( @@ -126,7 +126,7 @@ assert.throws( { code: 'ERR_ASSERTION', message: `${defaultMsgStartFull}\n\n` + - '+ 2016-01-01T00:00:00.000Z {\n' + + '+ MyDate 2016-01-01T00:00:00.000Z {\n' + "+ '0': '1'\n+ }\n- 2016-01-01T00:00:00.000Z" } ); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index e001273409..bd24efeecc 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1663,7 +1663,9 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); 'byteOffset: undefined,\n buffer: undefined }'], [new SharedArrayBuffer(2), '[SharedArrayBuffer: null prototype] ' + '{ [Uint8Contents]: <00 00>, byteLength: undefined }'], - [/foobar/, '[RegExp: null prototype] /foobar/'] + [/foobar/, '[RegExp: null prototype] /foobar/'], + [new Date('Sun, 14 Feb 2010 11:48:40 GMT'), + '[Date: null prototype] 2010-02-14T11:48:40.000Z'] ].forEach(([value, expected]) => { assert.strictEqual( util.inspect(Object.setPrototypeOf(value, null)), @@ -1707,6 +1709,50 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); assert(/\[Symbol\(foo\)]: 'yeah'/.test(res), res); }); +// Date null prototype checks +{ + class CustomDate extends Date { + } + + const date = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT'); + assert.strictEqual(util.inspect(date), 'CustomDate 2010-02-14T11:48:40.000Z'); + + // add properties + date.foo = 'bar'; + assert.strictEqual(util.inspect(date), + '{ CustomDate 2010-02-14T11:48:40.000Z foo: \'bar\' }'); + + // check for null prototype + Object.setPrototypeOf(date, null); + assert.strictEqual(util.inspect(date), + '{ [Date: null prototype] 2010-02-14T11:48:40.000Z' + + ' foo: \'bar\' }'); + + const anotherDate = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT'); + Object.setPrototypeOf(anotherDate, null); + assert.strictEqual(util.inspect(anotherDate), + '[Date: null prototype] 2010-02-14T11:48:40.000Z'); +} + +// Check for invalid dates and null prototype +{ + class CustomDate extends Date { + } + + const date = new CustomDate('invalid_date'); + assert.strictEqual(util.inspect(date), 'CustomDate Invalid Date'); + + // add properties + date.foo = 'bar'; + assert.strictEqual(util.inspect(date), + '{ CustomDate Invalid Date foo: \'bar\' }'); + + // check for null prototype + Object.setPrototypeOf(date, null); + assert.strictEqual(util.inspect(date), + '{ [Date: null prototype] Invalid Date foo: \'bar\' }'); +} + assert.strictEqual(inspect(1n), '1n'); assert.strictEqual(inspect(Object(-1n)), '[BigInt: -1n]'); assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]'); |