If F contains any code unit other than "g", "i", "m", "s", "u", or "y" or if it contains the same code unit more than once, throw a SyntaxError exception.
If F contains "u", let BMP be false; else let BMP be true.
If BMP is true, then
Parse P using the grammars in 21.2.1 and interpreting each of its 16-bit elements as a Unicode BMP code point. UTF-16 decoding is not applied to the elements. The goal symbol for the parse is Pattern[~U]. Throw a SyntaxError exception if P did not conform to the grammar, if any elements of P were not matched by the parse, or if any Early Error conditions exist.
Let patternCharacters be a List whose elements are the code unit elements of P.
Else,
Parse P using the grammars in 21.2.1 and interpreting P as UTF-16 encoded Unicode code points (6.1.4). The goal symbol for the parse is Pattern[+U]. Throw a SyntaxError exception if P did not conform to the grammar, if any elements of P were not matched by the parse, or if any Early Error conditions exist.
Let patternCharacters be a List whose elements are the code points resulting from applying UTF-16 decoding to P's sequence of elements.
Set obj.[[OriginalSource]] to P.
Set obj.[[OriginalFlags]] to F.
Set obj.[[RegExpMatcher]] to the internal procedure that evaluates the above parse of P by applying the semantics provided in 21.2.2 using patternCharacters as the pattern's List of SourceCharacter values and F as the flag parameters.
The descriptions below use the following variables:
Input is a List consisting of all of the characters, in order, of the String being matched by the regular expression pattern. Each character is either a code unit or a code point, depending upon the kind of pattern involved. The notation Input[n] means the nth character of Input, where n can range between 0 (inclusive) and InputLength (exclusive).
InputLength is the number of characters in Input.
NcapturingParens is the total number of left capturing parentheses (i.e. the total number of times the Atom::(Disjunction) production is expanded) in the pattern. A left capturing parenthesis is any ( pattern character that is matched by the ( terminal of the Atom::(Disjunction) production.
DotAll is true if the RegExp object's [[OriginalFlags]] internal slot contains "s" and otherwise is false.
IgnoreCase is true if the RegExp object's [[OriginalFlags]] internal slot contains "i" and otherwise is false.
Multiline is true if the RegExp object's [[OriginalFlags]] internal slot contains "m" and otherwise is false.
Unicode is true if the RegExp object's [[OriginalFlags]] internal slot contains "u" and otherwise is false.
The algorithm listed in 21.2.2.8 Atom is modified as follows.