OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
8 | 8 |
9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
10 // Imports | 10 // Imports |
11 | 11 |
12 var ArrayIndexOf; | 12 var ArrayIndexOf; |
13 var ArrayJoin; | 13 var ArrayJoin; |
14 var GlobalRegExp = global.RegExp; | 14 var GlobalRegExp = global.RegExp; |
15 var GlobalString = global.String; | 15 var GlobalString = global.String; |
16 var InternalArray = utils.InternalArray; | 16 var InternalArray = utils.InternalArray; |
17 var InternalPackedArray = utils.InternalPackedArray; | 17 var InternalPackedArray = utils.InternalPackedArray; |
18 var MakeRangeError; | 18 var MakeRangeError; |
19 var MakeTypeError; | 19 var MakeTypeError; |
20 var MathMax; | 20 var MathMax; |
21 var MathMin; | 21 var MathMin; |
| 22 var matchSymbol = utils.ImportNow("match_symbol"); |
22 var RegExpExec; | 23 var RegExpExec; |
23 var RegExpExecNoTests; | 24 var RegExpExecNoTests; |
24 var RegExpLastMatchInfo; | 25 var RegExpLastMatchInfo; |
25 var splitSymbol = utils.ImportNow("split_symbol"); | 26 var splitSymbol = utils.ImportNow("split_symbol"); |
26 | 27 |
27 utils.Import(function(from) { | 28 utils.Import(function(from) { |
28 ArrayIndexOf = from.ArrayIndexOf; | 29 ArrayIndexOf = from.ArrayIndexOf; |
29 ArrayJoin = from.ArrayJoin; | 30 ArrayJoin = from.ArrayJoin; |
30 MakeRangeError = from.MakeRangeError; | 31 MakeRangeError = from.MakeRangeError; |
31 MakeTypeError = from.MakeTypeError; | 32 MakeTypeError = from.MakeTypeError; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // This function is implementation specific. For now, we do not | 149 // This function is implementation specific. For now, we do not |
149 // do anything locale specific. | 150 // do anything locale specific. |
150 function StringLocaleCompareJS(other) { | 151 function StringLocaleCompareJS(other) { |
151 CHECK_OBJECT_COERCIBLE(this, "String.prototype.localeCompare"); | 152 CHECK_OBJECT_COERCIBLE(this, "String.prototype.localeCompare"); |
152 | 153 |
153 return %StringLocaleCompare(TO_STRING(this), TO_STRING(other)); | 154 return %StringLocaleCompare(TO_STRING(this), TO_STRING(other)); |
154 } | 155 } |
155 | 156 |
156 | 157 |
157 // ECMA-262 section 15.5.4.10 | 158 // ECMA-262 section 15.5.4.10 |
158 function StringMatchJS(regexp) { | 159 function StringMatchJS(pattern) { |
159 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); | 160 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); |
160 | 161 |
| 162 if (!IS_NULL_OR_UNDEFINED(pattern)) { |
| 163 var matcher = pattern[matchSymbol]; |
| 164 if (!IS_UNDEFINED(matcher)) { |
| 165 if (!IS_CALLABLE(matcher)) { |
| 166 throw MakeTypeError(kCalledNonCallable, matcher); |
| 167 } |
| 168 return %_Call(matcher, pattern, this); |
| 169 } |
| 170 } |
| 171 |
161 var subject = TO_STRING(this); | 172 var subject = TO_STRING(this); |
162 if (IS_REGEXP(regexp)) { | 173 |
163 if (!REGEXP_GLOBAL(regexp)) return RegExpExecNoTests(regexp, subject, 0); | |
164 var result = %StringMatch(subject, regexp, RegExpLastMatchInfo); | |
165 regexp.lastIndex = 0; | |
166 return result; | |
167 } | |
168 // Non-regexp argument. | 174 // Non-regexp argument. |
169 regexp = new GlobalRegExp(regexp); | 175 var regexp = new GlobalRegExp(pattern); |
170 return RegExpExecNoTests(regexp, subject, 0); | 176 return RegExpExecNoTests(regexp, subject, 0); |
171 } | 177 } |
172 | 178 |
173 | 179 |
174 // ECMA-262 v6, section 21.1.3.12 | 180 // ECMA-262 v6, section 21.1.3.12 |
175 // | 181 // |
176 // For now we do nothing, as proper normalization requires big tables. | 182 // For now we do nothing, as proper normalization requires big tables. |
177 // If Intl is enabled, then i18n.js will override it and provide the the | 183 // If Intl is enabled, then i18n.js will override it and provide the the |
178 // proper functionality. | 184 // proper functionality. |
179 function StringNormalizeJS() { | 185 function StringNormalizeJS() { |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 to.StringLastIndexOf = StringLastIndexOfJS; | 1109 to.StringLastIndexOf = StringLastIndexOfJS; |
1104 to.StringMatch = StringMatchJS; | 1110 to.StringMatch = StringMatchJS; |
1105 to.StringReplace = StringReplace; | 1111 to.StringReplace = StringReplace; |
1106 to.StringSlice = StringSlice; | 1112 to.StringSlice = StringSlice; |
1107 to.StringSplit = StringSplitJS; | 1113 to.StringSplit = StringSplitJS; |
1108 to.StringSubstr = StringSubstr; | 1114 to.StringSubstr = StringSubstr; |
1109 to.StringSubstring = StringSubstring; | 1115 to.StringSubstring = StringSubstring; |
1110 }); | 1116 }); |
1111 | 1117 |
1112 }) | 1118 }) |
OLD | NEW |