Browse Source

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 <anna@addaleax.net>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v7.x
cjihrig 8 years ago
committed by Evan Lucas
parent
commit
744ed9477b
  1. 1
      src/node_util.cc
  2. 18
      test/parallel/test-util.js

1
src/node_util.cc

@ -24,6 +24,7 @@ using v8::Value;
V(isDate, IsDate) \ V(isDate, IsDate) \
V(isMap, IsMap) \ V(isMap, IsMap) \
V(isMapIterator, IsMapIterator) \ V(isMapIterator, IsMapIterator) \
V(isNativeError, IsNativeError) \
V(isPromise, IsPromise) \ V(isPromise, IsPromise) \
V(isRegExp, IsRegExp) \ V(isRegExp, IsRegExp) \
V(isSet, IsSet) \ V(isSet, IsSet) \

18
test/parallel/test-util.js

@ -2,6 +2,7 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const util = require('util'); const util = require('util');
const binding = process.binding('util');
const context = require('vm').runInNewContext; const context = require('vm').runInNewContext;
// isArray // isArray
@ -132,3 +133,20 @@ util.print('test');
util.puts('test'); util.puts('test');
util.debug('test'); util.debug('test');
util.error('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);
}

Loading…
Cancel
Save