OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 function ConvertToString(x) { | 195 function ConvertToString(x) { |
196 // Assumes x is a non-string. | 196 // Assumes x is a non-string. |
197 if (IS_NUMBER(x)) return %_NumberToString(x); | 197 if (IS_NUMBER(x)) return %_NumberToString(x); |
198 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 198 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
199 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x)); | 199 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x)); |
200 } | 200 } |
201 | 201 |
202 | 202 |
203 function ConvertToLocaleString(e) { | 203 function ConvertToLocaleString(e) { |
204 if (e == null) { | 204 if (IS_NULL_OR_UNDEFINED(e)) { |
205 return ''; | 205 return ''; |
206 } else { | 206 } else { |
207 // e_obj's toLocaleString might be overwritten, check if it is a function. | 207 // According to ES5, seciton 15.4.4.3, the toLocaleString conversion |
208 // Call ToString if toLocaleString is not a function. | 208 // must throw a TypeError if ToObject(e).toLocaleString isn't |
209 // See issue 877615. | 209 // callable. |
210 var e_obj = ToObject(e); | 210 var e_obj = ToObject(e); |
211 if (IS_SPEC_FUNCTION(e_obj.toLocaleString)) | 211 return %ToString(e_obj.toLocaleString()); |
212 return ToString(e_obj.toLocaleString()); | |
213 else | |
214 return ToString(e); | |
215 } | 212 } |
216 } | 213 } |
217 | 214 |
218 | 215 |
219 // This function implements the optimized splice implementation that can use | 216 // This function implements the optimized splice implementation that can use |
220 // special array operations to handle sparse arrays in a sensible fashion. | 217 // special array operations to handle sparse arrays in a sensible fashion. |
221 function SmartSlice(array, start_i, del_count, len, deleted_elements) { | 218 function SmartSlice(array, start_i, del_count, len, deleted_elements) { |
222 // Move deleted elements to a new array (the return value from splice). | 219 // Move deleted elements to a new array (the return value from splice). |
223 // Intervals array can contain keys and intervals. See comment in Concat. | 220 // Intervals array can contain keys and intervals. See comment in Concat. |
224 var intervals = %GetArrayKeys(array, start_i + del_count); | 221 var intervals = %GetArrayKeys(array, start_i + del_count); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 } | 371 } |
375 } | 372 } |
376 } | 373 } |
377 } | 374 } |
378 | 375 |
379 | 376 |
380 // ------------------------------------------------------------------- | 377 // ------------------------------------------------------------------- |
381 | 378 |
382 | 379 |
383 function ArrayToString() { | 380 function ArrayToString() { |
384 if (!IS_ARRAY(this)) { | 381 var array; |
385 throw new $TypeError('Array.prototype.toString is not generic'); | 382 var func; |
| 383 if (IS_ARRAY(this)) { |
| 384 func = this.join; |
| 385 if (func === ArrayJoin) { |
| 386 return Join(this, this.length, ',', ConvertToString); |
| 387 } |
| 388 array = this; |
| 389 } else { |
| 390 array = ToObject(this); |
| 391 func = array.join; |
386 } | 392 } |
387 return Join(this, this.length, ',', ConvertToString); | 393 if (!IS_SPEC_FUNCTION(func)) { |
| 394 return %_CallFunction(array, ObjectToString); |
| 395 } |
| 396 return %_CallFunction(array, func); |
388 } | 397 } |
389 | 398 |
390 | 399 |
391 function ArrayToLocaleString() { | 400 function ArrayToLocaleString() { |
392 if (!IS_ARRAY(this)) { | 401 var array = ToObject(this); |
393 throw new $TypeError('Array.prototype.toString is not generic'); | 402 var arrayLen = array.length; |
394 } | 403 var len = TO_UINT32(arrayLen); |
395 return Join(this, this.length, ',', ConvertToLocaleString); | 404 if (len === 0) return ""; |
| 405 return Join(array, len, ',', ConvertToLocaleString); |
396 } | 406 } |
397 | 407 |
398 | 408 |
399 function ArrayJoin(separator) { | 409 function ArrayJoin(separator) { |
400 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 410 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
401 throw MakeTypeError("called_on_null_or_undefined", | 411 throw MakeTypeError("called_on_null_or_undefined", |
402 ["Array.prototype.join"]); | 412 ["Array.prototype.join"]); |
403 } | 413 } |
404 | 414 |
405 if (IS_UNDEFINED(separator)) { | 415 if (IS_UNDEFINED(separator)) { |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 // exposed to user code. | 1382 // exposed to user code. |
1373 // Adding only the functions that are actually used. | 1383 // Adding only the functions that are actually used. |
1374 SetUpLockedPrototype(InternalArray, $Array(), $Array( | 1384 SetUpLockedPrototype(InternalArray, $Array(), $Array( |
1375 "join", getFunction("join", ArrayJoin), | 1385 "join", getFunction("join", ArrayJoin), |
1376 "pop", getFunction("pop", ArrayPop), | 1386 "pop", getFunction("pop", ArrayPop), |
1377 "push", getFunction("push", ArrayPush) | 1387 "push", getFunction("push", ArrayPush) |
1378 )); | 1388 )); |
1379 } | 1389 } |
1380 | 1390 |
1381 SetUpArray(); | 1391 SetUpArray(); |
OLD | NEW |