Skip to content

Make Array includes() polyfill not enumerable#7517

Merged
aghassemi merged 2 commits intoampproject:masterfrom
aghassemi:includes
Feb 14, 2017
Merged

Make Array includes() polyfill not enumerable#7517
aghassemi merged 2 commits intoampproject:masterfrom
aghassemi:includes

Conversation

@aghassemi
Copy link
Copy Markdown
Contributor

All the for var in arr code that did not check hasOwnProperty has been broken since the polyfill did not make includes not enumerable.

Fixes Chrome 45 tests failures on Master as well.

/to @jridgewell

@aghassemi aghassemi requested a review from jridgewell February 13, 2017 22:02
@jridgewell
Copy link
Copy Markdown
Contributor

Who on earth is using a for-in on an array?

If we do this, let's update the other polyfills.

if (!win.Array.prototype.includes) {
win.Array.prototype.includes = includes;
win.Object.defineProperty(Array.prototype, 'includes', {
enumerable: false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enumerable can be omitted, since it defaults to false. However, we should include writable: true and configurable: true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use-case for making it writable and configurable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It matches the normal methods. Plus this is just confusing:

// Setup
var Arr = Object.create(Array.prototype, { includes: { value: Array.prototype.includes } });
var a = Object.create(Arr);

// Surprise!
a.includes = 'test';
a.includes; // => function includes() { [native code] }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, you are right, native includes is writable and configurable. Did not expect that...

@aghassemi
Copy link
Copy Markdown
Contributor Author

@jridgewell PTAL, I am keeping enumerable: false to be explicit.

@aghassemi aghassemi merged commit 05d0f57 into ampproject:master Feb 14, 2017
@dreamofabear
Copy link
Copy Markdown

Thanks for fixing this!

@muxin
Copy link
Copy Markdown
Contributor

muxin commented Feb 14, 2017

The following tests are failing on travis after this

Chrome 56.0.2924 (Linux 0.0.0) amp-youtube Actions should support mute, play, pause, unmute actions FAILED
	Error: timeout of 20000ms exceeded. Ensure the done() callback is being called in this test.
Chrome 56.0.2924 (Linux 0.0.0) amp-youtube Autoplay play/pause should play when in view port initially FAILED
	Error: timeout of 20000ms exceeded. Ensure the done() callback is being called in this test.
.
Chrome 56.0.2924 (Linux 0.0.0) amp-youtube Autoplay play/pause should play/pause when video enters/exists viewport FAILED
	Error: timeout of 20000ms exceeded. Ensure the done() callback is being called in this test.

Not sure whether these are flakes.

@aghassemi
Copy link
Copy Markdown
Contributor Author

amp-youtube failures were just a flake with slow YouTube.

https://travis-ci.org/ampproject/amphtml/builds/201349924

Currently the only failure is Chrome 45.0.2454 (Linux 0.0.0) 3p-frame should create an iframe FAILED

@muxin
Copy link
Copy Markdown
Contributor

muxin commented Feb 14, 2017

Yeah, it's a flake :)

torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Feb 14, 2017
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
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

Successfully merging this pull request may close these issues.

4 participants