kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | // Expect $Object = global.Object; |
| 29 | // Expect $Array = global.Array; |
| 30 | |
| 31 | const $RegExp = global.RegExp; |
| 32 | |
| 33 | // A recursive descent parser for Patterns according to the grammar of |
| 34 | // ECMA-262 15.10.1, with deviations noted below. |
| 35 | function DoConstructRegExp(object, pattern, flags, isConstructorCall) { |
| 36 | // RegExp : Called as constructor; see ECMA-262, section 15.10.4. |
| 37 | if (IS_REGEXP(pattern)) { |
| 38 | if (!IS_UNDEFINED(flags)) { |
| 39 | throw MakeTypeError('regexp_flags', []); |
| 40 | } |
| 41 | flags = (pattern.global ? 'g' : '') |
| 42 | + (pattern.ignoreCase ? 'i' : '') |
| 43 | + (pattern.multiline ? 'm' : ''); |
| 44 | pattern = pattern.source; |
| 45 | } |
| 46 | |
| 47 | pattern = IS_UNDEFINED(pattern) ? '' : ToString(pattern); |
| 48 | flags = IS_UNDEFINED(flags) ? '' : ToString(flags); |
| 49 | |
| 50 | var global = false; |
| 51 | var ignoreCase = false; |
| 52 | var multiline = false; |
| 53 | |
| 54 | for (var i = 0; i < flags.length; i++) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 55 | var c = StringCharAt.call(flags, i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 56 | switch (c) { |
| 57 | case 'g': |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 58 | // Allow duplicate flags to be consistent with JSC and others. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 59 | global = true; |
| 60 | break; |
| 61 | case 'i': |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 62 | ignoreCase = true; |
| 63 | break; |
| 64 | case 'm': |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | multiline = true; |
| 66 | break; |
| 67 | default: |
| 68 | // Ignore flags that have no meaning to be consistent with |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 69 | // JSC. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | break; |
| 71 | } |
| 72 | } |
| 73 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 74 | if (!isConstructorCall) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 75 | regExpCache.type = 'none'; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 77 | %RegExpInitializeObject(object, pattern, global, ignoreCase, multiline); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | |
| 79 | // Call internal function to compile the pattern. |
| 80 | %RegExpCompile(object, pattern, flags); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 81 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 82 | |
| 83 | |
| 84 | function RegExpConstructor(pattern, flags) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 85 | if (%_IsConstructCall()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | DoConstructRegExp(this, pattern, flags, true); |
| 87 | } else { |
| 88 | // RegExp : Called as function; see ECMA-262, section 15.10.3.1. |
| 89 | if (IS_REGEXP(pattern) && IS_UNDEFINED(flags)) { |
| 90 | return pattern; |
| 91 | } |
| 92 | return new $RegExp(pattern, flags); |
| 93 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 94 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 95 | |
| 96 | |
| 97 | // Deprecated RegExp.prototype.compile method. We behave like the constructor |
| 98 | // were called again. In SpiderMonkey, this method returns the regexp object. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 99 | // In JSC, it returns undefined. For compatibility with JSC, we match their |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 100 | // behavior. |
| 101 | function CompileRegExp(pattern, flags) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 102 | // Both JSC and SpiderMonkey treat a missing pattern argument as the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | // empty subject string, and an actual undefined value passed as the |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 104 | // pattern as the string 'undefined'. Note that JSC is inconsistent |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | // here, treating undefined values differently in |
| 106 | // RegExp.prototype.compile and in the constructor, where they are |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 107 | // the empty string. For compatibility with JSC, we match their |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 108 | // behavior. |
| 109 | if (IS_UNDEFINED(pattern) && %_ArgumentsLength() != 0) { |
| 110 | DoConstructRegExp(this, 'undefined', flags, false); |
| 111 | } else { |
| 112 | DoConstructRegExp(this, pattern, flags, false); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | function DoRegExpExec(regexp, string, index) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 118 | var result = %_RegExpExec(regexp, string, index, lastMatchInfo); |
| 119 | if (result !== null) lastMatchInfoOverride = null; |
| 120 | return result; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 121 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | |
| 123 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 124 | function RegExpCache() { |
| 125 | this.type = 'none'; |
| 126 | this.regExp = 0; |
| 127 | this.subject = 0; |
| 128 | this.replaceString = 0; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 129 | this.answer = 0; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 130 | // answerSaved marks whether the contents of answer is valid for a cache |
| 131 | // hit in RegExpExec, StringMatch and StringSplit. |
| 132 | this.answerSaved = false; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 133 | this.splitLimit = 0; // Used only when type is "split". |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | |
| 137 | var regExpCache = new RegExpCache(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 138 | |
| 139 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 140 | function BuildResultFromMatchInfo(lastMatchInfo, s) { |
| 141 | var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; |
| 142 | var result = %_RegExpConstructResult(numResults, lastMatchInfo[CAPTURE0], s); |
| 143 | if (numResults === 1) { |
| 144 | var matchStart = lastMatchInfo[CAPTURE(0)]; |
| 145 | var matchEnd = lastMatchInfo[CAPTURE(1)]; |
| 146 | result[0] = SubString(s, matchStart, matchEnd); |
| 147 | } else { |
| 148 | for (var i = 0; i < numResults; i++) { |
| 149 | var matchStart = lastMatchInfo[CAPTURE(i << 1)]; |
| 150 | var matchEnd = lastMatchInfo[CAPTURE((i << 1) + 1)]; |
| 151 | if (matchStart != -1 && matchEnd != -1) { |
| 152 | result[i] = SubString(s, matchStart, matchEnd); |
| 153 | } else { |
| 154 | // Make sure the element is present. Avoid reading the undefined |
| 155 | // property from the global object since this may change. |
| 156 | result[i] = void 0; |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | return result; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | function RegExpExecNoTests(regexp, string, start) { |
| 165 | // Must be called with RegExp, string and positive integer as arguments. |
| 166 | var matchInfo = DoRegExpExec(regexp, string, start); |
| 167 | var result = null; |
| 168 | if (matchInfo !== null) { |
| 169 | result = BuildResultFromMatchInfo(matchInfo, string); |
| 170 | } |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 175 | function RegExpExec(string) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 176 | if (!IS_REGEXP(this)) { |
| 177 | throw MakeTypeError('incompatible_method_receiver', |
| 178 | ['RegExp.prototype.exec', this]); |
| 179 | } |
| 180 | |
| 181 | var cache = regExpCache; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 182 | var saveAnswer = false; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 183 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 184 | var lastIndex = this.lastIndex; |
| 185 | |
| 186 | // Since cache.subject is always a string, a matching input can not |
| 187 | // cause visible side-effects when converted to a string, so we can omit |
| 188 | // the conversion required by the specification. |
| 189 | // Likewise, the regexp.lastIndex and regexp.global properties are value |
| 190 | // properties that are not configurable, so reading them can also not cause |
| 191 | // any side effects (converting lastIndex to a number can, though). |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 192 | if (%_ObjectEquals(cache.type, 'exec') && |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 193 | %_ObjectEquals(0, lastIndex) && |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 194 | %_IsRegExpEquivalent(cache.regExp, this) && |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 195 | %_ObjectEquals(cache.subject, string)) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 196 | if (cache.answerSaved) { |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 197 | // The regexp.lastIndex value must be 0 for non-global RegExps, and for |
| 198 | // global RegExps we only cache negative results, which gives a lastIndex |
| 199 | // of zero as well. |
| 200 | this.lastIndex = 0; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 201 | return %_RegExpCloneResult(cache.answer); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 202 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 203 | saveAnswer = true; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 207 | if (%_ArgumentsLength() === 0) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 208 | var regExpInput = LAST_INPUT(lastMatchInfo); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 209 | if (IS_UNDEFINED(regExpInput)) { |
| 210 | throw MakeError('no_input_to_regexp', [this]); |
| 211 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 212 | string = regExpInput; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 213 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 214 | var s; |
| 215 | if (IS_STRING(string)) { |
| 216 | s = string; |
| 217 | } else { |
| 218 | s = ToString(string); |
| 219 | } |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 220 | var global = this.global; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 221 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 222 | // Conversion is required by the ES5 specification (RegExp.prototype.exec |
| 223 | // algorithm, step 5) even if the value is discarded for non-global RegExps. |
| 224 | var i = TO_INTEGER(lastIndex); |
| 225 | if (global) { |
| 226 | if (i < 0 || i > s.length) { |
| 227 | this.lastIndex = 0; |
| 228 | return null; |
| 229 | } |
| 230 | } else { |
| 231 | i = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | } |
| 233 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 234 | %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, s, lastIndex]); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 235 | // matchIndices is either null or the lastMatchInfo array. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 236 | var matchIndices = %_RegExpExec(this, s, i, lastMatchInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 237 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 238 | if (matchIndices === null) { |
| 239 | if (global) { |
| 240 | // Cache negative result only if initial lastIndex was zero. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 241 | this.lastIndex = 0; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 242 | if (lastIndex !== 0) return matchIndices; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 243 | } |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 244 | cache.regExp = this; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 245 | cache.subject = s; // Always a string. |
| 246 | cache.answer = null; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 247 | cache.answerSaved = true; // Safe since no cloning is needed. |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 248 | cache.type = 'exec'; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 249 | return matchIndices; // No match. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | } |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 251 | |
| 252 | // Successful match. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 253 | lastMatchInfoOverride = null; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 254 | var result = BuildResultFromMatchInfo(matchIndices, s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 256 | if (global) { |
| 257 | // Don't cache positive results for global regexps. |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 258 | this.lastIndex = lastMatchInfo[CAPTURE1]; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 259 | } else { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 260 | cache.regExp = this; |
| 261 | cache.subject = s; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 262 | if (saveAnswer) cache.answer = %_RegExpCloneResult(result); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 263 | cache.answerSaved = saveAnswer; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 264 | cache.type = 'exec'; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 265 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 266 | return result; |
| 267 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 268 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | |
| 270 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 271 | // One-element cache for the simplified test regexp. |
| 272 | var regexp_key; |
| 273 | var regexp_val; |
| 274 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 275 | // Section 15.10.6.3 doesn't actually make sense, but the intention seems to be |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 276 | // that test is defined in terms of String.prototype.exec. However, it probably |
| 277 | // means the original value of String.prototype.exec, which is what everybody |
| 278 | // else implements. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 279 | function RegExpTest(string) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 280 | if (!IS_REGEXP(this)) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 281 | throw MakeTypeError('incompatible_method_receiver', |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 282 | ['RegExp.prototype.test', this]); |
| 283 | } |
| 284 | if (%_ArgumentsLength() == 0) { |
| 285 | var regExpInput = LAST_INPUT(lastMatchInfo); |
| 286 | if (IS_UNDEFINED(regExpInput)) { |
| 287 | throw MakeError('no_input_to_regexp', [this]); |
| 288 | } |
| 289 | string = regExpInput; |
| 290 | } |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 291 | |
| 292 | var lastIndex = this.lastIndex; |
| 293 | |
| 294 | var cache = regExpCache; |
| 295 | if (%_ObjectEquals(cache.type, 'test') && |
| 296 | %_IsRegExpEquivalent(cache.regExp, this) && |
| 297 | %_ObjectEquals(cache.subject, string) && |
| 298 | %_ObjectEquals(0, lastIndex)) { |
| 299 | // The regexp.lastIndex value must be 0 for non-global RegExps, and for |
| 300 | // global RegExps we only cache negative results, which gives a resulting |
| 301 | // lastIndex of zero as well. |
| 302 | if (global) this.lastIndex = 0; |
| 303 | return cache.answer; |
| 304 | } |
| 305 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 306 | var s; |
| 307 | if (IS_STRING(string)) { |
| 308 | s = string; |
| 309 | } else { |
| 310 | s = ToString(string); |
| 311 | } |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 312 | var length = s.length; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 313 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 314 | // Conversion is required by the ES5 specification (RegExp.prototype.exec |
| 315 | // algorithm, step 5) even if the value is discarded for non-global RegExps. |
| 316 | var i = TO_INTEGER(lastIndex); |
| 317 | if (global) { |
| 318 | if (i < 0 || i > length) { |
| 319 | this.lastIndex = 0; |
| 320 | return false; |
| 321 | } |
| 322 | } else { |
| 323 | i = 0; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 324 | } |
| 325 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 326 | var global = this.global; |
| 327 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 328 | // Remove irrelevant preceeding '.*' in a test regexp. The expression |
| 329 | // checks whether this.source starts with '.*' and that the third |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 330 | // char is not a '?' |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 331 | if (%_StringCharCodeAt(this.source, 0) == 46 && // '.' |
| 332 | %_StringCharCodeAt(this.source, 1) == 42 && // '*' |
| 333 | %_StringCharCodeAt(this.source, 2) != 63) { // '?' |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 334 | if (!%_ObjectEquals(regexp_key, this)) { |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 335 | regexp_key = this; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 336 | regexp_val = new $RegExp(this.source.substring(2, this.source.length), |
| 337 | (this.global ? 'g' : '') |
| 338 | + (this.ignoreCase ? 'i' : '') |
| 339 | + (this.multiline ? 'm' : '')); |
| 340 | } |
| 341 | if (!regexp_val.test(s)) return false; |
| 342 | } |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 343 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 344 | %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, s, lastIndex]); |
| 345 | // matchIndices is either null or the lastMatchInfo array. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 346 | var matchIndices = %_RegExpExec(this, s, i, lastMatchInfo); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 347 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 348 | var result = (matchIndices !== null); |
| 349 | if (result) { |
| 350 | lastMatchInfoOverride = null; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 351 | } |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 352 | if (global) { |
| 353 | if (result) { |
| 354 | this.lastIndex = lastMatchInfo[CAPTURE1]; |
| 355 | return true; |
| 356 | } else { |
| 357 | this.lastIndex = 0; |
| 358 | if (lastIndex !== 0) return false; |
| 359 | } |
| 360 | } |
| 361 | cache.type = 'test'; |
| 362 | cache.regExp = this; |
| 363 | cache.subject = s; |
| 364 | cache.answer = result; |
| 365 | return result; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 366 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 367 | |
| 368 | |
| 369 | function RegExpToString() { |
| 370 | // If this.source is an empty string, output /(?:)/. |
| 371 | // http://bugzilla.mozilla.org/show_bug.cgi?id=225550 |
| 372 | // ecma_2/RegExp/properties-001.js. |
| 373 | var src = this.source ? this.source : '(?:)'; |
| 374 | var result = '/' + src + '/'; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame^] | 375 | if (this.global) result += 'g'; |
| 376 | if (this.ignoreCase) result += 'i'; |
| 377 | if (this.multiline) result += 'm'; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 378 | return result; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 379 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 380 | |
| 381 | |
| 382 | // Getters for the static properties lastMatch, lastParen, leftContext, and |
| 383 | // rightContext of the RegExp constructor. The properties are computed based |
| 384 | // on the captures array of the last successful match and the subject string |
| 385 | // of the last successful match. |
| 386 | function RegExpGetLastMatch() { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 387 | if (lastMatchInfoOverride !== null) { |
| 388 | return lastMatchInfoOverride[0]; |
| 389 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 390 | var regExpSubject = LAST_SUBJECT(lastMatchInfo); |
| 391 | return SubString(regExpSubject, |
| 392 | lastMatchInfo[CAPTURE0], |
| 393 | lastMatchInfo[CAPTURE1]); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 394 | } |
| 395 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 396 | |
| 397 | function RegExpGetLastParen() { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 398 | if (lastMatchInfoOverride) { |
| 399 | var override = lastMatchInfoOverride; |
| 400 | if (override.length <= 3) return ''; |
| 401 | return override[override.length - 3]; |
| 402 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 403 | var length = NUMBER_OF_CAPTURES(lastMatchInfo); |
| 404 | if (length <= 2) return ''; // There were no captures. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 405 | // We match the SpiderMonkey behavior: return the substring defined by the |
| 406 | // last pair (after the first pair) of elements of the capture array even if |
| 407 | // it is empty. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 408 | var regExpSubject = LAST_SUBJECT(lastMatchInfo); |
| 409 | var start = lastMatchInfo[CAPTURE(length - 2)]; |
| 410 | var end = lastMatchInfo[CAPTURE(length - 1)]; |
| 411 | if (start != -1 && end != -1) { |
| 412 | return SubString(regExpSubject, start, end); |
| 413 | } |
| 414 | return ""; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 415 | } |
| 416 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 417 | |
| 418 | function RegExpGetLeftContext() { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 419 | var start_index; |
| 420 | var subject; |
| 421 | if (!lastMatchInfoOverride) { |
| 422 | start_index = lastMatchInfo[CAPTURE0]; |
| 423 | subject = LAST_SUBJECT(lastMatchInfo); |
| 424 | } else { |
| 425 | var override = lastMatchInfoOverride; |
| 426 | start_index = override[override.length - 2]; |
| 427 | subject = override[override.length - 1]; |
| 428 | } |
| 429 | return SubString(subject, 0, start_index); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 430 | } |
| 431 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 432 | |
| 433 | function RegExpGetRightContext() { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 434 | var start_index; |
| 435 | var subject; |
| 436 | if (!lastMatchInfoOverride) { |
| 437 | start_index = lastMatchInfo[CAPTURE1]; |
| 438 | subject = LAST_SUBJECT(lastMatchInfo); |
| 439 | } else { |
| 440 | var override = lastMatchInfoOverride; |
| 441 | subject = override[override.length - 1]; |
| 442 | start_index = override[override.length - 2] + subject.length; |
| 443 | } |
| 444 | return SubString(subject, start_index, subject.length); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 445 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 446 | |
| 447 | |
| 448 | // The properties $1..$9 are the first nine capturing substrings of the last |
| 449 | // successful match, or ''. The function RegExpMakeCaptureGetter will be |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 450 | // called with indices from 1 to 9. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 451 | function RegExpMakeCaptureGetter(n) { |
| 452 | return function() { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 453 | if (lastMatchInfoOverride) { |
| 454 | if (n < lastMatchInfoOverride.length - 2) return lastMatchInfoOverride[n]; |
| 455 | return ''; |
| 456 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 457 | var index = n * 2; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 458 | if (index >= NUMBER_OF_CAPTURES(lastMatchInfo)) return ''; |
| 459 | var matchStart = lastMatchInfo[CAPTURE(index)]; |
| 460 | var matchEnd = lastMatchInfo[CAPTURE(index + 1)]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 461 | if (matchStart == -1 || matchEnd == -1) return ''; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 462 | return SubString(LAST_SUBJECT(lastMatchInfo), matchStart, matchEnd); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 463 | }; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 464 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 465 | |
| 466 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 467 | // Property of the builtins object for recording the result of the last |
| 468 | // regexp match. The property lastMatchInfo includes the matchIndices |
| 469 | // array of the last successful regexp match (an array of start/end index |
| 470 | // pairs for the match and all the captured substrings), the invariant is |
| 471 | // that there are at least two capture indeces. The array also contains |
| 472 | // the subject string for the last successful match. |
| 473 | var lastMatchInfo = [ |
| 474 | 2, // REGEXP_NUMBER_OF_CAPTURES |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 475 | "", // Last subject. |
| 476 | void 0, // Last input - settable with RegExpSetInput. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 477 | 0, // REGEXP_FIRST_CAPTURE + 0 |
| 478 | 0, // REGEXP_FIRST_CAPTURE + 1 |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 479 | ]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 480 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 481 | // Override last match info with an array of actual substrings. |
| 482 | // Used internally by replace regexp with function. |
| 483 | // The array has the format of an "apply" argument for a replacement |
| 484 | // function. |
| 485 | var lastMatchInfoOverride = null; |
| 486 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 487 | // ------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 488 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 489 | function SetupRegExp() { |
| 490 | %FunctionSetInstanceClassName($RegExp, 'RegExp'); |
| 491 | %FunctionSetPrototype($RegExp, new $Object()); |
| 492 | %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); |
| 493 | %SetCode($RegExp, RegExpConstructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 494 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 495 | InstallFunctions($RegExp.prototype, DONT_ENUM, $Array( |
| 496 | "exec", RegExpExec, |
| 497 | "test", RegExpTest, |
| 498 | "toString", RegExpToString, |
| 499 | "compile", CompileRegExp |
| 500 | )); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 501 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 502 | // The length of compile is 1 in SpiderMonkey. |
| 503 | %FunctionSetLength($RegExp.prototype.compile, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 504 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 505 | // The properties input, $input, and $_ are aliases for each other. When this |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 506 | // value is set the value it is set to is coerced to a string. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 507 | // Getter and setter for the input. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 508 | function RegExpGetInput() { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 509 | var regExpInput = LAST_INPUT(lastMatchInfo); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 510 | return IS_UNDEFINED(regExpInput) ? "" : regExpInput; |
| 511 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 512 | function RegExpSetInput(string) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 513 | regExpCache.type = 'none'; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 514 | LAST_INPUT(lastMatchInfo) = ToString(string); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 515 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 516 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 517 | %DefineAccessor($RegExp, 'input', GETTER, RegExpGetInput, DONT_DELETE); |
| 518 | %DefineAccessor($RegExp, 'input', SETTER, RegExpSetInput, DONT_DELETE); |
| 519 | %DefineAccessor($RegExp, '$_', GETTER, RegExpGetInput, DONT_ENUM | DONT_DELETE); |
| 520 | %DefineAccessor($RegExp, '$_', SETTER, RegExpSetInput, DONT_ENUM | DONT_DELETE); |
| 521 | %DefineAccessor($RegExp, '$input', GETTER, RegExpGetInput, DONT_ENUM | DONT_DELETE); |
| 522 | %DefineAccessor($RegExp, '$input', SETTER, RegExpSetInput, DONT_ENUM | DONT_DELETE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 524 | // The properties multiline and $* are aliases for each other. When this |
| 525 | // value is set in SpiderMonkey, the value it is set to is coerced to a |
| 526 | // boolean. We mimic that behavior with a slight difference: in SpiderMonkey |
| 527 | // the value of the expression 'RegExp.multiline = null' (for instance) is the |
| 528 | // boolean false (ie, the value after coercion), while in V8 it is the value |
| 529 | // null (ie, the value before coercion). |
| 530 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | // Getter and setter for multiline. |
| 532 | var multiline = false; |
| 533 | function RegExpGetMultiline() { return multiline; }; |
| 534 | function RegExpSetMultiline(flag) { multiline = flag ? true : false; }; |
| 535 | |
| 536 | %DefineAccessor($RegExp, 'multiline', GETTER, RegExpGetMultiline, DONT_DELETE); |
| 537 | %DefineAccessor($RegExp, 'multiline', SETTER, RegExpSetMultiline, DONT_DELETE); |
| 538 | %DefineAccessor($RegExp, '$*', GETTER, RegExpGetMultiline, DONT_ENUM | DONT_DELETE); |
| 539 | %DefineAccessor($RegExp, '$*', SETTER, RegExpSetMultiline, DONT_ENUM | DONT_DELETE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | |
| 541 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 542 | function NoOpSetter(ignored) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | |
| 544 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 545 | // Static properties set by a successful match. |
| 546 | %DefineAccessor($RegExp, 'lastMatch', GETTER, RegExpGetLastMatch, DONT_DELETE); |
| 547 | %DefineAccessor($RegExp, 'lastMatch', SETTER, NoOpSetter, DONT_DELETE); |
| 548 | %DefineAccessor($RegExp, '$&', GETTER, RegExpGetLastMatch, DONT_ENUM | DONT_DELETE); |
| 549 | %DefineAccessor($RegExp, '$&', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 550 | %DefineAccessor($RegExp, 'lastParen', GETTER, RegExpGetLastParen, DONT_DELETE); |
| 551 | %DefineAccessor($RegExp, 'lastParen', SETTER, NoOpSetter, DONT_DELETE); |
| 552 | %DefineAccessor($RegExp, '$+', GETTER, RegExpGetLastParen, DONT_ENUM | DONT_DELETE); |
| 553 | %DefineAccessor($RegExp, '$+', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 554 | %DefineAccessor($RegExp, 'leftContext', GETTER, RegExpGetLeftContext, DONT_DELETE); |
| 555 | %DefineAccessor($RegExp, 'leftContext', SETTER, NoOpSetter, DONT_DELETE); |
| 556 | %DefineAccessor($RegExp, '$`', GETTER, RegExpGetLeftContext, DONT_ENUM | DONT_DELETE); |
| 557 | %DefineAccessor($RegExp, '$`', SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 558 | %DefineAccessor($RegExp, 'rightContext', GETTER, RegExpGetRightContext, DONT_DELETE); |
| 559 | %DefineAccessor($RegExp, 'rightContext', SETTER, NoOpSetter, DONT_DELETE); |
| 560 | %DefineAccessor($RegExp, "$'", GETTER, RegExpGetRightContext, DONT_ENUM | DONT_DELETE); |
| 561 | %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 563 | for (var i = 1; i < 10; ++i) { |
| 564 | %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_DELETE); |
| 565 | %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); |
| 566 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | |
| 570 | SetupRegExp(); |