diff options
author | Thomas <hakerh403@gmail.com> | 2019-02-10 12:39:23 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-02 00:07:53 +0100 |
commit | e9ed6b988f9b8a5a9db8deb4f06c759cf226a1a5 (patch) | |
tree | 15e919f561064361c1439a06e8425ff85aa0502a /test | |
parent | fc4c0de92fcbd25236de6eac35afab620ffc1e27 (diff) | |
download | android-node-v8-e9ed6b988f9b8a5a9db8deb4f06c759cf226a1a5.tar.gz android-node-v8-e9ed6b988f9b8a5a9db8deb4f06c759cf226a1a5.tar.bz2 android-node-v8-e9ed6b988f9b8a5a9db8deb4f06c759cf226a1a5.zip |
console: prevent constructing console methods
Ref: https://github.com/nodejs/node/issues/25987
PR-URL: https://github.com/nodejs/node/pull/26096
Refs: https://github.com/nodejs/node/issues/25987
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-console-methods.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/parallel/test-console-methods.js b/test/parallel/test-console-methods.js new file mode 100644 index 0000000000..00dc144761 --- /dev/null +++ b/test/parallel/test-console-methods.js @@ -0,0 +1,40 @@ +'use strict'; +require('../common'); + +// This test ensures that console methods +// cannot be invoked as constructors + +const assert = require('assert'); + +const { Console } = console; +const newInstance = new Console(process.stdout); +const err = TypeError; + +const methods = [ + 'log', + 'warn', + 'dir', + 'time', + 'timeEnd', + 'timeLog', + 'trace', + 'assert', + 'clear', + 'count', + 'countReset', + 'group', + 'groupEnd', + 'table', + 'debug', + 'info', + 'dirxml', + 'error', + 'groupCollapsed', +]; + +for (const method of methods) { + assert.throws(() => new console[method](), err); + assert.throws(() => new newInstance[method](), err); + assert.throws(() => Reflect.construct({}, [], console[method]), err); + assert.throws(() => Reflect.construct({}, [], newInstance[method]), err); +} |