paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 387 forks source link

Not entry object and SameValueZero #377

Closed Xotic750 closed 8 years ago

Xotic750 commented 8 years ago

I was working on my ES3 compatibility shims (non-intrusive) and I wanted to use native Map and Set where available. Now, I know there have been issues in environments and so I thought I would use es6-shim as the tests seem to show that the issues have been resolved. To my surprise I found that some of my tests began to fail. I have added the tests to this PR so that you can see, either there is something wrong with my tests (but my compatibility shims pass all of these), or these are native bugs that have not yet been picked up, or there is something wrong with the es6-shims/fixes. I haven't investigated too far.

On node v0.10

[graham@tyr es6-shim]$ node
> new Map([1]);
ReferenceError: Map is not defined
    at repl:1:5
    at REPLServer.self.eval (repl.js:110:21)
    at repl.js:249:20
    at REPLServer.self.eval (repl.js:122:7)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
> require("./es6-shim.js");
> new Map("1");
{}
> new Map([1]);
{}

So the shim didn't throw a TypeError when I expected it to throw.

try {
    new Map([1]);
} catch (e) {
    console.log('threw', e);
}
try {
    new Map('1');
} catch (e) {
    console.log('threw', e);
}

http://jsfiddle.net/Xotic750/qoswzuye/

With Chromium 46.0.2490.80

threw TypeError: Iterator value 1 is not an entry object(…)
threw TypeError: Iterator value 1 is not an entry object(…)
ljharb commented 8 years ago

Thanks as always for the report! I've fixed the "iterable" cases. However, it looks like this is multiple issues - would you mind filing a new one for the SameValueZero stuff?

Xotic750 commented 8 years ago

Yes, it was two issues. The SameValueZero one seems weird as you already have tests for it (which pass), so my guess is that it is something specific about the order of creation/replacement or something, again I haven't investigated. I will open another issue/PR.