Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/runtime.js

Issue 1287203002: [strong] Simplify (and sortof optimize) string addition for strong mode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Small beautification. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/hydrogen.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This files contains runtime support implemented in JavaScript. 5 // This files contains runtime support implemented in JavaScript.
6 6
7 // CAUTION: Some of the functions specified in this file are called 7 // CAUTION: Some of the functions specified in this file are called
8 // directly from compiled code. These are the functions with names in 8 // directly from compiled code. These are the functions with names in
9 // ALL CAPS. The compiled code passes the first argument in 'this'. 9 // ALL CAPS. The compiled code passes the first argument in 'this'.
10 10
11 11
12 /* ----------------------------------- 12 /* -----------------------------------
13 - - - C o m p a r i s o n - - - 13 - - - C o m p a r i s o n - - -
14 ----------------------------------- 14 -----------------------------------
15 */ 15 */
16 16
17 // The following declarations are shared with other native JS files. 17 // The following declarations are shared with other native JS files.
18 // They are all declared at this one spot to avoid redeclaration errors. 18 // They are all declared at this one spot to avoid redeclaration errors.
19 var EQUALS; 19 var EQUALS;
20 var STRICT_EQUALS; 20 var STRICT_EQUALS;
21 var COMPARE; 21 var COMPARE;
22 var COMPARE_STRONG; 22 var COMPARE_STRONG;
23 var ADD; 23 var ADD;
24 var ADD_STRONG; 24 var ADD_STRONG;
25 var STRING_ADD_LEFT; 25 var STRING_ADD_LEFT;
26 var STRING_ADD_LEFT_STRONG;
27 var STRING_ADD_RIGHT; 26 var STRING_ADD_RIGHT;
28 var STRING_ADD_RIGHT_STRONG;
29 var SUB; 27 var SUB;
30 var SUB_STRONG; 28 var SUB_STRONG;
31 var MUL; 29 var MUL;
32 var MUL_STRONG; 30 var MUL_STRONG;
33 var DIV; 31 var DIV;
34 var DIV_STRONG; 32 var DIV_STRONG;
35 var MOD; 33 var MOD;
36 var MOD_STRONG; 34 var MOD_STRONG;
37 var BIT_OR; 35 var BIT_OR;
38 var BIT_OR_STRONG; 36 var BIT_OR_STRONG;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } else { 253 } else {
256 y = IS_NUMBER(y) 254 y = IS_NUMBER(y)
257 ? %_NumberToString(y) 255 ? %_NumberToString(y)
258 : %$toString(%$toPrimitive(y, NO_HINT)); 256 : %$toString(%$toPrimitive(y, NO_HINT));
259 } 257 }
260 } 258 }
261 return %_StringAdd(this, y); 259 return %_StringAdd(this, y);
262 } 260 }
263 261
264 262
265 // Left operand (this) is already a string.
266 STRING_ADD_LEFT_STRONG = function STRING_ADD_LEFT_STRONG(y) {
267 if (IS_STRING(y)) {
268 return %_StringAdd(this, y);
269 }
270 throw %MakeTypeError(kStrongImplicitConversion);
271 }
272
273
274 // Right operand (y) is already a string. 263 // Right operand (y) is already a string.
275 STRING_ADD_RIGHT = function STRING_ADD_RIGHT(y) { 264 STRING_ADD_RIGHT = function STRING_ADD_RIGHT(y) {
276 var x = this; 265 var x = this;
277 if (!IS_STRING(x)) { 266 if (!IS_STRING(x)) {
278 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) { 267 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) {
279 x = %_ValueOf(x); 268 x = %_ValueOf(x);
280 } else { 269 } else {
281 x = IS_NUMBER(x) 270 x = IS_NUMBER(x)
282 ? %_NumberToString(x) 271 ? %_NumberToString(x)
283 : %$toString(%$toPrimitive(x, NO_HINT)); 272 : %$toString(%$toPrimitive(x, NO_HINT));
284 } 273 }
285 } 274 }
286 return %_StringAdd(x, y); 275 return %_StringAdd(x, y);
287 } 276 }
288 277
289 278
290 // Right operand (y) is already a string.
291 STRING_ADD_RIGHT_STRONG = function STRING_ADD_RIGHT_STRONG(y) {
292 if (IS_STRING(this)) {
293 return %_StringAdd(this, y);
294 }
295 throw %MakeTypeError(kStrongImplicitConversion);
296 }
297
298
299 // ECMA-262, section 11.6.2, page 50. 279 // ECMA-262, section 11.6.2, page 50.
300 SUB = function SUB(y) { 280 SUB = function SUB(y) {
301 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 281 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this);
302 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 282 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
303 return %NumberSub(x, y); 283 return %NumberSub(x, y);
304 } 284 }
305 285
306 286
307 // Strong mode SUB throws if an implicit conversion would be performed 287 // Strong mode SUB throws if an implicit conversion would be performed
308 SUB_STRONG = function SUB_STRONG(y) { 288 SUB_STRONG = function SUB_STRONG(y) {
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 $toBoolean = ToBoolean; 935 $toBoolean = ToBoolean;
956 $toInteger = ToInteger; 936 $toInteger = ToInteger;
957 $toLength = ToLength; 937 $toLength = ToLength;
958 $toName = ToName; 938 $toName = ToName;
959 $toNumber = ToNumber; 939 $toNumber = ToNumber;
960 $toPositiveInteger = ToPositiveInteger; 940 $toPositiveInteger = ToPositiveInteger;
961 $toPrimitive = ToPrimitive; 941 $toPrimitive = ToPrimitive;
962 $toString = ToString; 942 $toString = ToString;
963 943
964 }) 944 })
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698