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

Attempt to fix the Array.prototype.includes and String.prototype.includes polyfills (issue 9514, 9516) #9520

Merged
merged 1 commit into from
Mar 1, 2018
Merged

Attempt to fix the Array.prototype.includes and String.prototype.includes polyfills (issue 9514, 9516) #9520

merged 1 commit into from
Mar 1, 2018

Conversation

Snuffleupagus
Copy link
Collaborator

I don't understand why the previous way importing the polyfills didn't work, and I don't have time to try and figure it out, however this patch seems to fix things.

Fixes #9514.
Fixes #9516.

@@ -131,7 +131,7 @@ PDFJS.compatibilityChecked = true;
if (String.prototype.includes) {
return;
}
String.prototype.includes = require('core-js/fn/string/includes');
Copy link
Member

Choose a reason for hiding this comment

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

Just remove the String.prototype.includes = part and this should work.

When you import core-js/fn/string/includes, then String.prototype.includes is already overwritten, which can be seen using the following example:

$ node -e 'delete String.prototype.includes; console.log("".includes); require("core-js/fn/string/includes"); console.log("abc".includes("a"))'
undefined
true

The exported function from require('core-js/fn/string/includes') does not use this, but expects the first parameter to be the string, and the other parameters to be the parameters for the string method. I.e. require('core-js/fn/string/includes')("abc", "b");. With the current (wrong) code, it becomes require('core-js/fn/string/includes').call("abc", "b"), which becomes (since thisis ignored)require('core-js/fn/string/includes')("b"), i.e. equivalent to "b".includes(undefined)`.

The documentation at https://github.com/zloirock/core-js#usage also shows that the intended usage for the default mode is to just call require and not use its return value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you; I've made the suggested changes and everything seems to work just fine now!

…ncludes` polyfills (issue 9514, 9516)

I don't understand why the previous way importing the polyfills didn't work, and I don't have time to try and figure it out, however this patch seems to fix things.

Fixes 9514.
Fixes 9516.
@pdfjsbot
Copy link

pdfjsbot commented Mar 1, 2018

From: Bot.io (Linux m4)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/4ed073dd5007fac/output.txt

@mozilla mozilla deleted a comment from pdfjsbot Mar 1, 2018
@mozilla mozilla deleted a comment from pdfjsbot Mar 1, 2018
@pdfjsbot
Copy link

pdfjsbot commented Mar 1, 2018

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/4ed073dd5007fac/output.txt

Total script time: 2.59 mins

Published

@Rob--W Rob--W merged commit 401f3a9 into mozilla:master Mar 1, 2018
@Rob--W
Copy link
Member

Rob--W commented Mar 1, 2018

Squashed two bugs in one PR, good one!

@Snuffleupagus Snuffleupagus deleted the fix-includes-polyfills branch March 1, 2018 17:09
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
…ills

Attempt to fix the `Array.prototype.includes` and `String.prototype.includes` polyfills (issue 9514, 9516)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrong polyfill with IE11 ? Warning: FormatError: Required "loca" table is not found in Internet Explorer
3 participants