| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 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 | |
| 29 // 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 |
| 30 // in runtime.js: | 29 // in runtime.js: |
| 31 // var $String = global.String; | 30 // var $String = global.String; |
| 32 // var $NaN = 0/0; | 31 // var $NaN = 0/0; |
| 33 | 32 |
| 33 // ------------------------------------------------------------------- |
| 34 | 34 |
| 35 // Set the String function and constructor. | 35 function StringConstructor(x) { |
| 36 %SetCode($String, function(x) { | |
| 37 var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x); | 36 var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x); |
| 38 if (%_IsConstructCall()) { | 37 if (%_IsConstructCall()) { |
| 39 %_SetValueOf(this, value); | 38 %_SetValueOf(this, value); |
| 40 } else { | 39 } else { |
| 41 return value; | 40 return value; |
| 42 } | 41 } |
| 43 }); | 42 } |
| 44 | 43 |
| 45 %FunctionSetPrototype($String, new $String()); | |
| 46 | 44 |
| 47 // ECMA-262 section 15.5.4.2 | 45 // ECMA-262 section 15.5.4.2 |
| 48 function StringToString() { | 46 function StringToString() { |
| 49 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { | 47 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { |
| 50 throw new $TypeError('String.prototype.toString is not generic'); | 48 throw new $TypeError('String.prototype.toString is not generic'); |
| 51 } | 49 } |
| 52 return %_ValueOf(this); | 50 return %_ValueOf(this); |
| 53 } | 51 } |
| 54 | 52 |
| 55 | 53 |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 var elements = this.elements; | 985 var elements = this.elements; |
| 988 return %StringBuilderConcat(elements, elements.length, this.special_string); | 986 return %StringBuilderConcat(elements, elements.length, this.special_string); |
| 989 } | 987 } |
| 990 )); | 988 )); |
| 991 | 989 |
| 992 | 990 |
| 993 // ------------------------------------------------------------------- | 991 // ------------------------------------------------------------------- |
| 994 | 992 |
| 995 function SetUpString() { | 993 function SetUpString() { |
| 996 %CheckIsBootstrapping(); | 994 %CheckIsBootstrapping(); |
| 995 |
| 996 // Set the String function and constructor. |
| 997 %SetCode($String, StringConstructor); |
| 998 %FunctionSetPrototype($String, new $String()); |
| 999 |
| 997 // Set up the constructor property on the String prototype object. | 1000 // Set up the constructor property on the String prototype object. |
| 998 %SetProperty($String.prototype, "constructor", $String, DONT_ENUM); | 1001 %SetProperty($String.prototype, "constructor", $String, DONT_ENUM); |
| 999 | 1002 |
| 1000 | |
| 1001 // Set up the non-enumerable functions on the String object. | 1003 // Set up the non-enumerable functions on the String object. |
| 1002 InstallFunctions($String, DONT_ENUM, $Array( | 1004 InstallFunctions($String, DONT_ENUM, $Array( |
| 1003 "fromCharCode", StringFromCharCode | 1005 "fromCharCode", StringFromCharCode |
| 1004 )); | 1006 )); |
| 1005 | 1007 |
| 1006 | |
| 1007 // Set up the non-enumerable functions on the String prototype object. | 1008 // Set up the non-enumerable functions on the String prototype object. |
| 1008 InstallFunctions($String.prototype, DONT_ENUM, $Array( | 1009 InstallFunctions($String.prototype, DONT_ENUM, $Array( |
| 1009 "valueOf", StringValueOf, | 1010 "valueOf", StringValueOf, |
| 1010 "toString", StringToString, | 1011 "toString", StringToString, |
| 1011 "charAt", StringCharAt, | 1012 "charAt", StringCharAt, |
| 1012 "charCodeAt", StringCharCodeAt, | 1013 "charCodeAt", StringCharCodeAt, |
| 1013 "concat", StringConcat, | 1014 "concat", StringConcat, |
| 1014 "indexOf", StringIndexOf, | 1015 "indexOf", StringIndexOf, |
| 1015 "lastIndexOf", StringLastIndexOf, | 1016 "lastIndexOf", StringLastIndexOf, |
| 1016 "localeCompare", StringLocaleCompare, | 1017 "localeCompare", StringLocaleCompare, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1038 "fixed", StringFixed, | 1039 "fixed", StringFixed, |
| 1039 "italics", StringItalics, | 1040 "italics", StringItalics, |
| 1040 "small", StringSmall, | 1041 "small", StringSmall, |
| 1041 "strike", StringStrike, | 1042 "strike", StringStrike, |
| 1042 "sub", StringSub, | 1043 "sub", StringSub, |
| 1043 "sup", StringSup | 1044 "sup", StringSup |
| 1044 )); | 1045 )); |
| 1045 } | 1046 } |
| 1046 | 1047 |
| 1047 SetUpString(); | 1048 SetUpString(); |
| OLD | NEW |