co icon indicating copy to clipboard operation
co copied to clipboard

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

Open hagemt opened this issue 8 years ago • 4 comments

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 avatar Jul 18 '16 15:07 hagemt

???

image

in my console, there is no any problems

alsotang avatar Jul 19 '16 04:07 alsotang

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.

hagemt avatar Jul 19 '16 19:07 hagemt

Works fine for me, node 6.7.0

havenchyk avatar Oct 02 '16 17:10 havenchyk

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' }

hagemt avatar Nov 22 '16 20:11 hagemt