Closed Bug 1539690 Opened 10 months ago Closed 10 months ago

Publicly expose a JS::RegExpFlag::* set of constants as flag-bits, JS::RegExpFlags as encapsulating bit-set

Categories

(Core :: JavaScript Engine, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: Waldo, Assigned: Waldo)

References

Details

Attachments

(1 file)

js/public/RegExp.h has uint8_t JS::RegExpFlags::* constants in it now, but sets of flags in API are just raw numbers. Moreover, all the bits are duplicated as *Flag constants internally, which makes no sense. We should have only one version of all of them, and it should be public.

It would be ideal if we could have an enum of bits, whose initializers could be accessed by qualified JS::RegExpFlags::* names, that supports flag-friendly access. mfbt/TypedEnumBits.h intends to support this. Unfortunately, it's super-fragile:

enum class E : uint8_t
{
  A = 0,
  B = 1,
  C = 2,
};

MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(E)

void f(bool) {}

int main()
{
  E e = E::A;
  f(e & E::A); // fails to compile, and-result doesn't convert to bool here

  e |= ~E::A; // fails to compile, negation-result is wrong type here
}

I tried for too long to fix this but ultimately gave up. If it's possible, it's not worth my time to figure it out.

Soooooo...just have a JS::RegExpFlag akin to the current JS::RegExpFlags struct of constants, and add a JS::RegExpFlags flag-set abstraction to expose flags. Not the ideally minimal amount of code, but whatever.

Priority: -- → P1
Pushed by jwalden@mit.edu:
https://hg.mozilla.org/integration/autoland/rev/6f8d311064d9
Make a JS::RegExpFlag public API for flag bits, and make a JS::RegExpFlags flag-set abstraction.  r=sfink
Pushed by jwalden@mit.edu:
https://hg.mozilla.org/integration/autoland/rev/4b7338224751
Make a JS::RegExpFlag public API for flag bits, and make a JS::RegExpFlags flag-set abstraction.  r=sfink
Status: ASSIGNED → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
Flags: needinfo?(jwalden)
Regressions: 1546300
You need to log in before you can comment on or make changes to this bug.