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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 if (!%_IsSmi(code)) { | 153 if (!%_IsSmi(code)) { |
154 code = ToNumber(code); | 154 code = ToNumber(code); |
155 } | 155 } |
156 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { | 156 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { |
157 throw MakeRangeError("invalid_code_point", [code]); | 157 throw MakeRangeError("invalid_code_point", [code]); |
158 } | 158 } |
159 if (code <= 0xFFFF) { | 159 if (code <= 0xFFFF) { |
160 result += %_StringCharFromCode(code); | 160 result += %_StringCharFromCode(code); |
161 } else { | 161 } else { |
162 code -= 0x10000; | 162 code -= 0x10000; |
163 result += StringFromCharCode( | 163 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); |
164 code >>> 10 & 0x3FF | 0xD800, | 164 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); |
165 0xDC00 | code & 0x3FF | |
166 ); | |
167 } | 165 } |
168 } | 166 } |
169 return result; | 167 return result; |
170 } | 168 } |
171 | 169 |
172 | 170 |
173 // ------------------------------------------------------------------- | 171 // ------------------------------------------------------------------- |
174 | 172 |
175 function ExtendStringPrototype() { | 173 function ExtendStringPrototype() { |
176 %CheckIsBootstrapping(); | 174 %CheckIsBootstrapping(); |
177 | 175 |
178 // Set up the non-enumerable functions on the String object. | 176 // Set up the non-enumerable functions on the String object. |
179 InstallFunctions($String, DONT_ENUM, $Array( | 177 InstallFunctions($String, DONT_ENUM, $Array( |
180 "fromCodePoint", StringFromCodePoint | 178 "fromCodePoint", StringFromCodePoint |
181 )); | 179 )); |
182 | 180 |
183 // Set up the non-enumerable functions on the String prototype object. | 181 // Set up the non-enumerable functions on the String prototype object. |
184 InstallFunctions($String.prototype, DONT_ENUM, $Array( | 182 InstallFunctions($String.prototype, DONT_ENUM, $Array( |
185 "codePointAt", StringCodePointAt, | 183 "codePointAt", StringCodePointAt, |
186 "contains", StringContains, | 184 "contains", StringContains, |
187 "endsWith", StringEndsWith, | 185 "endsWith", StringEndsWith, |
188 "repeat", StringRepeat, | 186 "repeat", StringRepeat, |
189 "startsWith", StringStartsWith | 187 "startsWith", StringStartsWith |
190 )); | 188 )); |
191 } | 189 } |
192 | 190 |
193 ExtendStringPrototype(); | 191 ExtendStringPrototype(); |
OLD | NEW |