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 IsRegExp; | 18 var IsRegExp; |
19 var MakeRangeError; | 19 var MakeRangeError; |
20 var MakeTypeError; | 20 var MakeTypeError; |
21 var MaxSimple; | 21 var MaxSimple; |
22 var MinSimple; | 22 var MinSimple; |
| 23 var RegExpInitialize; |
23 var matchSymbol = utils.ImportNow("match_symbol"); | 24 var matchSymbol = utils.ImportNow("match_symbol"); |
24 var replaceSymbol = utils.ImportNow("replace_symbol"); | 25 var replaceSymbol = utils.ImportNow("replace_symbol"); |
25 var searchSymbol = utils.ImportNow("search_symbol"); | 26 var searchSymbol = utils.ImportNow("search_symbol"); |
26 var splitSymbol = utils.ImportNow("split_symbol"); | 27 var splitSymbol = utils.ImportNow("split_symbol"); |
27 | 28 |
28 utils.Import(function(from) { | 29 utils.Import(function(from) { |
29 ArrayIndexOf = from.ArrayIndexOf; | 30 ArrayIndexOf = from.ArrayIndexOf; |
30 ArrayJoin = from.ArrayJoin; | 31 ArrayJoin = from.ArrayJoin; |
31 IsRegExp = from.IsRegExp; | 32 IsRegExp = from.IsRegExp; |
32 MakeRangeError = from.MakeRangeError; | 33 MakeRangeError = from.MakeRangeError; |
33 MakeTypeError = from.MakeTypeError; | 34 MakeTypeError = from.MakeTypeError; |
34 MaxSimple = from.MaxSimple; | 35 MaxSimple = from.MaxSimple; |
35 MinSimple = from.MinSimple; | 36 MinSimple = from.MinSimple; |
| 37 RegExpInitialize = from.RegExpInitialize; |
36 }); | 38 }); |
37 | 39 |
38 //------------------------------------------------------------------- | 40 //------------------------------------------------------------------- |
39 | 41 |
40 // ECMA-262 section 15.5.4.2 | 42 // ECMA-262 section 15.5.4.2 |
41 function StringToString() { | 43 function StringToString() { |
42 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { | 44 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { |
43 throw MakeTypeError(kNotGeneric, 'String.prototype.toString'); | 45 throw MakeTypeError(kNotGeneric, 'String.prototype.toString'); |
44 } | 46 } |
45 return %_ValueOf(this); | 47 return %_ValueOf(this); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 154 |
153 if (!IS_NULL_OR_UNDEFINED(pattern)) { | 155 if (!IS_NULL_OR_UNDEFINED(pattern)) { |
154 var matcher = pattern[matchSymbol]; | 156 var matcher = pattern[matchSymbol]; |
155 if (!IS_UNDEFINED(matcher)) { | 157 if (!IS_UNDEFINED(matcher)) { |
156 return %_Call(matcher, pattern, this); | 158 return %_Call(matcher, pattern, this); |
157 } | 159 } |
158 } | 160 } |
159 | 161 |
160 var subject = TO_STRING(this); | 162 var subject = TO_STRING(this); |
161 | 163 |
162 // Non-regexp argument. | 164 // Equivalent to RegExpCreate (ES#sec-regexpcreate) |
163 var regexp = new GlobalRegExp(pattern); | 165 var regexp = %NewObject(GlobalRegExp, GlobalRegExp); |
| 166 RegExpInitialize(regexp, pattern); |
164 return regexp[matchSymbol](subject); | 167 return regexp[matchSymbol](subject); |
165 } | 168 } |
166 | 169 |
167 | 170 |
168 // ECMA-262 v6, section 21.1.3.12 | 171 // ECMA-262 v6, section 21.1.3.12 |
169 // | 172 // |
170 // For now we do nothing, as proper normalization requires big tables. | 173 // For now we do nothing, as proper normalization requires big tables. |
171 // If Intl is enabled, then i18n.js will override it and provide the the | 174 // If Intl is enabled, then i18n.js will override it and provide the the |
172 // proper functionality. | 175 // proper functionality. |
173 function StringNormalize(formArg) { // length == 0 | 176 function StringNormalize(formArg) { // length == 0 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 CHECK_OBJECT_COERCIBLE(this, "String.prototype.search"); | 351 CHECK_OBJECT_COERCIBLE(this, "String.prototype.search"); |
349 | 352 |
350 if (!IS_NULL_OR_UNDEFINED(pattern)) { | 353 if (!IS_NULL_OR_UNDEFINED(pattern)) { |
351 var searcher = pattern[searchSymbol]; | 354 var searcher = pattern[searchSymbol]; |
352 if (!IS_UNDEFINED(searcher)) { | 355 if (!IS_UNDEFINED(searcher)) { |
353 return %_Call(searcher, pattern, this); | 356 return %_Call(searcher, pattern, this); |
354 } | 357 } |
355 } | 358 } |
356 | 359 |
357 var subject = TO_STRING(this); | 360 var subject = TO_STRING(this); |
358 var regexp = new GlobalRegExp(pattern); | 361 |
| 362 // Equivalent to RegExpCreate (ES#sec-regexpcreate) |
| 363 var regexp = %NewObject(GlobalRegExp, GlobalRegExp); |
| 364 RegExpInitialize(regexp, pattern); |
359 return %_Call(regexp[searchSymbol], regexp, subject); | 365 return %_Call(regexp[searchSymbol], regexp, subject); |
360 } | 366 } |
361 | 367 |
362 | 368 |
363 // ECMA-262 section 15.5.4.13 | 369 // ECMA-262 section 15.5.4.13 |
364 function StringSlice(start, end) { | 370 function StringSlice(start, end) { |
365 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice"); | 371 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice"); |
366 | 372 |
367 var s = TO_STRING(this); | 373 var s = TO_STRING(this); |
368 var s_len = s.length; | 374 var s_len = s.length; |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 to.StringLastIndexOf = StringLastIndexOf; | 927 to.StringLastIndexOf = StringLastIndexOf; |
922 to.StringMatch = StringMatchJS; | 928 to.StringMatch = StringMatchJS; |
923 to.StringReplace = StringReplace; | 929 to.StringReplace = StringReplace; |
924 to.StringSlice = StringSlice; | 930 to.StringSlice = StringSlice; |
925 to.StringSplit = StringSplitJS; | 931 to.StringSplit = StringSplitJS; |
926 to.StringSubstr = StringSubstr; | 932 to.StringSubstr = StringSubstr; |
927 to.StringSubstring = StringSubstring; | 933 to.StringSubstring = StringSubstring; |
928 }); | 934 }); |
929 | 935 |
930 }) | 936 }) |
OLD | NEW |