2.8.7.1 RegExp.prototype.compile(pattern, flags)

If pattern is an object R that has a [[Class]] property "RegExp" and flags is undefined, let P be the pattern used to construct R, and let F be the flags used to construct R. If pattern is an object R that has a [[Class]] property "RegExp", and flags is not undefined, throw a SyntaxError exception. Otherwise, let P be "(?:)" if pattern is undefined and ToString(pattern) otherwise, and let F be the empty string if flags is undefined and ToString(flags) otherwise.

The global property of this RegExp object is set to a Boolean value that is true if F contains the character "g" and that is false otherwise.

The ignoreCase property of this RegExp object is set to a Boolean value that is true if F contains the character "i" and that is false otherwise.

The multiline property of this RegExp object is set to a Boolean value that is true if F contains the character "m" and that is false otherwise.

If F contains any character other than "g", "i", or "m", throw a SyntaxError exception.

If the characters in P do not have the form Pattern, throw a SyntaxError exception. Otherwise, let the newly constructed object have a [[Match]] property obtained by evaluating ("compiling") Pattern.

The source property of this RegExp object is set as follows:

  1. When pattern is an object R that has a [[Class]] property of "RegExp", this RegExp object is set to the same string value as the value of the source property of pattern. Otherwise, the source property of this RegExp object is set to P.

  2. The lastIndex property of this RegExp object is set to 0.

  3. The options property of this RegExp object is set as described in section 2.8.8.1 of this document.

  4. This RegExp object is optimized using the assumption that it will be executed multiple times.