| 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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); | 39 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); |
| 40 var s = TO_STRING(this); | 40 var s = TO_STRING(this); |
| 41 var len = arguments.length; | 41 var len = arguments.length; |
| 42 for (var i = 0; i < len; ++i) { | 42 for (var i = 0; i < len; ++i) { |
| 43 s = s + TO_STRING(arguments[i]); | 43 s = s + TO_STRING(arguments[i]); |
| 44 } | 44 } |
| 45 return s; | 45 return s; |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 // ECMA-262 section 15.5.4.7 | |
| 50 function StringIndexOf(pattern, position) { // length == 1 | |
| 51 CHECK_OBJECT_COERCIBLE(this, "String.prototype.indexOf"); | |
| 52 | |
| 53 var subject = TO_STRING(this); | |
| 54 pattern = TO_STRING(pattern); | |
| 55 var index = TO_INTEGER(position); | |
| 56 if (index < 0) index = 0; | |
| 57 if (index > subject.length) index = subject.length; | |
| 58 return %StringIndexOf(subject, pattern, index); | |
| 59 } | |
| 60 | |
| 61 %FunctionSetLength(StringIndexOf, 1); | |
| 62 | |
| 63 | |
| 64 // ES6 21.1.3.11. | 49 // ES6 21.1.3.11. |
| 65 function StringMatchJS(pattern) { | 50 function StringMatchJS(pattern) { |
| 66 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); | 51 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); |
| 67 | 52 |
| 68 if (!IS_NULL_OR_UNDEFINED(pattern)) { | 53 if (!IS_NULL_OR_UNDEFINED(pattern)) { |
| 69 var matcher = pattern[matchSymbol]; | 54 var matcher = pattern[matchSymbol]; |
| 70 if (!IS_UNDEFINED(matcher)) { | 55 if (!IS_UNDEFINED(matcher)) { |
| 71 return %_Call(matcher, pattern, this); | 56 return %_Call(matcher, pattern, this); |
| 72 } | 57 } |
| 73 } | 58 } |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 utils.InstallFunctions(GlobalString, DONT_ENUM, [ | 513 utils.InstallFunctions(GlobalString, DONT_ENUM, [ |
| 529 "raw", StringRaw | 514 "raw", StringRaw |
| 530 ]); | 515 ]); |
| 531 | 516 |
| 532 // Set up the non-enumerable functions on the String prototype object. | 517 // Set up the non-enumerable functions on the String prototype object. |
| 533 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ | 518 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ |
| 534 "codePointAt", StringCodePointAt, | 519 "codePointAt", StringCodePointAt, |
| 535 "concat", StringConcat, | 520 "concat", StringConcat, |
| 536 "endsWith", StringEndsWith, | 521 "endsWith", StringEndsWith, |
| 537 "includes", StringIncludes, | 522 "includes", StringIncludes, |
| 538 "indexOf", StringIndexOf, | |
| 539 "match", StringMatchJS, | 523 "match", StringMatchJS, |
| 540 "repeat", StringRepeat, | 524 "repeat", StringRepeat, |
| 541 "replace", StringReplace, | 525 "replace", StringReplace, |
| 542 "search", StringSearch, | 526 "search", StringSearch, |
| 543 "slice", StringSlice, | 527 "slice", StringSlice, |
| 544 "split", StringSplitJS, | 528 "split", StringSplitJS, |
| 545 "startsWith", StringStartsWith, | 529 "startsWith", StringStartsWith, |
| 546 "toLowerCase", StringToLowerCaseJS, | 530 "toLowerCase", StringToLowerCaseJS, |
| 547 "toLocaleLowerCase", StringToLocaleLowerCase, | 531 "toLocaleLowerCase", StringToLocaleLowerCase, |
| 548 "toUpperCase", StringToUpperCaseJS, | 532 "toUpperCase", StringToUpperCaseJS, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 560 "small", StringSmall, | 544 "small", StringSmall, |
| 561 "strike", StringStrike, | 545 "strike", StringStrike, |
| 562 "sub", StringSub, | 546 "sub", StringSub, |
| 563 "sup", StringSup | 547 "sup", StringSup |
| 564 ]); | 548 ]); |
| 565 | 549 |
| 566 // ------------------------------------------------------------------- | 550 // ------------------------------------------------------------------- |
| 567 // Exports | 551 // Exports |
| 568 | 552 |
| 569 utils.Export(function(to) { | 553 utils.Export(function(to) { |
| 570 to.StringIndexOf = StringIndexOf; | |
| 571 to.StringMatch = StringMatchJS; | 554 to.StringMatch = StringMatchJS; |
| 572 to.StringReplace = StringReplace; | 555 to.StringReplace = StringReplace; |
| 573 to.StringSlice = StringSlice; | 556 to.StringSlice = StringSlice; |
| 574 to.StringSplit = StringSplitJS; | 557 to.StringSplit = StringSplitJS; |
| 575 }); | 558 }); |
| 576 | 559 |
| 577 }) | 560 }) |
| OLD | NEW |