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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } else if (IS_STRING(b)) { | 154 } else if (IS_STRING(b)) { |
155 return %StringAdd(%ToString(a), b); | 155 return %StringAdd(%ToString(a), b); |
156 } else { | 156 } else { |
157 return %NumberAdd(%ToNumber(a), %ToNumber(b)); | 157 return %NumberAdd(%ToNumber(a), %ToNumber(b)); |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 | 161 |
162 // Left operand (this) is already a string. | 162 // Left operand (this) is already a string. |
163 function STRING_ADD_LEFT(y) { | 163 function STRING_ADD_LEFT(y) { |
164 if (!IS_STRING(y)) y = %ToString(%ToPrimitive(y, NO_HINT)); | 164 if (!IS_STRING(y)) { |
| 165 if (IS_STRING_WRAPPER(y)) { |
| 166 y = %_ValueOf(y); |
| 167 } else { |
| 168 y = IS_NUMBER(y) |
| 169 ? %NumberToString(y) |
| 170 : %ToString(%ToPrimitive(y, NO_HINT)); |
| 171 } |
| 172 } |
165 return %StringAdd(this, y); | 173 return %StringAdd(this, y); |
166 } | 174 } |
167 | 175 |
168 | 176 |
169 // Right operand (y) is already a string. | 177 // Right operand (y) is already a string. |
170 function STRING_ADD_RIGHT(y) { | 178 function STRING_ADD_RIGHT(y) { |
171 var x = IS_STRING(this) ? this : %ToString(%ToPrimitive(this, NO_HINT)); | 179 var x = this; |
| 180 if (!IS_STRING(x)) { |
| 181 if (IS_STRING_WRAPPER(x)) { |
| 182 x = %_ValueOf(x); |
| 183 } else { |
| 184 x = IS_NUMBER(x) |
| 185 ? %NumberToString(x) |
| 186 : %ToString(%ToPrimitive(x, NO_HINT)); |
| 187 } |
| 188 } |
172 return %StringAdd(x, y); | 189 return %StringAdd(x, y); |
173 } | 190 } |
174 | 191 |
175 | 192 |
176 // ECMA-262, section 11.6.2, page 50. | 193 // ECMA-262, section 11.6.2, page 50. |
177 function SUB(y) { | 194 function SUB(y) { |
178 var x = IS_NUMBER(this) ? this : %ToNumber(this); | 195 var x = IS_NUMBER(this) ? this : %ToNumber(this); |
179 if (!IS_NUMBER(y)) y = %ToNumber(y); | 196 if (!IS_NUMBER(y)) y = %ToNumber(y); |
180 return %NumberSub(x, y); | 197 return %NumberSub(x, y); |
181 } | 198 } |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 throw %MakeTypeError('cannot_convert_to_primitive', []); | 594 throw %MakeTypeError('cannot_convert_to_primitive', []); |
578 } | 595 } |
579 | 596 |
580 | 597 |
581 // NOTE: Setting the prototype for Array must take place as early as | 598 // NOTE: Setting the prototype for Array must take place as early as |
582 // possible due to code generation for array literals. When | 599 // possible due to code generation for array literals. When |
583 // generating code for a array literal a boilerplate array is created | 600 // generating code for a array literal a boilerplate array is created |
584 // that is cloned when running the code. It is essiential that the | 601 // that is cloned when running the code. It is essiential that the |
585 // boilerplate gets the right prototype. | 602 // boilerplate gets the right prototype. |
586 %FunctionSetPrototype($Array, new $Array(0)); | 603 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |