| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 var elements = new InternalArray(n); | 47 var elements = new InternalArray(n); |
| 48 for (var i = 0; i < n; i++) { | 48 for (var i = 0; i < n; i++) { |
| 49 elements[i] = s; | 49 elements[i] = s; |
| 50 } | 50 } |
| 51 | 51 |
| 52 return %StringBuilderConcat(elements, n, ""); | 52 return %StringBuilderConcat(elements, n, ""); |
| 53 } | 53 } |
| 54 | 54 |
| 55 | 55 |
| 56 // ES6 draft 01-20-14, section 21.1.3.18 | 56 // ES6 draft 04-05-14, section 21.1.3.18 |
| 57 function StringStartsWith(searchString /* position */) { // length == 1 | 57 function StringStartsWith(searchString /* position */) { // length == 1 |
| 58 CHECK_OBJECT_COERCIBLE(this, "String.prototype.startsWith"); | 58 CHECK_OBJECT_COERCIBLE(this, "String.prototype.startsWith"); |
| 59 | 59 |
| 60 var s = TO_STRING_INLINE(this); | 60 var s = TO_STRING_INLINE(this); |
| 61 | 61 |
| 62 if (IS_REGEXP(searchString)) { | 62 if (IS_REGEXP(searchString)) { |
| 63 throw MakeTypeError("first_argument_not_regexp", | 63 throw MakeTypeError("first_argument_not_regexp", |
| 64 ["String.prototype.startsWith"]); | 64 ["String.prototype.startsWith"]); |
| 65 } | 65 } |
| 66 | 66 |
| 67 var ss = TO_STRING_INLINE(searchString); | 67 var ss = TO_STRING_INLINE(searchString); |
| 68 var pos = 0; | 68 var pos = 0; |
| 69 if (%_ArgumentsLength() > 1) { | 69 if (%_ArgumentsLength() > 1) { |
| 70 pos = %_Arguments(1); // position | 70 pos = %_Arguments(1); // position |
| 71 pos = ToInteger(pos); | 71 pos = ToInteger(pos); |
| 72 } | 72 } |
| 73 | 73 |
| 74 var s_len = s.length; | 74 var s_len = s.length; |
| 75 var start = MathMin(MathMax(pos, 0), s_len); | 75 var start = MathMin(MathMax(pos, 0), s_len); |
| 76 var ss_len = ss.length; | 76 var ss_len = ss.length; |
| 77 if (ss_len + start > s_len) { | 77 if (ss_len + start > s_len) { |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 | 80 |
| 81 return %StringIndexOf(s, ss, start) === start; | 81 return %StringIndexOf(s, ss, start) === start; |
| 82 } | 82 } |
| 83 | 83 |
| 84 | 84 |
| 85 // ES6 draft 01-20-14, section 21.1.3.7 | 85 // ES6 draft 04-05-14, section 21.1.3.7 |
| 86 function StringEndsWith(searchString /* position */) { // length == 1 | 86 function StringEndsWith(searchString /* position */) { // length == 1 |
| 87 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith"); | 87 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith"); |
| 88 | 88 |
| 89 var s = TO_STRING_INLINE(this); | 89 var s = TO_STRING_INLINE(this); |
| 90 | 90 |
| 91 if (IS_REGEXP(searchString)) { | 91 if (IS_REGEXP(searchString)) { |
| 92 throw MakeTypeError("first_argument_not_regexp", | 92 throw MakeTypeError("first_argument_not_regexp", |
| 93 ["String.prototype.endsWith"]); | 93 ["String.prototype.endsWith"]); |
| 94 } | 94 } |
| 95 | 95 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 107 var ss_len = ss.length; | 107 var ss_len = ss.length; |
| 108 var start = end - ss_len; | 108 var start = end - ss_len; |
| 109 if (start < 0) { | 109 if (start < 0) { |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 | 112 |
| 113 return %StringLastIndexOf(s, ss, start) === start; | 113 return %StringLastIndexOf(s, ss, start) === start; |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 // ES6 draft 01-20-14, section 21.1.3.6 | 117 // ES6 draft 04-05-14, section 21.1.3.6 |
| 118 function StringContains(searchString /* position */) { // length == 1 | 118 function StringContains(searchString /* position */) { // length == 1 |
| 119 CHECK_OBJECT_COERCIBLE(this, "String.prototype.contains"); | 119 CHECK_OBJECT_COERCIBLE(this, "String.prototype.contains"); |
| 120 | 120 |
| 121 var s = TO_STRING_INLINE(this); | 121 var s = TO_STRING_INLINE(this); |
| 122 |
| 123 if (IS_REGEXP(searchString)) { |
| 124 throw MakeTypeError("first_argument_not_regexp", |
| 125 ["String.prototype.contains"]); |
| 126 } |
| 127 |
| 122 var ss = TO_STRING_INLINE(searchString); | 128 var ss = TO_STRING_INLINE(searchString); |
| 123 var pos = 0; | 129 var pos = 0; |
| 124 if (%_ArgumentsLength() > 1) { | 130 if (%_ArgumentsLength() > 1) { |
| 125 pos = %_Arguments(1); // position | 131 pos = %_Arguments(1); // position |
| 126 pos = ToInteger(pos); | 132 pos = ToInteger(pos); |
| 127 } | 133 } |
| 128 | 134 |
| 129 var s_len = s.length; | 135 var s_len = s.length; |
| 130 var start = MathMin(MathMax(pos, 0), s_len); | 136 var start = MathMin(MathMax(pos, 0), s_len); |
| 131 var ss_len = ss.length; | 137 var ss_len = ss.length; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 145 // Set up the non-enumerable functions on the String prototype object. | 151 // Set up the non-enumerable functions on the String prototype object. |
| 146 InstallFunctions($String.prototype, DONT_ENUM, $Array( | 152 InstallFunctions($String.prototype, DONT_ENUM, $Array( |
| 147 "repeat", StringRepeat, | 153 "repeat", StringRepeat, |
| 148 "startsWith", StringStartsWith, | 154 "startsWith", StringStartsWith, |
| 149 "endsWith", StringEndsWith, | 155 "endsWith", StringEndsWith, |
| 150 "contains", StringContains | 156 "contains", StringContains |
| 151 )); | 157 )); |
| 152 } | 158 } |
| 153 | 159 |
| 154 ExtendStringPrototype(); | 160 ExtendStringPrototype(); |
| OLD | NEW |