Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
});
});
});