co
co copied to clipboard
TypeError due to isObject unable to recognize Objects (node 6)
Reproduction:
-
nvm install 6 && npm install co && node
- 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.
???
in my console, there is no any problems
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.
Works fine for me, node 6.7.0
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' }