Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPolyfill is incorrect, Array.find is always shimmed when calling .shim() #22

Closed
zerovox opened this issue Jan 23, 2017 · 8 comments
Closed

Comments

@zerovox
Copy link

zerovox commented Jan 23, 2017

var implemented = Array.prototype.find && [, 1].find(function (item, index) {
	return index === 0;
});

The comment says 'Detect early implementations which skipped holes in sparse arrays' but this code appears to return the first item in the array, which is undefined, hence implemented returns false. I believe that whole clause should be negated.

@zerovox
Copy link
Author

zerovox commented Jan 23, 2017

I believe this bug is present in es6-shim too, filed #433 to track

@ljharb
Copy link
Collaborator

ljharb commented Jan 23, 2017

Thanks, I'll fix in both places.

@ljharb ljharb closed this as completed in 026db56 Jan 23, 2017
@ljharb
Copy link
Collaborator

ljharb commented Jan 24, 2017

Released in v2.0.2

@zerovox
Copy link
Author

zerovox commented Jan 24, 2017

Did you test this in chrome @ljharb? I'm pretty sure this fix has the exact same issue. The es6-shim fix looks correct though (the predicate in es6-shims means shouldShim, whereas here it means implemented)

@ljharb
Copy link
Collaborator

ljharb commented Jan 24, 2017

@zerovox ah crap, you're right. I forgot the negation :-) v2.0.3 coming soon.

ljharb added a commit that referenced this issue Jan 24, 2017
@ljharb
Copy link
Collaborator

ljharb commented Jan 24, 2017

(for the record; my tests only test for proper behavior; an overzealous shim is not an observable bug, it's simply a negligible performance hit :-) )

@zerovox
Copy link
Author

zerovox commented Jan 24, 2017

Thanks for the quick fixes! Yep, correctness wasn't an issue but the shimmed .find is unfortunately slower than the native equivalent in our use case. Might be possible to test the overzealous shimming in es6-shim with a test that shims once then mocks overrideNative and attempts to shim a second time - overrideNative should, theoretically, never be called on the second iteration.

@ljharb
Copy link
Collaborator

ljharb commented Jan 24, 2017

That's a very interesting idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants