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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Default implementation. | 125 // Default implementation. |
126 var a = %ToPrimitive(this, NUMBER_HINT); | 126 var a = %ToPrimitive(this, NUMBER_HINT); |
127 var b = %ToPrimitive(x, NUMBER_HINT); | 127 var b = %ToPrimitive(x, NUMBER_HINT); |
128 if (IS_STRING(a) && IS_STRING(b)) { | 128 if (IS_STRING(a) && IS_STRING(b)) { |
129 return %StringCompare(a, b); | 129 return %StringCompare(a, b); |
130 } else { | 130 } else { |
131 return %NumberCompare(%ToNumber(a), %ToNumber(b), ncr); | 131 var a_number = %ToNumber(a); |
| 132 var b_number = %ToNumber(b); |
| 133 if (NUMBER_IS_NAN(a_number) || NUMBER_IS_NAN(b_number)) return ncr; |
| 134 return %NumberCompare(a_number, b_number, ncr); |
132 } | 135 } |
133 } | 136 } |
134 | 137 |
135 | 138 |
136 | 139 |
137 /* ----------------------------------- | 140 /* ----------------------------------- |
138 - - - A r i t h m e t i c - - - | 141 - - - A r i t h m e t i c - - - |
139 ----------------------------------- | 142 ----------------------------------- |
140 */ | 143 */ |
141 | 144 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 throw %MakeTypeError('cannot_convert_to_primitive', []); | 597 throw %MakeTypeError('cannot_convert_to_primitive', []); |
595 } | 598 } |
596 | 599 |
597 | 600 |
598 // NOTE: Setting the prototype for Array must take place as early as | 601 // NOTE: Setting the prototype for Array must take place as early as |
599 // possible due to code generation for array literals. When | 602 // possible due to code generation for array literals. When |
600 // generating code for a array literal a boilerplate array is created | 603 // generating code for a array literal a boilerplate array is created |
601 // that is cloned when running the code. It is essiential that the | 604 // that is cloned when running the code. It is essiential that the |
602 // boilerplate gets the right prototype. | 605 // boilerplate gets the right prototype. |
603 %FunctionSetPrototype($Array, new $Array(0)); | 606 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |