From 2e8c4c8b17d77069a3341a4ebce89e2a160068b0 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 20 Apr 2017 13:49:56 -0400 Subject: [PATCH] src: expose V8's IsNativeError() in util bindings Refs: https://github.com/nodejs/node/pull/12400 PR-URL: https://github.com/nodejs/node/pull/12546 Reviewed-By: Anna Henningsen Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell --- src/node_util.cc | 1 + test/parallel/test-util.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/node_util.cc b/src/node_util.cc index 8279a787d7d1ac..8b089ad4f3f750 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -24,6 +24,7 @@ using v8::Value; V(isDate, IsDate) \ V(isMap, IsMap) \ V(isMapIterator, IsMapIterator) \ + V(isNativeError, IsNativeError) \ V(isPromise, IsPromise) \ V(isRegExp, IsRegExp) \ V(isSet, IsSet) \ diff --git a/test/parallel/test-util.js b/test/parallel/test-util.js index 3b7e78ea1e464e..162191e9196e7c 100644 --- a/test/parallel/test-util.js +++ b/test/parallel/test-util.js @@ -2,6 +2,7 @@ const common = require('../common'); const assert = require('assert'); const util = require('util'); +const binding = process.binding('util'); const context = require('vm').runInNewContext; // isArray @@ -132,3 +133,20 @@ util.print('test'); util.puts('test'); util.debug('test'); util.error('test'); + +{ + // binding.isNativeError() + assert.strictEqual(binding.isNativeError(new Error()), true); + assert.strictEqual(binding.isNativeError(new TypeError()), true); + assert.strictEqual(binding.isNativeError(new SyntaxError()), true); + assert.strictEqual(binding.isNativeError(new (context('Error'))()), true); + assert.strictEqual(binding.isNativeError(new (context('TypeError'))()), true); + assert.strictEqual(binding.isNativeError(new (context('SyntaxError'))()), + true); + assert.strictEqual(binding.isNativeError({}), false); + assert.strictEqual(binding.isNativeError({ name: 'Error', message: '' }), + false); + assert.strictEqual(binding.isNativeError([]), false); + assert.strictEqual(binding.isNativeError(Object.create(Error.prototype)), + false); +}