| 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 // 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 const $Array = global.Array; | 45 const $Array = global.Array; |
| 46 const $String = global.String; | 46 const $String = global.String; |
| 47 const $Number = global.Number; | 47 const $Number = global.Number; |
| 48 const $Function = global.Function; | 48 const $Function = global.Function; |
| 49 const $Boolean = global.Boolean; | 49 const $Boolean = global.Boolean; |
| 50 const $NaN = 0/0; | 50 const $NaN = 0/0; |
| 51 | 51 |
| 52 | 52 |
| 53 // ECMA-262, section 11.9.1, page 55. | 53 // ECMA-262, section 11.9.1, page 55. |
| 54 function EQUALS(y) { | 54 function EQUALS(y) { |
| 55 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y); | 55 var r = %FastEquals(this, y); |
| 56 if (r <= 1) return r; |
| 56 var x = this; | 57 var x = this; |
| 57 | 58 |
| 58 // NOTE: We use iteration instead of recursion, because it is | 59 // NOTE: We use iteration instead of recursion, because it is |
| 59 // difficult to call EQUALS with the correct setting of 'this' in | 60 // difficult to call EQUALS with the correct setting of 'this' in |
| 60 // an efficient way. | 61 // an efficient way. |
| 61 while (true) { | 62 while (true) { |
| 62 if (IS_NUMBER(x)) { | 63 if (r == EQUALS_SECOND_ARG_TO_DEFAULT_VALUE) { |
| 63 if (y == null) return 1; // not equal | 64 x = %ToNumber(x); |
| 64 return %NumberEquals(x, %ToNumber(y)); | 65 y = %ToNumber(%DefaultNumber(y)); |
| 65 } else if (IS_STRING(x)) { | 66 return %NumberEquals(x, y); |
| 66 if (IS_STRING(y)) return %StringEquals(x, y); | 67 } else if (r == EQUALS_SECOND_ARG_TO_PRIMITIVE) { |
| 67 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y); | |
| 68 if (IS_BOOLEAN(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); | |
| 69 if (y == null) return 1; // not equal | |
| 70 y = %ToPrimitive(y, NO_HINT); | 68 y = %ToPrimitive(y, NO_HINT); |
| 71 } else if (IS_BOOLEAN(x)) { | 69 // retry |
| 72 if (IS_BOOLEAN(y)) { | 70 } else if (r == EQUALS_FIRST_ARG_TO_PRIMITIVE) { |
| 73 return %_ObjectEquals(x, y) ? 0 : 1; | 71 x = %ToPrimitive(x, NO_HINT); |
| 74 } | 72 // retry |
| 75 if (y == null) return 1; // not equal | 73 } |
| 76 return %NumberEquals(%ToNumber(x), %ToNumber(y)); | |
| 77 } else if (x == null) { | |
| 78 // NOTE: This checks for both null and undefined. | |
| 79 return (y == null) ? 0 : 1; | |
| 80 } else { | |
| 81 // x is not a number, boolean, null or undefined. | |
| 82 if (y == null) return 1; // not equal | |
| 83 if (IS_OBJECT(y)) { | |
| 84 return %_ObjectEquals(x, y) ? 0 : 1; | |
| 85 } | |
| 86 if (IS_FUNCTION(y)) { | |
| 87 return %_ObjectEquals(x, y) ? 0 : 1; | |
| 88 } | |
| 89 | 74 |
| 90 x = %ToPrimitive(x, NO_HINT); | 75 var r = %FastEquals(x, y); |
| 91 } | 76 if (r <= 1) return r; |
| 92 } | 77 } |
| 93 } | 78 } |
| 94 | 79 |
| 95 // ECMA-262, section 11.9.4, page 56. | 80 // ECMA-262, section 11.9.4, page 56. |
| 96 function STRICT_EQUALS(x) { | 81 function STRICT_EQUALS(x) { |
| 97 if (IS_STRING(this)) { | 82 if (IS_STRING(this)) { |
| 98 if (!IS_STRING(x)) return 1; // not equal | 83 if (!IS_STRING(x)) return 1; // not equal |
| 99 return %StringEquals(this, x); | 84 return %StringEquals(this, x); |
| 100 } | 85 } |
| 101 | 86 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 throw %MakeTypeError('cannot_convert_to_primitive', []); | 624 throw %MakeTypeError('cannot_convert_to_primitive', []); |
| 640 } | 625 } |
| 641 | 626 |
| 642 | 627 |
| 643 // NOTE: Setting the prototype for Array must take place as early as | 628 // NOTE: Setting the prototype for Array must take place as early as |
| 644 // possible due to code generation for array literals. When | 629 // possible due to code generation for array literals. When |
| 645 // generating code for a array literal a boilerplate array is created | 630 // generating code for a array literal a boilerplate array is created |
| 646 // that is cloned when running the code. It is essiential that the | 631 // that is cloned when running the code. It is essiential that the |
| 647 // boilerplate gets the right prototype. | 632 // boilerplate gets the right prototype. |
| 648 %FunctionSetPrototype($Array, new $Array(0)); | 633 %FunctionSetPrototype($Array, new $Array(0)); |
| OLD | NEW |