| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 // This files contains runtime support implemented in JavaScript. | 5 // This files contains runtime support implemented in JavaScript. |
| 6 | 6 |
| 7 // CAUTION: Some of the functions specified in this file are called | 7 // CAUTION: Some of the functions specified in this file are called |
| 8 // directly from compiled code. These are the functions with names in | 8 // directly from compiled code. These are the functions with names in |
| 9 // ALL CAPS. The compiled code passes the first argument in 'this' and | 9 // ALL CAPS. The compiled code passes the first argument in 'this' and |
| 10 // it does not push the function onto the stack. This means that you | 10 // it does not push the function onto the stack. This means that you |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // ECMA-262 Section 11.9.3. | 29 // ECMA-262 Section 11.9.3. |
| 30 function EQUALS(y) { | 30 function EQUALS(y) { |
| 31 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y); | 31 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y); |
| 32 var x = this; | 32 var x = this; |
| 33 | 33 |
| 34 while (true) { | 34 while (true) { |
| 35 if (IS_NUMBER(x)) { | 35 if (IS_NUMBER(x)) { |
| 36 while (true) { | 36 while (true) { |
| 37 if (IS_NUMBER(y)) return %NumberEquals(x, y); | 37 if (IS_NUMBER(y)) return %NumberEquals(x, y); |
| 38 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 38 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
| 39 if (IS_SYMBOL(y)) return 1; // not equal |
| 39 if (!IS_SPEC_OBJECT(y)) { | 40 if (!IS_SPEC_OBJECT(y)) { |
| 40 // String or boolean. | 41 // String or boolean. |
| 41 return %NumberEquals(x, %ToNumber(y)); | 42 return %NumberEquals(x, %ToNumber(y)); |
| 42 } | 43 } |
| 43 y = %ToPrimitive(y, NO_HINT); | 44 y = %ToPrimitive(y, NO_HINT); |
| 44 } | 45 } |
| 45 } else if (IS_STRING(x)) { | 46 } else if (IS_STRING(x)) { |
| 46 while (true) { | 47 while (true) { |
| 47 if (IS_STRING(y)) return %StringEquals(x, y); | 48 if (IS_STRING(y)) return %StringEquals(x, y); |
| 48 if (IS_SYMBOL(y)) return 1; // not equal | 49 if (IS_SYMBOL(y)) return 1; // not equal |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 495 |
| 495 // ECMA-262, section 9.3, page 31. | 496 // ECMA-262, section 9.3, page 31. |
| 496 function ToNumber(x) { | 497 function ToNumber(x) { |
| 497 if (IS_NUMBER(x)) return x; | 498 if (IS_NUMBER(x)) return x; |
| 498 if (IS_STRING(x)) { | 499 if (IS_STRING(x)) { |
| 499 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 500 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
| 500 : %StringToNumber(x); | 501 : %StringToNumber(x); |
| 501 } | 502 } |
| 502 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 503 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
| 503 if (IS_UNDEFINED(x)) return NAN; | 504 if (IS_UNDEFINED(x)) return NAN; |
| 504 if (IS_SYMBOL(x)) return NAN; | 505 if (IS_SYMBOL(x)) throw MakeTypeError('symbol_to_number', []); |
| 505 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 506 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
| 506 } | 507 } |
| 507 | 508 |
| 508 function NonNumberToNumber(x) { | 509 function NonNumberToNumber(x) { |
| 509 if (IS_STRING(x)) { | 510 if (IS_STRING(x)) { |
| 510 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 511 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
| 511 : %StringToNumber(x); | 512 : %StringToNumber(x); |
| 512 } | 513 } |
| 513 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 514 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
| 514 if (IS_UNDEFINED(x)) return NAN; | 515 if (IS_UNDEFINED(x)) return NAN; |
| 515 if (IS_SYMBOL(x)) return NAN; | 516 if (IS_SYMBOL(x)) throw MakeTypeError('symbol_to_number', []); |
| 516 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 517 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
| 517 } | 518 } |
| 518 | 519 |
| 519 | 520 |
| 520 // ECMA-262, section 9.8, page 35. | 521 // ECMA-262, section 9.8, page 35. |
| 521 function ToString(x) { | 522 function ToString(x) { |
| 522 if (IS_STRING(x)) return x; | 523 if (IS_STRING(x)) return x; |
| 523 if (IS_NUMBER(x)) return %_NumberToString(x); | 524 if (IS_NUMBER(x)) return %_NumberToString(x); |
| 524 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 525 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
| 525 if (IS_UNDEFINED(x)) return 'undefined'; | 526 if (IS_UNDEFINED(x)) return 'undefined'; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 return i; | 648 return i; |
| 648 } | 649 } |
| 649 | 650 |
| 650 | 651 |
| 651 // NOTE: Setting the prototype for Array must take place as early as | 652 // NOTE: Setting the prototype for Array must take place as early as |
| 652 // possible due to code generation for array literals. When | 653 // possible due to code generation for array literals. When |
| 653 // generating code for a array literal a boilerplate array is created | 654 // generating code for a array literal a boilerplate array is created |
| 654 // that is cloned when running the code. It is essential that the | 655 // that is cloned when running the code. It is essential that the |
| 655 // boilerplate gets the right prototype. | 656 // boilerplate gets the right prototype. |
| 656 %FunctionSetPrototype($Array, new $Array(0)); | 657 %FunctionSetPrototype($Array, new $Array(0)); |
| OLD | NEW |