tools: Use `throw new Error()` consistently
authorRich Trott <rtrott@gmail.com>
Sun, 8 Nov 2015 17:51:29 +0000 (09:51 -0800)
committerMyles Borins <mborins@us.ibm.com>
Tue, 19 Jan 2016 19:52:13 +0000 (11:52 -0800)
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 <evanlucas@me.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
test/addons/make-callback/test.js
test/parallel/test-assert.js
test/parallel/test-http-mutable-headers.js
test/pummel/test-regress-GH-814.js
test/pummel/test-regress-GH-814_2.js

index 80ea0db..f3c9877 100644 (file)
@@ -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));
index db36abc..7e40ecb 100644 (file)
@@ -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');
index 2a60117..af8fd6d 100644 (file)
@@ -110,7 +110,7 @@ function nextTest() {
         break;
 
       default:
-        throw Error('?');
+        throw new Error('?');
     }
 
     response.setEncoding('utf8');
index 4ed4b31..820903d 100644 (file)
@@ -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) {
index 9de1a2c..d7c6d94 100644 (file)
@@ -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');
   }
 }