From e522bcd774c6a43d8facc1905b59e53a86f7ae0a 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 a615aa88fd3937..5f3de643d4c2f3 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -25,6 +25,7 @@ using v8::Value; V(isExternal, IsExternal) \ 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 fabf9dc22bd22d..c1dc4eadcb520a 100644 --- a/test/parallel/test-util.js +++ b/test/parallel/test-util.js @@ -23,6 +23,7 @@ const common = require('../common'); const assert = require('assert'); const util = require('util'); +const binding = process.binding('util'); const context = require('vm').runInNewContext; // isArray @@ -153,3 +154,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); +}