Skip to content

Commit

Permalink
Function as target object allowed
Browse files Browse the repository at this point in the history
PR-URL: #3
  • Loading branch information
piotrkobzda authored and addaleax committed Jan 2, 2018
1 parent 8a0984c commit c5450d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/weakref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace {
class ObjectInfo : public ObjectWrap<ObjectInfo> {
public:
ObjectInfo(const CallbackInfo& args) : ObjectWrap(args) {
if (!args[0].IsObject())
if (!args[0].IsObject() && !args[0].IsFunction())
throw Error::New(Env(), "target should be object");
if (!args[1].IsFunction())
throw Error::New(Env(), "callback should be function");
Expand Down
19 changes: 19 additions & 0 deletions test/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@ describe('create()', function() {
null,
undefined,
'foo',
Symbol(),
].forEach((val) => {
assert.throws(function() {
weak.create(val);
});
});
});

it('should accept "object" values', function() {
[
{},
function() {},
() => {},
[],
Buffer(''),
new ArrayBuffer(10),
new Int32Array(new ArrayBuffer(12)),
Promise.resolve(),
new WeakMap(),
].forEach((val) => {
assert.doesNotThrow(() => {
assert.ok(weak.create(val));
}, Error, String(val));
});
});
});

0 comments on commit c5450d7

Please sign in to comment.