| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // This file relies on the fact that the following declaration has been made | 28 // This file relies on the fact that the following declaration has been made |
| 29 // in runtime.js: | 29 // in runtime.js: |
| 30 // var $String = global.String; | 30 // var $String = global.String; |
| 31 // var $NaN = 0/0; | |
| 32 | 31 |
| 33 // ------------------------------------------------------------------- | 32 // ------------------------------------------------------------------- |
| 34 | 33 |
| 35 function StringConstructor(x) { | 34 function StringConstructor(x) { |
| 36 var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x); | 35 var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x); |
| 37 if (%_IsConstructCall()) { | 36 if (%_IsConstructCall()) { |
| 38 %_SetValueOf(this, value); | 37 %_SetValueOf(this, value); |
| 39 } else { | 38 } else { |
| 40 return value; | 39 return value; |
| 41 } | 40 } |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 // ECMA-262 section 15.5.4.13 | 566 // ECMA-262 section 15.5.4.13 |
| 568 function StringSlice(start, end) { | 567 function StringSlice(start, end) { |
| 569 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 568 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 570 throw MakeTypeError("called_on_null_or_undefined", | 569 throw MakeTypeError("called_on_null_or_undefined", |
| 571 ["String.prototype.slice"]); | 570 ["String.prototype.slice"]); |
| 572 } | 571 } |
| 573 var s = TO_STRING_INLINE(this); | 572 var s = TO_STRING_INLINE(this); |
| 574 var s_len = s.length; | 573 var s_len = s.length; |
| 575 var start_i = TO_INTEGER(start); | 574 var start_i = TO_INTEGER(start); |
| 576 var end_i = s_len; | 575 var end_i = s_len; |
| 577 if (end !== void 0) { | 576 if (!IS_UNDEFINED(end)) { |
| 578 end_i = TO_INTEGER(end); | 577 end_i = TO_INTEGER(end); |
| 579 } | 578 } |
| 580 | 579 |
| 581 if (start_i < 0) { | 580 if (start_i < 0) { |
| 582 start_i += s_len; | 581 start_i += s_len; |
| 583 if (start_i < 0) { | 582 if (start_i < 0) { |
| 584 start_i = 0; | 583 start_i = 0; |
| 585 } | 584 } |
| 586 } else { | 585 } else { |
| 587 if (start_i > s_len) { | 586 if (start_i > s_len) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 if (result.length === limit) break; | 691 if (result.length === limit) break; |
| 693 | 692 |
| 694 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE; | 693 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE; |
| 695 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) { | 694 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) { |
| 696 var start = matchInfo[i++]; | 695 var start = matchInfo[i++]; |
| 697 var end = matchInfo[i++]; | 696 var end = matchInfo[i++]; |
| 698 if (end != -1) { | 697 if (end != -1) { |
| 699 %_CallFunction(result, %_SubString(subject, start, end), | 698 %_CallFunction(result, %_SubString(subject, start, end), |
| 700 ArrayPushBuiltin); | 699 ArrayPushBuiltin); |
| 701 } else { | 700 } else { |
| 702 %_CallFunction(result, void 0, ArrayPushBuiltin); | 701 %_CallFunction(result, UNDEFINED, ArrayPushBuiltin); |
| 703 } | 702 } |
| 704 if (result.length === limit) break outer_loop; | 703 if (result.length === limit) break outer_loop; |
| 705 } | 704 } |
| 706 | 705 |
| 707 startIndex = currentIndex = endIndex; | 706 startIndex = currentIndex = endIndex; |
| 708 } | 707 } |
| 709 return result; | 708 return result; |
| 710 } | 709 } |
| 711 | 710 |
| 712 | 711 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 function StringSubstr(start, n) { | 748 function StringSubstr(start, n) { |
| 750 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 749 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 751 throw MakeTypeError("called_on_null_or_undefined", | 750 throw MakeTypeError("called_on_null_or_undefined", |
| 752 ["String.prototype.substr"]); | 751 ["String.prototype.substr"]); |
| 753 } | 752 } |
| 754 var s = TO_STRING_INLINE(this); | 753 var s = TO_STRING_INLINE(this); |
| 755 var len; | 754 var len; |
| 756 | 755 |
| 757 // Correct n: If not given, set to string length; if explicitly | 756 // Correct n: If not given, set to string length; if explicitly |
| 758 // set to undefined, zero, or negative, returns empty string. | 757 // set to undefined, zero, or negative, returns empty string. |
| 759 if (n === void 0) { | 758 if (IS_UNDEFINED(n)) { |
| 760 len = s.length; | 759 len = s.length; |
| 761 } else { | 760 } else { |
| 762 len = TO_INTEGER(n); | 761 len = TO_INTEGER(n); |
| 763 if (len <= 0) return ''; | 762 if (len <= 0) return ''; |
| 764 } | 763 } |
| 765 | 764 |
| 766 // Correct start: If not given (or undefined), set to zero; otherwise | 765 // Correct start: If not given (or undefined), set to zero; otherwise |
| 767 // convert to integer and handle negative case. | 766 // convert to integer and handle negative case. |
| 768 if (start === void 0) { | 767 if (IS_UNDEFINED(start)) { |
| 769 start = 0; | 768 start = 0; |
| 770 } else { | 769 } else { |
| 771 start = TO_INTEGER(start); | 770 start = TO_INTEGER(start); |
| 772 // If positive, and greater than or equal to the string length, | 771 // If positive, and greater than or equal to the string length, |
| 773 // return empty string. | 772 // return empty string. |
| 774 if (start >= s.length) return ''; | 773 if (start >= s.length) return ''; |
| 775 // If negative and absolute value is larger than the string length, | 774 // If negative and absolute value is larger than the string length, |
| 776 // use zero. | 775 // use zero. |
| 777 if (start < 0) { | 776 if (start < 0) { |
| 778 start += s.length; | 777 start += s.length; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 "fixed", StringFixed, | 1007 "fixed", StringFixed, |
| 1009 "italics", StringItalics, | 1008 "italics", StringItalics, |
| 1010 "small", StringSmall, | 1009 "small", StringSmall, |
| 1011 "strike", StringStrike, | 1010 "strike", StringStrike, |
| 1012 "sub", StringSub, | 1011 "sub", StringSub, |
| 1013 "sup", StringSup | 1012 "sup", StringSup |
| 1014 )); | 1013 )); |
| 1015 } | 1014 } |
| 1016 | 1015 |
| 1017 SetUpString(); | 1016 SetUpString(); |
| OLD | NEW |