'use strict';
new Map('a');
// Node.js 4.8.5
new Map('a');
^
TypeError: Iterator value a is not an entry object
// Node.js 6.11.5
new Map('a');
^
TypeError: Iterator value a is not an entry object
// Node.js 8.9.0
<no output>
// Node.js 9.0.0
<no output>
// Node.js 10.0.0 nightly 2017.11.06
<no output>
This only happens with a file script. In the REPL, new Map('a') throws TypeError in all these versions.
@nodejs/v8, Is it an upstream bug?
â–¶ ./d8
V8 version 6.2.414.32
d8> new Map('a');
TypeError: Iterator value a is not an entry object
TypeError: Iterator value a is not an entry object
at new Map (<anonymous>)
at (d8):1:1
â–¶ ./d8 file.js
TypeError: Iterator value a is not an entry object
TypeError: Iterator value a is not an entry object
at new Map (<anonymous>)
at file.js:3:1
@vsemozhetbyt Doesn't look like it
@joyeecheung Maybe we should also check with the module wrapper to be sure (compare https://github.com/nodejs/node/issues/15386):
> (function (exports, require, module, __filename, __dirname) { new Map('a'); })();
TypeError: Iterator value a is not an entry object
at new Map (<anonymous>)
at repl:1:63
@vsemozhetbyt d8 still throws with the wrapper
â–¶ ./d8 file.js
TypeError: Iterator value a is not an entry object
TypeError: Iterator value a is not an entry object
at new Map (<anonymous>)
at file.js:1:63
at file.js:1:79
I can reproduce with the latest canary (v10.0.0-v8-canary2017110614c987bd6b)
Looks like some kind of crash.
'use strict';
console.log('a');
try {
console.log(new Map('a'));
} catch (err) {
console.log(err);
}
console.log('b');
prints a, the error, and b as expected, yet
'use strict';
console.log('a');
console.log(new Map('a'));
console.log('b');
only prints a.
cc @gsathya
@bmeurer Should not this be an early error at the parsing time?
It's correct syntax. Why would it be an early error?
@hashseed We can know that a string is not an appropriate iterable in all such cases?
At parse time you can't know what Map refers to. I could simply overwrite the global Map object.
Interestingly, with the following code
'use strict';
console.log('a');
new Map('a');
console.log('b');
v8::internal::Isolate::Throw never triggers. Instead, we call Rethrow.
This is a bug in V8. The Map constructor does not throw correctly.
I filed an upstream issue.
cc @gsathya @caitp.
The upcoming fix is here: https://chromium-review.googlesource.com/c/v8/v8/+/758372
Fix has landed upstream.
Most helpful comment
The upcoming fix is here: https://chromium-review.googlesource.com/c/v8/v8/+/758372