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

An unexpected behaviour in strict mode in PhantomJS #1286

Closed
aleen42 opened this issue Sep 1, 2023 · 0 comments
Closed

An unexpected behaviour in strict mode in PhantomJS #1286

aleen42 opened this issue Sep 1, 2023 · 0 comments

Comments

@aleen42
Copy link
Contributor

aleen42 commented Sep 1, 2023

Recently, I have found that when I upgraded core-js, a test case run in PhantomJS had failed with the following exception:

PhantomJS 2.1.1 (Mac OS 0.0.0) LOG: 'polyfill load failed', ReferenceError: Can't find variable: SAFE_CLOSING
exports
eval code
eval@[native code]
./node_modules/core-js/modules/es.array.from.js@http://localhost:9876/base/build/coremail/__karma__bundle/commons.js?407226f1f29b0c48cbb273c58df7aaa58a0e970e:3027:5
__webpack_require__@http://localhost:9876/base/build/coremail/__karma__bundle/runtime.js?3c2a1c270c4c70b6d7720b608d8bc64728c3bd1b:31:46

To trace the source, I have found that the behaviour existed due to the commit 11f4ec8, which specified check-correctness-of-iteration.js to execute in strict mode.

'use strict';
var wellKnownSymbol = require('../internals/well-known-symbol');

var ITERATOR = wellKnownSymbol('iterator');
var SAFE_CLOSING = false;

try {
  var called = 0;
  var iteratorWithReturn = {
    next: function () {
      return { done: !!called++ };
    },
    'return': function () {
      SAFE_CLOSING = true;
    }
  };
  iteratorWithReturn[ITERATOR] = function () {
    return this;
  };
  // eslint-disable-next-line es/no-array-from, no-throw-literal -- required for testing
  Array.from(iteratorWithReturn, function () { throw 2; });
} catch (error) { /* empty */ }

module.exports = function (exec, SKIP_CLOSING) {
  if (!SKIP_CLOSING && !SAFE_CLOSING) return false; // Can't find variable: SAFE_CLOSING
  // ...
}

After a simple trial, I found that the execution of the following snippet has broken the scope:

Array.from(iteratorWithReturn, function () { throw 2; });
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