From 327b746f089fcd99ad9b52e8b02a1d5ed3ff4a6b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 8 Nov 2015 09:51:29 -0800 Subject: [PATCH] tools: Use `throw new Error()` consistently In preparation for a lint rule that will enforce `throw new Error()` over `throw Error()`, fix the handful of instances in the code that use `throw Error()`. PR-URL: https://github.com/nodejs/node/pull/3714 Reviewed-By: Evan Lucas Reviewed-By: Colin Ihrig Reviewed-By: Jeremiah Senkpiel Reviewed-By: James M Snell --- test/addons/make-callback/test.js | 4 ++-- test/parallel/test-assert.js | 2 +- test/parallel/test-http-mutable-headers.js | 2 +- test/pummel/test-regress-GH-814.js | 2 +- test/pummel/test-regress-GH-814_2.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/addons/make-callback/test.js b/test/addons/make-callback/test.js index 80ea0db796ab30..f3c98770ef335a 100644 --- a/test/addons/make-callback/test.js +++ b/test/addons/make-callback/test.js @@ -40,7 +40,7 @@ assert.strictEqual(42, makeCallback(recv, 'two', 1337)); const target = vm.runInNewContext(` (function($Object) { if (Object === $Object) - throw Error('bad'); + throw new Error('bad'); return Object; }) `); @@ -55,7 +55,7 @@ const forward = vm.runInNewContext(` // Runs in outer context. const endpoint = function($Object) { if (Object === $Object) - throw Error('bad'); + throw new Error('bad'); return Object; }; assert.strictEqual(Object, makeCallback(process, forward, endpoint)); diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index db36abc184b024..7e40ecb78b80c4 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -465,6 +465,6 @@ testBlockTypeError(assert.doesNotThrow, undefined); // https://github.com/nodejs/node/issues/3275 assert.throws(() => { throw 'error'; }, err => err === 'error'); -assert.throws(() => { throw Error(); }, err => err instanceof Error); +assert.throws(() => { throw new Error(); }, err => err instanceof Error); console.log('All OK'); diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js index 2a60117328c580..af8fd6d7e8f938 100644 --- a/test/parallel/test-http-mutable-headers.js +++ b/test/parallel/test-http-mutable-headers.js @@ -110,7 +110,7 @@ function nextTest() { break; default: - throw Error('?'); + throw new Error('?'); } response.setEncoding('utf8'); diff --git a/test/pummel/test-regress-GH-814.js b/test/pummel/test-regress-GH-814.js index 4ed4b31ae28143..820903d68873e7 100644 --- a/test/pummel/test-regress-GH-814.js +++ b/test/pummel/test-regress-GH-814.js @@ -46,7 +46,7 @@ var timeToQuit = Date.now() + 8e3; //Test during no more than this seconds. } } else { - throw Error("Buffer GC'ed test -> FAIL"); + throw new Error("Buffer GC'ed test -> FAIL"); } if (Date.now() < timeToQuit) { diff --git a/test/pummel/test-regress-GH-814_2.js b/test/pummel/test-regress-GH-814_2.js index 9de1a2c3f3b86b..d7c6d947919d59 100644 --- a/test/pummel/test-regress-GH-814_2.js +++ b/test/pummel/test-regress-GH-814_2.js @@ -21,7 +21,7 @@ function tailCB(data) { console.error('[FAIL]\n DATA -> '); console.error(data); console.error('\n'); - throw Error('Buffers GC test -> FAIL'); + throw new Error('Buffers GC test -> FAIL'); } }