erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 1 | // Copyright 2012 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 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 28 | // This file relies on the fact that the following declaration has been made |
| 29 | // in runtime.js: |
| 30 | // var $Object = global.Object; |
| 31 | // var $Array = global.Array; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 33 | var $RegExp = global.RegExp; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 35 | // ------------------------------------------------------------------- |
| 36 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | // A recursive descent parser for Patterns according to the grammar of |
| 38 | // ECMA-262 15.10.1, with deviations noted below. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 39 | function DoConstructRegExp(object, pattern, flags) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | // RegExp : Called as constructor; see ECMA-262, section 15.10.4. |
| 41 | if (IS_REGEXP(pattern)) { |
| 42 | if (!IS_UNDEFINED(flags)) { |
| 43 | throw MakeTypeError('regexp_flags', []); |
| 44 | } |
| 45 | flags = (pattern.global ? 'g' : '') |
| 46 | + (pattern.ignoreCase ? 'i' : '') |
| 47 | + (pattern.multiline ? 'm' : ''); |
| 48 | pattern = pattern.source; |
| 49 | } |
| 50 | |
| 51 | pattern = IS_UNDEFINED(pattern) ? '' : ToString(pattern); |
| 52 | flags = IS_UNDEFINED(flags) ? '' : ToString(flags); |
| 53 | |
| 54 | var global = false; |
| 55 | var ignoreCase = false; |
| 56 | var multiline = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | for (var i = 0; i < flags.length; i++) { |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 58 | var c = %_CallFunction(flags, i, StringCharAt); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 59 | switch (c) { |
| 60 | case 'g': |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 61 | if (global) { |
| 62 | throw MakeSyntaxError("invalid_regexp_flags", [flags]); |
| 63 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | global = true; |
| 65 | break; |
| 66 | case 'i': |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 67 | if (ignoreCase) { |
| 68 | throw MakeSyntaxError("invalid_regexp_flags", [flags]); |
| 69 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | ignoreCase = true; |
| 71 | break; |
| 72 | case 'm': |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 73 | if (multiline) { |
| 74 | throw MakeSyntaxError("invalid_regexp_flags", [flags]); |
| 75 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | multiline = true; |
| 77 | break; |
| 78 | default: |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 79 | throw MakeSyntaxError("invalid_regexp_flags", [flags]); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 83 | %RegExpInitializeObject(object, pattern, global, ignoreCase, multiline); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 84 | |
| 85 | // Call internal function to compile the pattern. |
| 86 | %RegExpCompile(object, pattern, flags); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 87 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | |
| 89 | |
| 90 | function RegExpConstructor(pattern, flags) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 91 | if (%_IsConstructCall()) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 92 | DoConstructRegExp(this, pattern, flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 93 | } else { |
| 94 | // RegExp : Called as function; see ECMA-262, section 15.10.3.1. |
| 95 | if (IS_REGEXP(pattern) && IS_UNDEFINED(flags)) { |
| 96 | return pattern; |
| 97 | } |
| 98 | return new $RegExp(pattern, flags); |
| 99 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 100 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 102 | // Deprecated RegExp.prototype.compile method. We behave like the constructor |
| 103 | // were called again. In SpiderMonkey, this method returns the regexp object. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 104 | // 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] | 105 | // behavior. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 106 | function RegExpCompile(pattern, flags) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 107 | // Both JSC and SpiderMonkey treat a missing pattern argument as the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 108 | // empty subject string, and an actual undefined value passed as the |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 109 | // pattern as the string 'undefined'. Note that JSC is inconsistent |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | // here, treating undefined values differently in |
| 111 | // RegExp.prototype.compile and in the constructor, where they are |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 112 | // the empty string. For compatibility with JSC, we match their |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | // behavior. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 114 | if (this == $RegExp.prototype) { |
| 115 | // We don't allow recompiling RegExp.prototype. |
| 116 | throw MakeTypeError('incompatible_method_receiver', |
| 117 | ['RegExp.prototype.compile', this]); |
| 118 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | if (IS_UNDEFINED(pattern) && %_ArgumentsLength() != 0) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 120 | DoConstructRegExp(this, 'undefined', flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 121 | } else { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 122 | DoConstructRegExp(this, pattern, flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
| 126 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | function DoRegExpExec(regexp, string, index) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 128 | var result = %_RegExpExec(regexp, string, index, lastMatchInfo); |
| 129 | if (result !== null) lastMatchInfoOverride = null; |
| 130 | return result; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 131 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 132 | |
| 133 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 134 | function BuildResultFromMatchInfo(lastMatchInfo, s) { |
| 135 | var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 136 | var start = lastMatchInfo[CAPTURE0]; |
| 137 | var end = lastMatchInfo[CAPTURE1]; |
| 138 | var result = %_RegExpConstructResult(numResults, start, s); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 139 | result[0] = %_SubString(s, start, end); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 140 | var j = REGEXP_FIRST_CAPTURE + 2; |
| 141 | for (var i = 1; i < numResults; i++) { |
| 142 | start = lastMatchInfo[j++]; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 143 | if (start != -1) { |
| 144 | end = lastMatchInfo[j]; |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 145 | result[i] = %_SubString(s, start, end); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 146 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 147 | j++; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 148 | } |
| 149 | return result; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | function RegExpExecNoTests(regexp, string, start) { |
| 154 | // Must be called with RegExp, string and positive integer as arguments. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 155 | var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 156 | if (matchInfo !== null) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 157 | lastMatchInfoOverride = null; |
| 158 | return BuildResultFromMatchInfo(matchInfo, string); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 159 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 160 | regexp.lastIndex = 0; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 161 | return null; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 165 | function RegExpExec(string) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 166 | if (!IS_REGEXP(this)) { |
| 167 | throw MakeTypeError('incompatible_method_receiver', |
| 168 | ['RegExp.prototype.exec', this]); |
| 169 | } |
| 170 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 171 | string = TO_STRING_INLINE(string); |
lrn@chromium.org | fa943b7 | 2010-11-03 08:14:36 +0000 | [diff] [blame] | 172 | var lastIndex = this.lastIndex; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 173 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 174 | // Conversion is required by the ES5 specification (RegExp.prototype.exec |
| 175 | // algorithm, step 5) even if the value is discarded for non-global RegExps. |
| 176 | var i = TO_INTEGER(lastIndex); |
lrn@chromium.org | fa943b7 | 2010-11-03 08:14:36 +0000 | [diff] [blame] | 177 | |
| 178 | var global = this.global; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 179 | if (global) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 180 | if (i < 0 || i > string.length) { |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 181 | this.lastIndex = 0; |
| 182 | return null; |
| 183 | } |
| 184 | } else { |
| 185 | i = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 186 | } |
| 187 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 188 | %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 189 | // matchIndices is either null or the lastMatchInfo array. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 190 | var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 191 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 192 | if (matchIndices === null) { |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 193 | this.lastIndex = 0; |
lrn@chromium.org | fa943b7 | 2010-11-03 08:14:36 +0000 | [diff] [blame] | 194 | return null; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 195 | } |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 196 | |
| 197 | // Successful match. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 198 | lastMatchInfoOverride = null; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 199 | if (global) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 200 | this.lastIndex = lastMatchInfo[CAPTURE1]; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 201 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 202 | return BuildResultFromMatchInfo(matchIndices, string); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 203 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | |
| 205 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 206 | // One-element cache for the simplified test regexp. |
| 207 | var regexp_key; |
| 208 | var regexp_val; |
| 209 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 210 | // 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] | 211 | // that test is defined in terms of String.prototype.exec. However, it probably |
| 212 | // means the original value of String.prototype.exec, which is what everybody |
| 213 | // else implements. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 214 | function RegExpTest(string) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 215 | if (!IS_REGEXP(this)) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 216 | throw MakeTypeError('incompatible_method_receiver', |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 217 | ['RegExp.prototype.test', this]); |
| 218 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 219 | string = TO_STRING_INLINE(string); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 220 | |
lrn@chromium.org | fa943b7 | 2010-11-03 08:14:36 +0000 | [diff] [blame] | 221 | var lastIndex = this.lastIndex; |
| 222 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 223 | // Conversion is required by the ES5 specification (RegExp.prototype.exec |
| 224 | // algorithm, step 5) even if the value is discarded for non-global RegExps. |
| 225 | var i = TO_INTEGER(lastIndex); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 226 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 227 | if (this.global) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 228 | if (i < 0 || i > string.length) { |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 229 | this.lastIndex = 0; |
| 230 | return false; |
| 231 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 232 | %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 233 | // matchIndices is either null or the lastMatchInfo array. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 234 | var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 235 | if (matchIndices === null) { |
| 236 | this.lastIndex = 0; |
| 237 | return false; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 238 | } |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 239 | lastMatchInfoOverride = null; |
| 240 | this.lastIndex = lastMatchInfo[CAPTURE1]; |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 241 | return true; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 242 | } else { |
| 243 | // Non-global regexp. |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 244 | // Remove irrelevant preceeding '.*' in a non-global test regexp. |
| 245 | // The expression checks whether this.source starts with '.*' and |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 246 | // that the third char is not a '?'. |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 247 | var regexp = this; |
| 248 | if (%_StringCharCodeAt(regexp.source, 0) == 46 && // '.' |
| 249 | %_StringCharCodeAt(regexp.source, 1) == 42 && // '*' |
| 250 | %_StringCharCodeAt(regexp.source, 2) != 63) { // '?' |
| 251 | regexp = TrimRegExp(regexp); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 252 | } |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 253 | %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [regexp, string, lastIndex]); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 254 | // matchIndices is either null or the lastMatchInfo array. |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 255 | var matchIndices = %_RegExpExec(regexp, string, 0, lastMatchInfo); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 256 | if (matchIndices === null) { |
| 257 | this.lastIndex = 0; |
| 258 | return false; |
| 259 | } |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 260 | lastMatchInfoOverride = null; |
| 261 | return true; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 262 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 263 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 264 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 265 | function TrimRegExp(regexp) { |
| 266 | if (!%_ObjectEquals(regexp_key, regexp)) { |
| 267 | regexp_key = regexp; |
| 268 | regexp_val = |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 269 | new $RegExp(%_SubString(regexp.source, 2, regexp.source.length), |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 270 | (regexp.ignoreCase ? regexp.multiline ? "im" : "i" |
| 271 | : regexp.multiline ? "m" : "")); |
| 272 | } |
| 273 | return regexp_val; |
| 274 | } |
| 275 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | |
| 277 | function RegExpToString() { |
jkummerow@chromium.org | 777db6f | 2012-05-24 09:33:09 +0000 | [diff] [blame] | 278 | if (!IS_REGEXP(this)) { |
| 279 | throw MakeTypeError('incompatible_method_receiver', |
| 280 | ['RegExp.prototype.toString', this]); |
| 281 | } |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 282 | var result = '/' + this.source + '/'; |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 283 | if (this.global) result += 'g'; |
| 284 | if (this.ignoreCase) result += 'i'; |
| 285 | if (this.multiline) result += 'm'; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | return result; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 287 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 288 | |
| 289 | |
| 290 | // Getters for the static properties lastMatch, lastParen, leftContext, and |
| 291 | // rightContext of the RegExp constructor. The properties are computed based |
| 292 | // on the captures array of the last successful match and the subject string |
| 293 | // of the last successful match. |
| 294 | function RegExpGetLastMatch() { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 295 | if (lastMatchInfoOverride !== null) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 296 | return OVERRIDE_MATCH(lastMatchInfoOverride); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 297 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 298 | var regExpSubject = LAST_SUBJECT(lastMatchInfo); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 299 | return %_SubString(regExpSubject, |
| 300 | lastMatchInfo[CAPTURE0], |
| 301 | lastMatchInfo[CAPTURE1]); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 302 | } |
| 303 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | |
| 305 | function RegExpGetLastParen() { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 306 | if (lastMatchInfoOverride) { |
| 307 | var override = lastMatchInfoOverride; |
| 308 | if (override.length <= 3) return ''; |
| 309 | return override[override.length - 3]; |
| 310 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 311 | var length = NUMBER_OF_CAPTURES(lastMatchInfo); |
| 312 | if (length <= 2) return ''; // There were no captures. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 313 | // We match the SpiderMonkey behavior: return the substring defined by the |
| 314 | // last pair (after the first pair) of elements of the capture array even if |
| 315 | // it is empty. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 316 | var regExpSubject = LAST_SUBJECT(lastMatchInfo); |
| 317 | var start = lastMatchInfo[CAPTURE(length - 2)]; |
| 318 | var end = lastMatchInfo[CAPTURE(length - 1)]; |
| 319 | if (start != -1 && end != -1) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 320 | return %_SubString(regExpSubject, start, end); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 321 | } |
| 322 | return ""; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 323 | } |
| 324 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 325 | |
| 326 | function RegExpGetLeftContext() { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 327 | var start_index; |
| 328 | var subject; |
| 329 | if (!lastMatchInfoOverride) { |
| 330 | start_index = lastMatchInfo[CAPTURE0]; |
| 331 | subject = LAST_SUBJECT(lastMatchInfo); |
| 332 | } else { |
| 333 | var override = lastMatchInfoOverride; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 334 | start_index = OVERRIDE_POS(override); |
| 335 | subject = OVERRIDE_SUBJECT(override); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 336 | } |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 337 | return %_SubString(subject, 0, start_index); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 338 | } |
| 339 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 340 | |
| 341 | function RegExpGetRightContext() { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 342 | var start_index; |
| 343 | var subject; |
| 344 | if (!lastMatchInfoOverride) { |
| 345 | start_index = lastMatchInfo[CAPTURE1]; |
| 346 | subject = LAST_SUBJECT(lastMatchInfo); |
| 347 | } else { |
| 348 | var override = lastMatchInfoOverride; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 349 | subject = OVERRIDE_SUBJECT(override); |
| 350 | var match = OVERRIDE_MATCH(override); |
| 351 | start_index = OVERRIDE_POS(override) + match.length; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 352 | } |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 353 | return %_SubString(subject, start_index, subject.length); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 354 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 355 | |
| 356 | |
| 357 | // The properties $1..$9 are the first nine capturing substrings of the last |
| 358 | // successful match, or ''. The function RegExpMakeCaptureGetter will be |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 359 | // called with indices from 1 to 9. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 360 | function RegExpMakeCaptureGetter(n) { |
| 361 | return function() { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 362 | if (lastMatchInfoOverride) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 363 | if (n < lastMatchInfoOverride.length - 2) { |
| 364 | return OVERRIDE_CAPTURE(lastMatchInfoOverride, n); |
| 365 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 366 | return ''; |
| 367 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 368 | var index = n * 2; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 369 | if (index >= NUMBER_OF_CAPTURES(lastMatchInfo)) return ''; |
| 370 | var matchStart = lastMatchInfo[CAPTURE(index)]; |
| 371 | var matchEnd = lastMatchInfo[CAPTURE(index + 1)]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 372 | if (matchStart == -1 || matchEnd == -1) return ''; |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 373 | return %_SubString(LAST_SUBJECT(lastMatchInfo), matchStart, matchEnd); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 374 | }; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 375 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 376 | |
| 377 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 378 | // Property of the builtins object for recording the result of the last |
| 379 | // regexp match. The property lastMatchInfo includes the matchIndices |
| 380 | // array of the last successful regexp match (an array of start/end index |
| 381 | // pairs for the match and all the captured substrings), the invariant is |
| 382 | // that there are at least two capture indeces. The array also contains |
| 383 | // the subject string for the last successful match. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 384 | var lastMatchInfo = new InternalPackedArray( |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 385 | 2, // REGEXP_NUMBER_OF_CAPTURES |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 386 | "", // Last subject. |
| 387 | void 0, // Last input - settable with RegExpSetInput. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 388 | 0, // REGEXP_FIRST_CAPTURE + 0 |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 389 | 0 // REGEXP_FIRST_CAPTURE + 1 |
| 390 | ); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 391 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 392 | // Override last match info with an array of actual substrings. |
| 393 | // Used internally by replace regexp with function. |
| 394 | // The array has the format of an "apply" argument for a replacement |
| 395 | // function. |
| 396 | var lastMatchInfoOverride = null; |
| 397 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 398 | // ------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 399 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 400 | function SetUpRegExp() { |
| 401 | %CheckIsBootstrapping(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 402 | %FunctionSetInstanceClassName($RegExp, 'RegExp'); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 403 | %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); |
| 404 | %SetCode($RegExp, RegExpConstructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 405 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 406 | InstallFunctions($RegExp.prototype, DONT_ENUM, $Array( |
| 407 | "exec", RegExpExec, |
| 408 | "test", RegExpTest, |
| 409 | "toString", RegExpToString, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 410 | "compile", RegExpCompile |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 411 | )); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 412 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 413 | // The length of compile is 1 in SpiderMonkey. |
| 414 | %FunctionSetLength($RegExp.prototype.compile, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 415 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 416 | // 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] | 417 | // 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] | 418 | // Getter and setter for the input. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 419 | var RegExpGetInput = function() { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 420 | var regExpInput = LAST_INPUT(lastMatchInfo); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 421 | return IS_UNDEFINED(regExpInput) ? "" : regExpInput; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 422 | }; |
| 423 | var RegExpSetInput = function(string) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 424 | LAST_INPUT(lastMatchInfo) = ToString(string); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 425 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 426 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 427 | %OptimizeObjectForAddingMultipleProperties($RegExp, 22); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 428 | %DefineOrRedefineAccessorProperty($RegExp, 'input', RegExpGetInput, |
| 429 | RegExpSetInput, DONT_DELETE); |
| 430 | %DefineOrRedefineAccessorProperty($RegExp, '$_', RegExpGetInput, |
| 431 | RegExpSetInput, DONT_ENUM | DONT_DELETE); |
| 432 | %DefineOrRedefineAccessorProperty($RegExp, '$input', RegExpGetInput, |
| 433 | RegExpSetInput, DONT_ENUM | DONT_DELETE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 434 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 435 | // The properties multiline and $* are aliases for each other. When this |
| 436 | // value is set in SpiderMonkey, the value it is set to is coerced to a |
| 437 | // boolean. We mimic that behavior with a slight difference: in SpiderMonkey |
| 438 | // the value of the expression 'RegExp.multiline = null' (for instance) is the |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 439 | // boolean false (i.e., the value after coercion), while in V8 it is the value |
| 440 | // null (i.e., the value before coercion). |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 441 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 442 | // Getter and setter for multiline. |
| 443 | var multiline = false; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 444 | var RegExpGetMultiline = function() { return multiline; }; |
| 445 | var RegExpSetMultiline = function(flag) { multiline = flag ? true : false; }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 446 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 447 | %DefineOrRedefineAccessorProperty($RegExp, 'multiline', RegExpGetMultiline, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 448 | RegExpSetMultiline, DONT_DELETE); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 449 | %DefineOrRedefineAccessorProperty($RegExp, '$*', RegExpGetMultiline, |
| 450 | RegExpSetMultiline, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 451 | DONT_ENUM | DONT_DELETE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 452 | |
| 453 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 454 | var NoOpSetter = function(ignored) {}; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | |
| 456 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 457 | // Static properties set by a successful match. |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 458 | %DefineOrRedefineAccessorProperty($RegExp, 'lastMatch', RegExpGetLastMatch, |
| 459 | NoOpSetter, DONT_DELETE); |
| 460 | %DefineOrRedefineAccessorProperty($RegExp, '$&', RegExpGetLastMatch, |
| 461 | NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 462 | %DefineOrRedefineAccessorProperty($RegExp, 'lastParen', RegExpGetLastParen, |
| 463 | NoOpSetter, DONT_DELETE); |
| 464 | %DefineOrRedefineAccessorProperty($RegExp, '$+', RegExpGetLastParen, |
| 465 | NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 466 | %DefineOrRedefineAccessorProperty($RegExp, 'leftContext', |
| 467 | RegExpGetLeftContext, NoOpSetter, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 468 | DONT_DELETE); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 469 | %DefineOrRedefineAccessorProperty($RegExp, '$`', RegExpGetLeftContext, |
| 470 | NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 471 | %DefineOrRedefineAccessorProperty($RegExp, 'rightContext', |
| 472 | RegExpGetRightContext, NoOpSetter, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 473 | DONT_DELETE); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 474 | %DefineOrRedefineAccessorProperty($RegExp, "$'", RegExpGetRightContext, |
| 475 | NoOpSetter, DONT_ENUM | DONT_DELETE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 476 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 477 | for (var i = 1; i < 10; ++i) { |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 478 | %DefineOrRedefineAccessorProperty($RegExp, '$' + i, |
| 479 | RegExpMakeCaptureGetter(i), NoOpSetter, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 480 | DONT_DELETE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 481 | } |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 482 | %ToFastProperties($RegExp); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 483 | } |
| 484 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 485 | SetUpRegExp(); |