OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $String = global.String; | 9 // var $String = global.String; |
10 // var $Array = global.Array; | 10 // var $Array = global.Array; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 var start = MathMin(MathMax(pos, 0), s_len); | 113 var start = MathMin(MathMax(pos, 0), s_len); |
114 var ss_len = ss.length; | 114 var ss_len = ss.length; |
115 if (ss_len + start > s_len) { | 115 if (ss_len + start > s_len) { |
116 return false; | 116 return false; |
117 } | 117 } |
118 | 118 |
119 return %StringIndexOf(s, ss, start) !== -1; | 119 return %StringIndexOf(s, ss, start) !== -1; |
120 } | 120 } |
121 | 121 |
122 | 122 |
| 123 // ES6 Draft 05-22-2014, section 21.1.3.3 |
| 124 function StringCodePointAt(pos) { |
| 125 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); |
| 126 |
| 127 var string = TO_STRING_INLINE(this); |
| 128 var size = string.length; |
| 129 pos = TO_INTEGER(pos); |
| 130 if (pos < 0 || pos >= size) { |
| 131 return UNDEFINED; |
| 132 } |
| 133 var first = %_StringCharCodeAt(string, pos); |
| 134 if (first < 0xD800 || first > 0xDBFF || pos + 1 == size) { |
| 135 return first; |
| 136 } |
| 137 var second = %_StringCharCodeAt(string, pos + 1); |
| 138 if (second < 0xDC00 || second > 0xDFFF) { |
| 139 return first; |
| 140 } |
| 141 return (first - 0xD800) * 0x400 + second + 0x2400; |
| 142 } |
| 143 |
| 144 |
| 145 // ES6 Draft 05-22-2014, section 21.1.2.2 |
| 146 function StringFromCodePoint(_) { // length = 1 |
| 147 var code; |
| 148 var length = %_ArgumentsLength(); |
| 149 var index; |
| 150 var result = ""; |
| 151 for (index = 0; index < length; index++) { |
| 152 code = %_Arguments(index); |
| 153 if (!%_IsSmi(code)) { |
| 154 code = ToNumber(code); |
| 155 } |
| 156 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { |
| 157 throw MakeRangeError("invalid_code_point", [code]); |
| 158 } |
| 159 if (code <= 0xFFFF) { |
| 160 result += %_StringCharFromCode(code); |
| 161 } else { |
| 162 code -= 0x10000; |
| 163 result += StringFromCharCode( |
| 164 code >>> 10 & 0x3FF | 0xD800, |
| 165 0xDC00 | code & 0x3FF |
| 166 ); |
| 167 } |
| 168 } |
| 169 return result; |
| 170 } |
| 171 |
| 172 |
123 // ------------------------------------------------------------------- | 173 // ------------------------------------------------------------------- |
124 | 174 |
125 function ExtendStringPrototype() { | 175 function ExtendStringPrototype() { |
126 %CheckIsBootstrapping(); | 176 %CheckIsBootstrapping(); |
127 | 177 |
| 178 // Set up the non-enumerable functions on the String object. |
| 179 InstallFunctions($String, DONT_ENUM, $Array( |
| 180 "fromCodePoint", StringFromCodePoint |
| 181 )); |
| 182 |
128 // Set up the non-enumerable functions on the String prototype object. | 183 // Set up the non-enumerable functions on the String prototype object. |
129 InstallFunctions($String.prototype, DONT_ENUM, $Array( | 184 InstallFunctions($String.prototype, DONT_ENUM, $Array( |
| 185 "codePointAt", StringCodePointAt, |
| 186 "contains", StringContains, |
| 187 "endsWith", StringEndsWith, |
130 "repeat", StringRepeat, | 188 "repeat", StringRepeat, |
131 "startsWith", StringStartsWith, | 189 "startsWith", StringStartsWith |
132 "endsWith", StringEndsWith, | |
133 "contains", StringContains | |
134 )); | 190 )); |
135 } | 191 } |
136 | 192 |
137 ExtendStringPrototype(); | 193 ExtendStringPrototype(); |
OLD | NEW |