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); +}