“Holes” in array when use es6 spread operator on string with emojis

“Holes” in array when use es6 spread operator on string with emojis

Why when I try split string with emoji(s) using spread(…) operator I get “holes” in result array?
Example:
[…’💪’] // -> [“💪”, hole]
Also more emojis creates more “holes”:
[…’💪💪’] // -> [“💪”, “💪”, hole, hole]
Screenshot from Chrome v71.0.3578.98:

Solutions/Answers:

Solution 1:

Certainly this is a bug.

As a workaround, Array.from() works identically except it isn’t buggy.

> s="\uD83C\uDF1F\u5FCD\u8005\u306E\u653B\u6483\uD83C\uDF1F"
> [...s]
(9) ["🌟", "忍", "者", "の", "攻", "撃", "🌟", hole, hole]
> Array.from(s)
(7) ["🌟", "忍", "者", "の", "攻", "撃", "🌟"]

It looks like the fix is in Chrome 72, but you could open a bug in Chromium and ask for it to be merged to 71.

The fix and test case are here: https://crrev.com/902d21dd661033427b56d5f93c12b12339bf55ab

(I believe “hole” is V8 telling you that some native code screwed up and failed to initialize the array properly, in contrast to “empty” which can be produced by ordinary javascript.)

Yep, V8 has definitely confused itself:

> a=[...'\u{1f4a9}']
(2) ["💩", hole]
> hole=a[1]
undefined
> hole
VM384:1 Uncaught ReferenceError: hole is not defined

References

Related:  Need to open blob/PDF in IE window