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

ES6: In “Proxy, internal 'get' calls”, make the “RegExp.prototype.flags” test future-proof (failing because of hasIndices) #1717

Open
SebastianSimon opened this issue Apr 7, 2021 · 1 comment

Comments

@SebastianSimon
Copy link

SebastianSimon commented Apr 7, 2021

hasIndices (the d flag) is a new RegExp flag supported in pre-release versions of major browsers. It’s causing the “RegExp.prototype.flags” test in the “Proxy, internal 'get' calls” section to fail again (see #1208).

How can we avoid this in the future? What is this test really testing? It’s not supposed to test RegExp flag support, but implicit get calls to a Proxy (from the flags getter), right? So why not limit the test to one or two well-supported flags? For example:

const queriedProperties = [];

Object.getOwnPropertyDescriptor(RegExp.prototype, "flags")
  .get
  .call(new Proxy({}, {
    get(object, key) {
      queriedProperties.push(key);

      return object[key];
    }
  }));

return queriedProperties.includes("global") && queriedProperties.includes("ignoreCase")
  && queriedProperties.indexOf("global") < queriedProperties.indexOf("ignoreCase"); // Testing order.

Of course, the actual code would probably use var, and other more compatible constructs.

By the way, in the current test, there’s also a typo: // Sorted alphabetically by shortname – "gumsuy".. That should be “gimsuy”, or with the additional flag: “dgimsuy”, but of course this may become obsolete, depending on how the updated test is implemented.

@ljharb
Copy link
Member

ljharb commented Apr 7, 2021

It's pretty important that the current Proxy test ensure that no unexpected Gets are performed.

RegExp flags are added very rarely; I think it's totally fine to need to update the test when a new one is added.

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