Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working for primitives? #82

Open
martijnthe opened this issue Nov 7, 2017 · 3 comments
Open

Not working for primitives? #82

martijnthe opened this issue Nov 7, 2017 · 3 comments

Comments

@martijnthe
Copy link

The doc says:

The Object can be a regular Object, an Array, a Function, a RegExp, or any of the primitive types or constructor function created with new.

The "or any of the primitive types" part suggests that plain string, number, boolean, etc. should also work, but this doesn't seem to be the case to me. Can you clarify?

cc @jiangzidong

@rpaterson
Copy link

I am similarly disappointed. Here's the error:

$ node -e "require('weak')('a string')"
/home/rpaterson/programming/signpost/essentials/node_modules/weak/lib/weak.js:49
  var weakref = bindings._create(obj, new Emitter());
                         ^

TypeError: Object expected
    at TypeError (native)
    at create (/home/rpaterson/programming/signpost/essentials/node_modules/weak/lib/weak.js:49:26)
    at [eval]:1:16
    at ContextifyScript.Script.runInThisContext (vm.js:25:33)
    at Object.exports.runInThisContext (vm.js:77:17)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:570:32)
    at Immediate.<anonymous> (bootstrap_node.js:357:29)
    at runCallback (timers.js:637:20)
    at tryOnImmediate (timers.js:610:5)

@rpaterson
Copy link

rpaterson commented Apr 25, 2018

Javascript has built-in WeakMap and WeakSet now, but they only support Objects as well. I was hoping that I could build a weak Map/Set impl for Strings based on this module.

@rpaterson
Copy link

Here's the line that throws the error:

if (!info[0]->IsObject()) return Nan::ThrowTypeError("Object expected");

Looks like it dates back to the original creation of this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants