Skip to content

Commit

Permalink
src: fix util abort
Browse files Browse the repository at this point in the history
This makes sure util.isRegExp and util.isDate will not abort in case
more than one argument is passed to the function.

PR-URL: #19223
Reviewed-By: Myles Borins <myles.borins@gmail.com>
  • Loading branch information
BridgeAR authored and MylesBorins committed Mar 20, 2018
1 parent 1ba1861 commit 49391a7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ using v8::Value;

#define V(_, ucname) \
static void ucname(const FunctionCallbackInfo<Value>& args) { \
CHECK_EQ(1, args.Length()); \
args.GetReturnValue().Set(args[0]->ucname()); \
}

VALUE_METHOD_MAP(V)
#undef V

static void IsAnyArrayBuffer(const FunctionCallbackInfo<Value>& args) {
CHECK_EQ(1, args.Length());
args.GetReturnValue().Set(
args[0]->IsArrayBuffer() || args[0]->IsSharedArrayBuffer());
}
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ assert.strictEqual(false, util.isArray(Object.create(Array.prototype)));

// isRegExp
assert.strictEqual(true, util.isRegExp(/regexp/));
assert.strictEqual(true, util.isRegExp(RegExp()));
assert.strictEqual(true, util.isRegExp(RegExp(), 'foo'));
assert.strictEqual(true, util.isRegExp(new RegExp()));
assert.strictEqual(true, util.isRegExp(context('RegExp')()));
assert.strictEqual(false, util.isRegExp());
assert.strictEqual(false, util.isRegExp({}));
assert.strictEqual(false, util.isRegExp([]));
assert.strictEqual(false, util.isRegExp(new Date()));
assert.strictEqual(false, util.isRegExp(Object.create(RegExp.prototype)));

// isDate
assert.strictEqual(true, util.isDate(new Date()));
assert.strictEqual(true, util.isDate(new Date(0)));
assert.strictEqual(true, util.isDate(new Date(0), 'foo'));
assert.strictEqual(true, util.isDate(new (context('Date'))()));
assert.strictEqual(false, util.isDate(Date()));
assert.strictEqual(false, util.isDate({}));
Expand Down

0 comments on commit 49391a7

Please sign in to comment.