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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Objects (including functions), null, undefined and booleans were | 105 // Objects (including functions), null, undefined and booleans were |
106 // checked in the CompareStub, so there should be nothing left. | 106 // checked in the CompareStub, so there should be nothing left. |
107 return %_ObjectEquals(this, x) ? 0 : 1; | 107 return %_ObjectEquals(this, x) ? 0 : 1; |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as | 111 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as |
112 // the result when either (or both) the operands are NaN. | 112 // the result when either (or both) the operands are NaN. |
113 function COMPARE(x, ncr) { | 113 function COMPARE(x, ncr) { |
114 var left; | 114 var left; |
115 | 115 var right; |
116 // Fast cases for string, numbers and undefined compares. | 116 // Fast cases for string, numbers and undefined compares. |
117 if (IS_STRING(this)) { | 117 if (IS_STRING(this)) { |
118 if (IS_STRING(x)) return %_StringCompare(this, x); | 118 if (IS_STRING(x)) return %_StringCompare(this, x); |
119 if (IS_UNDEFINED(x)) return ncr; | 119 if (IS_UNDEFINED(x)) return ncr; |
120 left = this; | 120 left = this; |
121 } else if (IS_NUMBER(this)) { | 121 } else if (IS_NUMBER(this)) { |
122 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr); | 122 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr); |
123 if (IS_UNDEFINED(x)) return ncr; | 123 if (IS_UNDEFINED(x)) return ncr; |
124 left = this; | 124 left = this; |
125 } else if (IS_UNDEFINED(this)) { | 125 } else if (IS_UNDEFINED(this)) { |
| 126 if (!IS_UNDEFINED(x)) { |
| 127 %ToPrimitive(x, NUMBER_HINT); |
| 128 } |
| 129 return ncr; |
| 130 } else if (IS_UNDEFINED(x)) { |
| 131 %ToPrimitive(this, NUMBER_HINT); |
126 return ncr; | 132 return ncr; |
127 } else { | 133 } else { |
128 if (IS_UNDEFINED(x)) return ncr; | |
129 left = %ToPrimitive(this, NUMBER_HINT); | 134 left = %ToPrimitive(this, NUMBER_HINT); |
130 } | 135 } |
131 | 136 |
132 // Default implementation. | 137 right = %ToPrimitive(x, NUMBER_HINT); |
133 var right = %ToPrimitive(x, NUMBER_HINT); | |
134 if (IS_STRING(left) && IS_STRING(right)) { | 138 if (IS_STRING(left) && IS_STRING(right)) { |
135 return %_StringCompare(left, right); | 139 return %_StringCompare(left, right); |
136 } else { | 140 } else { |
137 var left_number = %ToNumber(left); | 141 var left_number = %ToNumber(left); |
138 var right_number = %ToNumber(right); | 142 var right_number = %ToNumber(right); |
139 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr; | 143 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr; |
140 return %NumberCompare(left_number, right_number, ncr); | 144 return %NumberCompare(left_number, right_number, ncr); |
141 } | 145 } |
142 } | 146 } |
143 | 147 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 throw %MakeTypeError('cannot_convert_to_primitive', []); | 624 throw %MakeTypeError('cannot_convert_to_primitive', []); |
621 } | 625 } |
622 | 626 |
623 | 627 |
624 // 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 |
625 // possible due to code generation for array literals. When | 629 // possible due to code generation for array literals. When |
626 // generating code for a array literal a boilerplate array is created | 630 // generating code for a array literal a boilerplate array is created |
627 // 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 |
628 // boilerplate gets the right prototype. | 632 // boilerplate gets the right prototype. |
629 %FunctionSetPrototype($Array, new $Array(0)); | 633 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |