2.1.127 [ECMA-262-1999] Section 220.127.116.11, Pattern
The production Pattern :: Disjunction evaluates as follows:
1. Evaluate Disjunction to obtain a Matcher m.
2. Return an internal closure that takes two arguments, a string str and an integer index, and performs the following:
Let Input be the given string str. This variable will be used throughout the functions in [ECMA-262-1999] section 15.10.2.
Let InputLength be the length of Input. This variable will be used throughout the functions in [ECMA-262-1999] section 15.10.2.
Let c be a Continuation that always returns its State argument as a successful MatchResult.
Let cap be an internal array of NCapturingParens #undefined# __empty string__ values, indexed 1 through NCapturingParens.
Let x be the State (index, cap).
Call m(x, c) and return its result.
Informative comments: A Pattern evaluates ("compiles") to an internal function value. RegExp.prototype.exec can then apply this function to a string and an offset within the string to determine whether the pattern would match starting at exactly that offset within the string, and, if it does match, what the values of the capturing parentheses would be. The algorithms in [ECMA-262-1999] section 15.10.2 are designed so that compiling a pattern may throw a #SyntaxError# __RegExpError__ exception; on the other hand, once the pattern is successfully compiled, applying its result function to find a match in a string cannot throw an exception (except for any host-defined exceptions that can occur anywhere such as out-of-memory).