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

LegacyIteratorNext issue with iterators. #906

Closed
romainmenke opened this issue Jan 9, 2021 · 4 comments
Closed

LegacyIteratorNext issue with iterators. #906

romainmenke opened this issue Jan 9, 2021 · 4 comments

Comments

@romainmenke
Copy link

romainmenke commented Jan 9, 2021

for (;!(step = next.call(iterator)).done; index++) {

Run through babel + core-js.
Test in older firefox (43 has the error)

const url = new URL(
	'https://u:p@example.com:8080/some/path?foo=true&bar=true#frag'
);

Array.from(url.searchParams.entries());

Result :

Page will freeze with an infinite loop.


Caused by : https://github.com/mozilla/gecko-dev/blob/0f254a30d684796bcc8b6e2a102a0095d25842bb/js/src/builtin/Iterator.js#L14

Hacky way to circumvent :

next = iterator.next;
var isLegacyIteratorNext = next.name === 'LegacyIteratorNext';
result = new C();
for (;!(step = (isLegacyIteratorNext ? next.call(iterator).value : next.call(iterator))).done; index++) {
  value = mapping ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true) : step.value;
  createProperty(result, index, value);

  if (index > 150) { // how to detect the infinite loop
    throw new Error('panic');
  }
}

Unsure what changed.
We started seeing this error a couple of weeks ago but it might have always been there and maybe didn't get reported.

@zloirock
Copy link
Owner

zloirock commented Jan 9, 2021

core-js does not use native URL and URLSearchParams in FF43, they should overwritten in FF57-. Make sure that you load all required modules.

@romainmenke
Copy link
Author

romainmenke commented Jan 9, 2021

This is with the overwritten URL and URLSearchParams (i think).

modules by path ../../../node_modules/core-js/internals/*.js 51.6 KiB 81 modules
modules by path ../../../node_modules/core-js/modules/*.js 48.9 KiB
  ../../../node_modules/core-js/modules/es.array.from.js 433 bytes [built] [code generated]
  ../../../node_modules/core-js/modules/es.array.iterator.js 2.1 KiB [built] [code generated]
  ../../../node_modules/core-js/modules/es.object.to-string.js 380 bytes [built] [code generated]
  ../../../node_modules/core-js/modules/es.string.iterator.js 1.01 KiB [built] [code generated]
  ../../../node_modules/core-js/modules/web.dom-collections.iterator.js 1.53 KiB [built] [code generated]
  ../../../node_modules/core-js/modules/web.url.js 31.9 KiB [built] [code generated]
  ../../../node_modules/core-js/modules/web.url-search-params.js 11.6 KiB [built] [code generated]

babel config :

module: {
	rules: [
		{
			test: /\.js$/,
			exclude: /(node_modules)/,
			use: {
				loader: 'babel-loader',
				options: {
					comments: false,
					presets: [
						[
							'@babel/preset-env',
							{
								corejs: '^3.6.3',
								targets: {
									browsers: [ 'chrome >= 26', 'edge >= 12', 'firefox >= 26', 'opera >= 26', 'safari >= 6', 'ie >= 8' ],
								},
								useBuiltIns: 'usage'
							}
						]
					]
				}
			}
		}
	]
}

@romainmenke
Copy link
Author

romainmenke commented Jan 9, 2021

A minimal project that reproduces the issue :

https://github.com/romainmenke/legacy-iterator-next

When visiting the page in Firefox 43 :

Screenshot 2021-01-09 at 23 02 43


update

Also added a log to make sure URLSearchParams uses the polyfill iterator next and it does.

Screenshot 2021-01-10 at 09 20 53

@romainmenke
Copy link
Author

Thank you @zloirock for taking the time to look into this and for having a fix so quickly!
Really appreciate all the hard work that goes into this project!

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