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

TypeError due to isObject unable to recognize Objects (node 6) #281

Open
hagemt opened this issue Jul 18, 2016 · 4 comments
Open

TypeError due to isObject unable to recognize Objects (node 6) #281

hagemt opened this issue Jul 18, 2016 · 4 comments

Comments

@hagemt
Copy link

hagemt commented Jul 18, 2016

Reproduction:

  1. nvm install 6 && npm install co && node
  2. Copy-paste the "Objects" example from Readme.md:
co(function* () {
  var res = yield {
    1: Promise.resolve(1),
    2: Promise.resolve(2),
  };
  console.log(res); // => { 1: 1, 2: 2 } 
})

Expected: { '1': 1, '2': 2 }

However, on the Console, I see:

TypeError: You may only yield a function, promise, generator, array, or object, but the following object was passed: "[object Object]"

Analysis

From my own investigation, it appears that in the context of isObject:

val.constructor == Object => false (consistently)

Testing the following expression in a REPL is fruitless. Both node v{4,6} produce:
({ '1': Promise { 1 }, '2': Promise { 2 } }).constructor == Object => true (consistently)

As such, I have made a PR that implements isObject using typeof, for the time being.

Please advise? Thanks.

hagemt pushed a commit to hagemt/co that referenced this issue Jul 18, 2016
fixed `'object' == typeof null`; caught by tests
@alsotang
Copy link

???

image

in my console, there is no any problems

@hagemt
Copy link
Author

hagemt commented Jul 19, 2016

Tested node versions:

  • v5.9.0: works as per your message
  • v6.0.0: same
  • v6.2.2: same
  • v6.3.0 (current): throws TypeError

Looks like a node regression sometime between 6.2.2 and 6.3.0.

@havenchyk
Copy link

Works fine for me, node 6.7.0

@hagemt
Copy link
Author

hagemt commented Nov 22, 2016

FWIW, looks like this was fixed by 6.4.0:

> process.versions
{ http_parser: '2.7.0',
  node: '6.4.0',
  v8: '5.0.71.60',
  uv: '1.9.1',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  icu: '57.1',
  modules: '48',
  openssl: '1.0.2h' }

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

3 participants