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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return %_StringAdd(%ToString(a), b); | 168 return %_StringAdd(%ToString(a), b); |
169 } else { | 169 } else { |
170 return %NumberAdd(%ToNumber(a), %ToNumber(b)); | 170 return %NumberAdd(%ToNumber(a), %ToNumber(b)); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 | 174 |
175 // Left operand (this) is already a string. | 175 // Left operand (this) is already a string. |
176 function STRING_ADD_LEFT(y) { | 176 function STRING_ADD_LEFT(y) { |
177 if (!IS_STRING(y)) { | 177 if (!IS_STRING(y)) { |
178 if (IS_STRING_WRAPPER(y)) { | 178 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) { |
179 y = %_ValueOf(y); | 179 y = %_ValueOf(y); |
180 } else { | 180 } else { |
181 y = IS_NUMBER(y) | 181 y = IS_NUMBER(y) |
182 ? %_NumberToString(y) | 182 ? %_NumberToString(y) |
183 : %ToString(%ToPrimitive(y, NO_HINT)); | 183 : %ToString(%ToPrimitive(y, NO_HINT)); |
184 } | 184 } |
185 } | 185 } |
186 return %_StringAdd(this, y); | 186 return %_StringAdd(this, y); |
187 } | 187 } |
188 | 188 |
189 | 189 |
190 // Right operand (y) is already a string. | 190 // Right operand (y) is already a string. |
191 function STRING_ADD_RIGHT(y) { | 191 function STRING_ADD_RIGHT(y) { |
192 var x = this; | 192 var x = this; |
193 if (!IS_STRING(x)) { | 193 if (!IS_STRING(x)) { |
194 if (IS_STRING_WRAPPER(x)) { | 194 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) { |
195 x = %_ValueOf(x); | 195 x = %_ValueOf(x); |
196 } else { | 196 } else { |
197 x = IS_NUMBER(x) | 197 x = IS_NUMBER(x) |
198 ? %_NumberToString(x) | 198 ? %_NumberToString(x) |
199 : %ToString(%ToPrimitive(x, NO_HINT)); | 199 : %ToString(%ToPrimitive(x, NO_HINT)); |
200 } | 200 } |
201 } | 201 } |
202 return %_StringAdd(x, y); | 202 return %_StringAdd(x, y); |
203 } | 203 } |
204 | 204 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 throw %MakeTypeError('cannot_convert_to_primitive', []); | 620 throw %MakeTypeError('cannot_convert_to_primitive', []); |
621 } | 621 } |
622 | 622 |
623 | 623 |
624 // NOTE: Setting the prototype for Array must take place as early as | 624 // NOTE: Setting the prototype for Array must take place as early as |
625 // possible due to code generation for array literals. When | 625 // possible due to code generation for array literals. When |
626 // generating code for a array literal a boilerplate array is created | 626 // generating code for a array literal a boilerplate array is created |
627 // that is cloned when running the code. It is essiential that the | 627 // that is cloned when running the code. It is essiential that the |
628 // boilerplate gets the right prototype. | 628 // boilerplate gets the right prototype. |
629 %FunctionSetPrototype($Array, new $Array(0)); | 629 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |