Node: new Map(wrong_iterable) swallow TypeError in file scripts

Created on 7 Nov 2017  Â·  15Comments  Â·  Source: nodejs/node

  • Version: 8–10
  • Platform: Windows 7 x64
  • Subsystem: ?
'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.

V8 Engine confirmed-bug

Most helpful comment

All 15 comments

@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.

Fix has landed upstream.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seishun picture seishun  Â·  3Comments

danielstaleiny picture danielstaleiny  Â·  3Comments

vsemozhetbyt picture vsemozhetbyt  Â·  3Comments

fanjunzhi picture fanjunzhi  Â·  3Comments

jmichae3 picture jmichae3  Â·  3Comments