Skip to content

Commit

Permalink
src: expose V8's IsNativeError() in util bindings
Browse files Browse the repository at this point in the history
Refs: #12400
PR-URL: #12546
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
cjihrig authored and evanlucas committed May 2, 2017
1 parent 51eafe8 commit 744ed94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

0 comments on commit 744ed94

Please sign in to comment.