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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
140 /* ----------------------------------- | 140 /* ----------------------------------- |
141 - - - A r i t h m e t i c - - - | 141 - - - A r i t h m e t i c - - - |
142 ----------------------------------- | 142 ----------------------------------- |
143 */ | 143 */ |
144 | 144 |
145 // ECMA-262, section 11.6.1, page 50. | 145 // ECMA-262, section 11.6.1, page 50. |
146 function ADD(x) { | 146 function ADD(x) { |
147 // Fast case: Check for number operands and do the addition. | 147 // Fast case: Check for number operands and do the addition. |
148 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); | 148 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); |
149 if (IS_STRING(this) && IS_STRING(x)) return %StringAdd(this, x); | 149 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); |
150 | 150 |
151 // Default implementation. | 151 // Default implementation. |
152 var a = %ToPrimitive(this, NO_HINT); | 152 var a = %ToPrimitive(this, NO_HINT); |
153 var b = %ToPrimitive(x, NO_HINT); | 153 var b = %ToPrimitive(x, NO_HINT); |
154 | 154 |
155 if (IS_STRING(a)) { | 155 if (IS_STRING(a)) { |
156 return %StringAdd(a, %ToString(b)); | 156 return %_StringAdd(a, %ToString(b)); |
157 } else if (IS_STRING(b)) { | 157 } else if (IS_STRING(b)) { |
158 return %StringAdd(%ToString(a), b); | 158 return %_StringAdd(%ToString(a), b); |
159 } else { | 159 } else { |
160 return %NumberAdd(%ToNumber(a), %ToNumber(b)); | 160 return %NumberAdd(%ToNumber(a), %ToNumber(b)); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 // Left operand (this) is already a string. | 165 // Left operand (this) is already a string. |
166 function STRING_ADD_LEFT(y) { | 166 function STRING_ADD_LEFT(y) { |
167 if (!IS_STRING(y)) { | 167 if (!IS_STRING(y)) { |
168 if (IS_STRING_WRAPPER(y)) { | 168 if (IS_STRING_WRAPPER(y)) { |
169 y = %_ValueOf(y); | 169 y = %_ValueOf(y); |
170 } else { | 170 } else { |
171 y = IS_NUMBER(y) | 171 y = IS_NUMBER(y) |
172 ? %NumberToString(y) | 172 ? %NumberToString(y) |
173 : %ToString(%ToPrimitive(y, NO_HINT)); | 173 : %ToString(%ToPrimitive(y, NO_HINT)); |
174 } | 174 } |
175 } | 175 } |
176 return %StringAdd(this, y); | 176 return %_StringAdd(this, y); |
177 } | 177 } |
178 | 178 |
179 | 179 |
180 // Right operand (y) is already a string. | 180 // Right operand (y) is already a string. |
181 function STRING_ADD_RIGHT(y) { | 181 function STRING_ADD_RIGHT(y) { |
182 var x = this; | 182 var x = this; |
183 if (!IS_STRING(x)) { | 183 if (!IS_STRING(x)) { |
184 if (IS_STRING_WRAPPER(x)) { | 184 if (IS_STRING_WRAPPER(x)) { |
185 x = %_ValueOf(x); | 185 x = %_ValueOf(x); |
186 } else { | 186 } else { |
187 x = IS_NUMBER(x) | 187 x = IS_NUMBER(x) |
188 ? %NumberToString(x) | 188 ? %NumberToString(x) |
189 : %ToString(%ToPrimitive(x, NO_HINT)); | 189 : %ToString(%ToPrimitive(x, NO_HINT)); |
190 } | 190 } |
191 } | 191 } |
192 return %StringAdd(x, y); | 192 return %_StringAdd(x, y); |
193 } | 193 } |
194 | 194 |
195 | 195 |
196 // ECMA-262, section 11.6.2, page 50. | 196 // ECMA-262, section 11.6.2, page 50. |
197 function SUB(y) { | 197 function SUB(y) { |
198 var x = IS_NUMBER(this) ? this : %ToNumber(this); | 198 var x = IS_NUMBER(this) ? this : %ToNumber(this); |
199 if (!IS_NUMBER(y)) y = %ToNumber(y); | 199 if (!IS_NUMBER(y)) y = %ToNumber(y); |
200 return %NumberSub(x, y); | 200 return %NumberSub(x, y); |
201 } | 201 } |
202 | 202 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 throw %MakeTypeError('cannot_convert_to_primitive', []); | 597 throw %MakeTypeError('cannot_convert_to_primitive', []); |
598 } | 598 } |
599 | 599 |
600 | 600 |
601 // 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 |
602 // possible due to code generation for array literals. When | 602 // possible due to code generation for array literals. When |
603 // generating code for a array literal a boilerplate array is created | 603 // generating code for a array literal a boilerplate array is created |
604 // 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 |
605 // boilerplate gets the right prototype. | 605 // boilerplate gets the right prototype. |
606 %FunctionSetPrototype($Array, new $Array(0)); | 606 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |