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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // the result when either (or both) the operands are NaN. | 115 // the result when either (or both) the operands are NaN. |
116 function COMPARE(x, ncr) { | 116 function COMPARE(x, ncr) { |
117 // Fast case for numbers and strings. | 117 // Fast case for numbers and strings. |
118 if (IS_NUMBER(this) && IS_NUMBER(x)) { | 118 if (IS_NUMBER(this) && IS_NUMBER(x)) { |
119 return %NumberCompare(this, x, ncr); | 119 return %NumberCompare(this, x, ncr); |
120 } | 120 } |
121 if (IS_STRING(this) && IS_STRING(x)) { | 121 if (IS_STRING(this) && IS_STRING(x)) { |
122 return %StringCompare(this, x); | 122 return %StringCompare(this, x); |
123 } | 123 } |
124 | 124 |
| 125 // If one of the operands is undefined, it will convert to NaN and |
| 126 // thus the result should be as if one of the operands was NaN. |
| 127 if (IS_UNDEFINED(this) || IS_UNDEFINED(x)) { |
| 128 return ncr; |
| 129 } |
| 130 |
125 // Default implementation. | 131 // Default implementation. |
126 var a = %ToPrimitive(this, NUMBER_HINT); | 132 var a = %ToPrimitive(this, NUMBER_HINT); |
127 var b = %ToPrimitive(x, NUMBER_HINT); | 133 var b = %ToPrimitive(x, NUMBER_HINT); |
128 if (IS_STRING(a) && IS_STRING(b)) { | 134 if (IS_STRING(a) && IS_STRING(b)) { |
129 return %StringCompare(a, b); | 135 return %StringCompare(a, b); |
130 } else { | 136 } else { |
131 var a_number = %ToNumber(a); | 137 var a_number = %ToNumber(a); |
132 var b_number = %ToNumber(b); | 138 var b_number = %ToNumber(b); |
133 if (NUMBER_IS_NAN(a_number) || NUMBER_IS_NAN(b_number)) return ncr; | 139 if (NUMBER_IS_NAN(a_number) || NUMBER_IS_NAN(b_number)) return ncr; |
134 return %NumberCompare(a_number, b_number, ncr); | 140 return %NumberCompare(a_number, b_number, ncr); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 throw %MakeTypeError('cannot_convert_to_primitive', []); | 603 throw %MakeTypeError('cannot_convert_to_primitive', []); |
598 } | 604 } |
599 | 605 |
600 | 606 |
601 // NOTE: Setting the prototype for Array must take place as early as | 607 // NOTE: Setting the prototype for Array must take place as early as |
602 // possible due to code generation for array literals. When | 608 // possible due to code generation for array literals. When |
603 // generating code for a array literal a boilerplate array is created | 609 // generating code for a array literal a boilerplate array is created |
604 // that is cloned when running the code. It is essiential that the | 610 // that is cloned when running the code. It is essiential that the |
605 // boilerplate gets the right prototype. | 611 // boilerplate gets the right prototype. |
606 %FunctionSetPrototype($Array, new $Array(0)); | 612 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |