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

Side by Side Diff: src/runtime.js

Issue 1216463003: [strong] Implement strong mode semantics for the count operation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cl feedback + eliminate runtime check Created 5 years, 5 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/ppc/full-codegen-ppc.cc ('k') | src/runtime/runtime.h » ('j') | 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
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr; 204 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr;
205 return %NumberCompare(left_number, right_number, ncr); 205 return %NumberCompare(left_number, right_number, ncr);
206 } 206 }
207 } 207 }
208 208
209 // Strong mode COMPARE throws if an implicit conversion would be performed 209 // Strong mode COMPARE throws if an implicit conversion would be performed
210 COMPARE_STRONG = function COMPARE_STRONG(x, ncr) { 210 COMPARE_STRONG = function COMPARE_STRONG(x, ncr) {
211 if (IS_STRING(this) && IS_STRING(x)) return %_StringCompare(this, x); 211 if (IS_STRING(this) && IS_STRING(x)) return %_StringCompare(this, x);
212 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberCompare(this, x, ncr); 212 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
213 213
214 throw %MakeTypeError(kStrongImplicitCast); 214 throw %MakeTypeError(kStrongImplicitConversion);
215 } 215 }
216 216
217 217
218 218
219 /* ----------------------------------- 219 /* -----------------------------------
220 - - - A r i t h m e t i c - - - 220 - - - A r i t h m e t i c - - -
221 ----------------------------------- 221 -----------------------------------
222 */ 222 */
223 223
224 // ECMA-262, section 11.6.1, page 50. 224 // ECMA-262, section 11.6.1, page 50.
(...skipping 14 matching lines...) Expand all
239 return %NumberAdd(%$toNumber(a), %$toNumber(b)); 239 return %NumberAdd(%$toNumber(a), %$toNumber(b));
240 } 240 }
241 } 241 }
242 242
243 243
244 // Strong mode ADD throws if an implicit conversion would be performed 244 // Strong mode ADD throws if an implicit conversion would be performed
245 ADD_STRONG = function ADD_STRONG(x) { 245 ADD_STRONG = function ADD_STRONG(x) {
246 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); 246 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x);
247 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); 247 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x);
248 248
249 throw %MakeTypeError(kStrongImplicitCast); 249 throw %MakeTypeError(kStrongImplicitConversion);
250 } 250 }
251 251
252 252
253 // Left operand (this) is already a string. 253 // Left operand (this) is already a string.
254 STRING_ADD_LEFT = function STRING_ADD_LEFT(y) { 254 STRING_ADD_LEFT = function STRING_ADD_LEFT(y) {
255 if (!IS_STRING(y)) { 255 if (!IS_STRING(y)) {
256 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) { 256 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) {
257 y = %_ValueOf(y); 257 y = %_ValueOf(y);
258 } else { 258 } else {
259 y = IS_NUMBER(y) 259 y = IS_NUMBER(y)
260 ? %_NumberToString(y) 260 ? %_NumberToString(y)
261 : %$toString(%$toPrimitive(y, NO_HINT)); 261 : %$toString(%$toPrimitive(y, NO_HINT));
262 } 262 }
263 } 263 }
264 return %_StringAdd(this, y); 264 return %_StringAdd(this, y);
265 } 265 }
266 266
267 267
268 // Left operand (this) is already a string. 268 // Left operand (this) is already a string.
269 STRING_ADD_LEFT_STRONG = function STRING_ADD_LEFT_STRONG(y) { 269 STRING_ADD_LEFT_STRONG = function STRING_ADD_LEFT_STRONG(y) {
270 if (IS_STRING(y)) { 270 if (IS_STRING(y)) {
271 return %_StringAdd(this, y); 271 return %_StringAdd(this, y);
272 } 272 }
273 throw %MakeTypeError(kStrongImplicitCast); 273 throw %MakeTypeError(kStrongImplicitConversion);
274 } 274 }
275 275
276 276
277 // Right operand (y) is already a string. 277 // Right operand (y) is already a string.
278 STRING_ADD_RIGHT = function STRING_ADD_RIGHT(y) { 278 STRING_ADD_RIGHT = function STRING_ADD_RIGHT(y) {
279 var x = this; 279 var x = this;
280 if (!IS_STRING(x)) { 280 if (!IS_STRING(x)) {
281 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) { 281 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) {
282 x = %_ValueOf(x); 282 x = %_ValueOf(x);
283 } else { 283 } else {
284 x = IS_NUMBER(x) 284 x = IS_NUMBER(x)
285 ? %_NumberToString(x) 285 ? %_NumberToString(x)
286 : %$toString(%$toPrimitive(x, NO_HINT)); 286 : %$toString(%$toPrimitive(x, NO_HINT));
287 } 287 }
288 } 288 }
289 return %_StringAdd(x, y); 289 return %_StringAdd(x, y);
290 } 290 }
291 291
292 292
293 // Right operand (y) is already a string. 293 // Right operand (y) is already a string.
294 STRING_ADD_RIGHT_STRONG = function STRING_ADD_RIGHT_STRONG(y) { 294 STRING_ADD_RIGHT_STRONG = function STRING_ADD_RIGHT_STRONG(y) {
295 if (IS_STRING(this)) { 295 if (IS_STRING(this)) {
296 return %_StringAdd(this, y); 296 return %_StringAdd(this, y);
297 } 297 }
298 throw %MakeTypeError(kStrongImplicitCast); 298 throw %MakeTypeError(kStrongImplicitConversion);
299 } 299 }
300 300
301 301
302 // ECMA-262, section 11.6.2, page 50. 302 // ECMA-262, section 11.6.2, page 50.
303 SUB = function SUB(y) { 303 SUB = function SUB(y) {
304 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 304 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this);
305 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 305 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
306 return %NumberSub(x, y); 306 return %NumberSub(x, y);
307 } 307 }
308 308
309 309
310 // Strong mode SUB throws if an implicit conversion would be performed 310 // Strong mode SUB throws if an implicit conversion would be performed
311 SUB_STRONG = function SUB_STRONG(y) { 311 SUB_STRONG = function SUB_STRONG(y) {
312 if (IS_NUMBER(this) && IS_NUMBER(y)) { 312 if (IS_NUMBER(this) && IS_NUMBER(y)) {
313 return %NumberSub(this, y); 313 return %NumberSub(this, y);
314 } 314 }
315 throw %MakeTypeError(kStrongImplicitCast); 315 throw %MakeTypeError(kStrongImplicitConversion);
316 } 316 }
317 317
318 318
319 // ECMA-262, section 11.5.1, page 48. 319 // ECMA-262, section 11.5.1, page 48.
320 MUL = function MUL(y) { 320 MUL = function MUL(y) {
321 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 321 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this);
322 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 322 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
323 return %NumberMul(x, y); 323 return %NumberMul(x, y);
324 } 324 }
325 325
326 326
327 // Strong mode MUL throws if an implicit conversion would be performed 327 // Strong mode MUL throws if an implicit conversion would be performed
328 MUL_STRONG = function MUL_STRONG(y) { 328 MUL_STRONG = function MUL_STRONG(y) {
329 if (IS_NUMBER(this) && IS_NUMBER(y)) { 329 if (IS_NUMBER(this) && IS_NUMBER(y)) {
330 return %NumberMul(this, y); 330 return %NumberMul(this, y);
331 } 331 }
332 throw %MakeTypeError(kStrongImplicitCast); 332 throw %MakeTypeError(kStrongImplicitConversion);
333 } 333 }
334 334
335 335
336 // ECMA-262, section 11.5.2, page 49. 336 // ECMA-262, section 11.5.2, page 49.
337 DIV = function DIV(y) { 337 DIV = function DIV(y) {
338 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 338 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this);
339 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 339 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
340 return %NumberDiv(x, y); 340 return %NumberDiv(x, y);
341 } 341 }
342 342
343 343
344 // Strong mode DIV throws if an implicit conversion would be performed 344 // Strong mode DIV throws if an implicit conversion would be performed
345 DIV_STRONG = function DIV_STRONG(y) { 345 DIV_STRONG = function DIV_STRONG(y) {
346 if (IS_NUMBER(this) && IS_NUMBER(y)) { 346 if (IS_NUMBER(this) && IS_NUMBER(y)) {
347 return %NumberDiv(this, y); 347 return %NumberDiv(this, y);
348 } 348 }
349 throw %MakeTypeError(kStrongImplicitCast); 349 throw %MakeTypeError(kStrongImplicitConversion);
350 } 350 }
351 351
352 352
353 // ECMA-262, section 11.5.3, page 49. 353 // ECMA-262, section 11.5.3, page 49.
354 MOD = function MOD(y) { 354 MOD = function MOD(y) {
355 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 355 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this);
356 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 356 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
357 return %NumberMod(x, y); 357 return %NumberMod(x, y);
358 } 358 }
359 359
360 360
361 // Strong mode MOD throws if an implicit conversion would be performed 361 // Strong mode MOD throws if an implicit conversion would be performed
362 MOD_STRONG = function MOD_STRONG(y) { 362 MOD_STRONG = function MOD_STRONG(y) {
363 if (IS_NUMBER(this) && IS_NUMBER(y)) { 363 if (IS_NUMBER(this) && IS_NUMBER(y)) {
364 return %NumberMod(this, y); 364 return %NumberMod(this, y);
365 } 365 }
366 throw %MakeTypeError(kStrongImplicitCast); 366 throw %MakeTypeError(kStrongImplicitConversion);
367 } 367 }
368 368
369 369
370 /* ------------------------------------------- 370 /* -------------------------------------------
371 - - - B i t o p e r a t i o n s - - - 371 - - - B i t o p e r a t i o n s - - -
372 ------------------------------------------- 372 -------------------------------------------
373 */ 373 */
374 374
375 // ECMA-262, section 11.10, page 57. 375 // ECMA-262, section 11.10, page 57.
376 BIT_OR = function BIT_OR(y) { 376 BIT_OR = function BIT_OR(y) {
377 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 377 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this);
378 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 378 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
379 return %NumberOr(x, y); 379 return %NumberOr(x, y);
380 } 380 }
381 381
382 382
383 // Strong mode BIT_OR throws if an implicit conversion would be performed 383 // Strong mode BIT_OR throws if an implicit conversion would be performed
384 BIT_OR_STRONG = function BIT_OR_STRONG(y) { 384 BIT_OR_STRONG = function BIT_OR_STRONG(y) {
385 if (IS_NUMBER(this) && IS_NUMBER(y)) { 385 if (IS_NUMBER(this) && IS_NUMBER(y)) {
386 return %NumberOr(this, y); 386 return %NumberOr(this, y);
387 } 387 }
388 throw %MakeTypeError(kStrongImplicitCast); 388 throw %MakeTypeError(kStrongImplicitConversion);
389 } 389 }
390 390
391 391
392 // ECMA-262, section 11.10, page 57. 392 // ECMA-262, section 11.10, page 57.
393 BIT_AND = function BIT_AND(y) { 393 BIT_AND = function BIT_AND(y) {
394 var x; 394 var x;
395 if (IS_NUMBER(this)) { 395 if (IS_NUMBER(this)) {
396 x = this; 396 x = this;
397 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 397 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
398 } else { 398 } else {
(...skipping 10 matching lines...) Expand all
409 } 409 }
410 return %NumberAnd(x, y); 410 return %NumberAnd(x, y);
411 } 411 }
412 412
413 413
414 // Strong mode BIT_AND throws if an implicit conversion would be performed 414 // Strong mode BIT_AND throws if an implicit conversion would be performed
415 BIT_AND_STRONG = function BIT_AND_STRONG(y) { 415 BIT_AND_STRONG = function BIT_AND_STRONG(y) {
416 if (IS_NUMBER(this) && IS_NUMBER(y)) { 416 if (IS_NUMBER(this) && IS_NUMBER(y)) {
417 return %NumberAnd(this, y); 417 return %NumberAnd(this, y);
418 } 418 }
419 throw %MakeTypeError(kStrongImplicitCast); 419 throw %MakeTypeError(kStrongImplicitConversion);
420 } 420 }
421 421
422 422
423 // ECMA-262, section 11.10, page 57. 423 // ECMA-262, section 11.10, page 57.
424 BIT_XOR = function BIT_XOR(y) { 424 BIT_XOR = function BIT_XOR(y) {
425 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 425 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this);
426 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 426 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
427 return %NumberXor(x, y); 427 return %NumberXor(x, y);
428 } 428 }
429 429
430 430
431 // Strong mode BIT_XOR throws if an implicit conversion would be performed 431 // Strong mode BIT_XOR throws if an implicit conversion would be performed
432 BIT_XOR_STRONG = function BIT_XOR_STRONG(y) { 432 BIT_XOR_STRONG = function BIT_XOR_STRONG(y) {
433 if (IS_NUMBER(this) && IS_NUMBER(y)) { 433 if (IS_NUMBER(this) && IS_NUMBER(y)) {
434 return %NumberXor(this, y); 434 return %NumberXor(this, y);
435 } 435 }
436 throw %MakeTypeError(kStrongImplicitCast); 436 throw %MakeTypeError(kStrongImplicitConversion);
437 } 437 }
438 438
439 439
440 // ECMA-262, section 11.7.1, page 51. 440 // ECMA-262, section 11.7.1, page 51.
441 SHL = function SHL(y) { 441 SHL = function SHL(y) {
442 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 442 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this);
443 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 443 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
444 return %NumberShl(x, y); 444 return %NumberShl(x, y);
445 } 445 }
446 446
447 447
448 // Strong mode SHL throws if an implicit conversion would be performed 448 // Strong mode SHL throws if an implicit conversion would be performed
449 SHL_STRONG = function SHL_STRONG(y) { 449 SHL_STRONG = function SHL_STRONG(y) {
450 if (IS_NUMBER(this) && IS_NUMBER(y)) { 450 if (IS_NUMBER(this) && IS_NUMBER(y)) {
451 return %NumberShl(this, y); 451 return %NumberShl(this, y);
452 } 452 }
453 throw %MakeTypeError(kStrongImplicitCast); 453 throw %MakeTypeError(kStrongImplicitConversion);
454 } 454 }
455 455
456 456
457 // ECMA-262, section 11.7.2, page 51. 457 // ECMA-262, section 11.7.2, page 51.
458 SAR = function SAR(y) { 458 SAR = function SAR(y) {
459 var x; 459 var x;
460 if (IS_NUMBER(this)) { 460 if (IS_NUMBER(this)) {
461 x = this; 461 x = this;
462 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 462 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
463 } else { 463 } else {
(...skipping 10 matching lines...) Expand all
474 } 474 }
475 return %NumberSar(x, y); 475 return %NumberSar(x, y);
476 } 476 }
477 477
478 478
479 // Strong mode SAR throws if an implicit conversion would be performed 479 // Strong mode SAR throws if an implicit conversion would be performed
480 SAR_STRONG = function SAR_STRONG(y) { 480 SAR_STRONG = function SAR_STRONG(y) {
481 if (IS_NUMBER(this) && IS_NUMBER(y)) { 481 if (IS_NUMBER(this) && IS_NUMBER(y)) {
482 return %NumberSar(this, y); 482 return %NumberSar(this, y);
483 } 483 }
484 throw %MakeTypeError(kStrongImplicitCast); 484 throw %MakeTypeError(kStrongImplicitConversion);
485 } 485 }
486 486
487 487
488 // ECMA-262, section 11.7.3, page 52. 488 // ECMA-262, section 11.7.3, page 52.
489 SHR = function SHR(y) { 489 SHR = function SHR(y) {
490 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 490 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this);
491 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 491 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y);
492 return %NumberShr(x, y); 492 return %NumberShr(x, y);
493 } 493 }
494 494
495 495
496 // Strong mode SHR throws if an implicit conversion would be performed 496 // Strong mode SHR throws if an implicit conversion would be performed
497 SHR_STRONG = function SHR_STRONG(y) { 497 SHR_STRONG = function SHR_STRONG(y) {
498 if (IS_NUMBER(this) && IS_NUMBER(y)) { 498 if (IS_NUMBER(this) && IS_NUMBER(y)) {
499 return %NumberShr(this, y); 499 return %NumberShr(this, y);
500 } 500 }
501 throw %MakeTypeError(kStrongImplicitCast); 501 throw %MakeTypeError(kStrongImplicitConversion);
502 } 502 }
503 503
504 504
505 /* ----------------------------- 505 /* -----------------------------
506 - - - H e l p e r s - - - 506 - - - H e l p e r s - - -
507 ----------------------------- 507 -----------------------------
508 */ 508 */
509 509
510 // ECMA-262, section 11.4.1, page 46. 510 // ECMA-262, section 11.4.1, page 46.
511 DELETE = function DELETE(key, language_mode) { 511 DELETE = function DELETE(key, language_mode) {
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 $toLength = ToLength; 1041 $toLength = ToLength;
1042 $toName = ToName; 1042 $toName = ToName;
1043 $toNumber = ToNumber; 1043 $toNumber = ToNumber;
1044 $toObject = ToObject; 1044 $toObject = ToObject;
1045 $toPositiveInteger = ToPositiveInteger; 1045 $toPositiveInteger = ToPositiveInteger;
1046 $toPrimitive = ToPrimitive; 1046 $toPrimitive = ToPrimitive;
1047 $toString = ToString; 1047 $toString = ToString;
1048 $toUint32 = ToUint32; 1048 $toUint32 = ToUint32;
1049 1049
1050 }) 1050 })
OLDNEW
« no previous file with comments | « src/ppc/full-codegen-ppc.cc ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698