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 // 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 return %NumberAdd(%$toNumber(a), %$toNumber(b)); | 228 return %NumberAdd(%$toNumber(a), %$toNumber(b)); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 // Strong mode ADD throws if an implicit conversion would be performed | 233 // Strong mode ADD throws if an implicit conversion would be performed |
234 ADD_STRONG = function ADD_STRONG(x) { | 234 ADD_STRONG = function ADD_STRONG(x) { |
235 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); | 235 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); |
236 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); | 236 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); |
237 | 237 |
238 throw %MakeTypeError(kStrongImplicitCast); | 238 throw %MakeTypeError('strong_implicit_cast'); |
239 } | 239 } |
240 | 240 |
241 | 241 |
242 // Left operand (this) is already a string. | 242 // Left operand (this) is already a string. |
243 STRING_ADD_LEFT = function STRING_ADD_LEFT(y) { | 243 STRING_ADD_LEFT = function STRING_ADD_LEFT(y) { |
244 if (!IS_STRING(y)) { | 244 if (!IS_STRING(y)) { |
245 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) { | 245 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) { |
246 y = %_ValueOf(y); | 246 y = %_ValueOf(y); |
247 } else { | 247 } else { |
248 y = IS_NUMBER(y) | 248 y = IS_NUMBER(y) |
249 ? %_NumberToString(y) | 249 ? %_NumberToString(y) |
250 : %$toString(%$toPrimitive(y, NO_HINT)); | 250 : %$toString(%$toPrimitive(y, NO_HINT)); |
251 } | 251 } |
252 } | 252 } |
253 return %_StringAdd(this, y); | 253 return %_StringAdd(this, y); |
254 } | 254 } |
255 | 255 |
256 | 256 |
257 // Left operand (this) is already a string. | 257 // Left operand (this) is already a string. |
258 STRING_ADD_LEFT_STRONG = function STRING_ADD_LEFT_STRONG(y) { | 258 STRING_ADD_LEFT_STRONG = function STRING_ADD_LEFT_STRONG(y) { |
259 if (IS_STRING(y)) { | 259 if (IS_STRING(y)) { |
260 return %_StringAdd(this, y); | 260 return %_StringAdd(this, y); |
261 } | 261 } |
262 throw %MakeTypeError(kStrongImplicitCast); | 262 throw %MakeTypeError('strong_implicit_cast'); |
263 } | 263 } |
264 | 264 |
265 | 265 |
266 // Right operand (y) is already a string. | 266 // Right operand (y) is already a string. |
267 STRING_ADD_RIGHT = function STRING_ADD_RIGHT(y) { | 267 STRING_ADD_RIGHT = function STRING_ADD_RIGHT(y) { |
268 var x = this; | 268 var x = this; |
269 if (!IS_STRING(x)) { | 269 if (!IS_STRING(x)) { |
270 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) { | 270 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) { |
271 x = %_ValueOf(x); | 271 x = %_ValueOf(x); |
272 } else { | 272 } else { |
273 x = IS_NUMBER(x) | 273 x = IS_NUMBER(x) |
274 ? %_NumberToString(x) | 274 ? %_NumberToString(x) |
275 : %$toString(%$toPrimitive(x, NO_HINT)); | 275 : %$toString(%$toPrimitive(x, NO_HINT)); |
276 } | 276 } |
277 } | 277 } |
278 return %_StringAdd(x, y); | 278 return %_StringAdd(x, y); |
279 } | 279 } |
280 | 280 |
281 | 281 |
282 // Right operand (y) is already a string. | 282 // Right operand (y) is already a string. |
283 STRING_ADD_RIGHT_STRONG = function STRING_ADD_RIGHT_STRONG(y) { | 283 STRING_ADD_RIGHT_STRONG = function STRING_ADD_RIGHT_STRONG(y) { |
284 if (IS_STRING(this)) { | 284 if (IS_STRING(this)) { |
285 return %_StringAdd(this, y); | 285 return %_StringAdd(this, y); |
286 } | 286 } |
287 throw %MakeTypeError(kStrongImplicitCast); | 287 throw %MakeTypeError('strong_implicit_cast'); |
288 } | 288 } |
289 | 289 |
290 | 290 |
291 // ECMA-262, section 11.6.2, page 50. | 291 // ECMA-262, section 11.6.2, page 50. |
292 SUB = function SUB(y) { | 292 SUB = function SUB(y) { |
293 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 293 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); |
294 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 294 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
295 return %NumberSub(x, y); | 295 return %NumberSub(x, y); |
296 } | 296 } |
297 | 297 |
298 | 298 |
299 // Strong mode SUB throws if an implicit conversion would be performed | 299 // Strong mode SUB throws if an implicit conversion would be performed |
300 SUB_STRONG = function SUB_STRONG(y) { | 300 SUB_STRONG = function SUB_STRONG(y) { |
301 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 301 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
302 return %NumberSub(this, y); | 302 return %NumberSub(this, y); |
303 } | 303 } |
304 throw %MakeTypeError(kStrongImplicitCast); | 304 throw %MakeTypeError('strong_implicit_cast'); |
305 } | 305 } |
306 | 306 |
307 | 307 |
308 // ECMA-262, section 11.5.1, page 48. | 308 // ECMA-262, section 11.5.1, page 48. |
309 MUL = function MUL(y) { | 309 MUL = function MUL(y) { |
310 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 310 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); |
311 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 311 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
312 return %NumberMul(x, y); | 312 return %NumberMul(x, y); |
313 } | 313 } |
314 | 314 |
315 | 315 |
316 // Strong mode MUL throws if an implicit conversion would be performed | 316 // Strong mode MUL throws if an implicit conversion would be performed |
317 MUL_STRONG = function MUL_STRONG(y) { | 317 MUL_STRONG = function MUL_STRONG(y) { |
318 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 318 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
319 return %NumberMul(this, y); | 319 return %NumberMul(this, y); |
320 } | 320 } |
321 throw %MakeTypeError(kStrongImplicitCast); | 321 throw %MakeTypeError('strong_implicit_cast'); |
322 } | 322 } |
323 | 323 |
324 | 324 |
325 // ECMA-262, section 11.5.2, page 49. | 325 // ECMA-262, section 11.5.2, page 49. |
326 DIV = function DIV(y) { | 326 DIV = function DIV(y) { |
327 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 327 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); |
328 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 328 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
329 return %NumberDiv(x, y); | 329 return %NumberDiv(x, y); |
330 } | 330 } |
331 | 331 |
332 | 332 |
333 // Strong mode DIV throws if an implicit conversion would be performed | 333 // Strong mode DIV throws if an implicit conversion would be performed |
334 DIV_STRONG = function DIV_STRONG(y) { | 334 DIV_STRONG = function DIV_STRONG(y) { |
335 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 335 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
336 return %NumberDiv(this, y); | 336 return %NumberDiv(this, y); |
337 } | 337 } |
338 throw %MakeTypeError(kStrongImplicitCast); | 338 throw %MakeTypeError('strong_implicit_cast'); |
339 } | 339 } |
340 | 340 |
341 | 341 |
342 // ECMA-262, section 11.5.3, page 49. | 342 // ECMA-262, section 11.5.3, page 49. |
343 MOD = function MOD(y) { | 343 MOD = function MOD(y) { |
344 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 344 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); |
345 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 345 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
346 return %NumberMod(x, y); | 346 return %NumberMod(x, y); |
347 } | 347 } |
348 | 348 |
349 | 349 |
350 // Strong mode MOD throws if an implicit conversion would be performed | 350 // Strong mode MOD throws if an implicit conversion would be performed |
351 MOD_STRONG = function MOD_STRONG(y) { | 351 MOD_STRONG = function MOD_STRONG(y) { |
352 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 352 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
353 return %NumberMod(this, y); | 353 return %NumberMod(this, y); |
354 } | 354 } |
355 throw %MakeTypeError(kStrongImplicitCast); | 355 throw %MakeTypeError('strong_implicit_cast'); |
356 } | 356 } |
357 | 357 |
358 | 358 |
359 /* ------------------------------------------- | 359 /* ------------------------------------------- |
360 - - - B i t o p e r a t i o n s - - - | 360 - - - B i t o p e r a t i o n s - - - |
361 ------------------------------------------- | 361 ------------------------------------------- |
362 */ | 362 */ |
363 | 363 |
364 // ECMA-262, section 11.10, page 57. | 364 // ECMA-262, section 11.10, page 57. |
365 BIT_OR = function BIT_OR(y) { | 365 BIT_OR = function BIT_OR(y) { |
366 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 366 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); |
367 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 367 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
368 return %NumberOr(x, y); | 368 return %NumberOr(x, y); |
369 } | 369 } |
370 | 370 |
371 | 371 |
372 // Strong mode BIT_OR throws if an implicit conversion would be performed | 372 // Strong mode BIT_OR throws if an implicit conversion would be performed |
373 BIT_OR_STRONG = function BIT_OR_STRONG(y) { | 373 BIT_OR_STRONG = function BIT_OR_STRONG(y) { |
374 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 374 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
375 return %NumberOr(this, y); | 375 return %NumberOr(this, y); |
376 } | 376 } |
377 throw %MakeTypeError(kStrongImplicitCast); | 377 throw %MakeTypeError('strong_implicit_cast'); |
378 } | 378 } |
379 | 379 |
380 | 380 |
381 // ECMA-262, section 11.10, page 57. | 381 // ECMA-262, section 11.10, page 57. |
382 BIT_AND = function BIT_AND(y) { | 382 BIT_AND = function BIT_AND(y) { |
383 var x; | 383 var x; |
384 if (IS_NUMBER(this)) { | 384 if (IS_NUMBER(this)) { |
385 x = this; | 385 x = this; |
386 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 386 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
387 } else { | 387 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
398 } | 398 } |
399 return %NumberAnd(x, y); | 399 return %NumberAnd(x, y); |
400 } | 400 } |
401 | 401 |
402 | 402 |
403 // Strong mode BIT_AND throws if an implicit conversion would be performed | 403 // Strong mode BIT_AND throws if an implicit conversion would be performed |
404 BIT_AND_STRONG = function BIT_AND_STRONG(y) { | 404 BIT_AND_STRONG = function BIT_AND_STRONG(y) { |
405 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 405 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
406 return %NumberAnd(this, y); | 406 return %NumberAnd(this, y); |
407 } | 407 } |
408 throw %MakeTypeError(kStrongImplicitCast); | 408 throw %MakeTypeError('strong_implicit_cast'); |
409 } | 409 } |
410 | 410 |
411 | 411 |
412 // ECMA-262, section 11.10, page 57. | 412 // ECMA-262, section 11.10, page 57. |
413 BIT_XOR = function BIT_XOR(y) { | 413 BIT_XOR = function BIT_XOR(y) { |
414 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 414 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); |
415 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 415 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
416 return %NumberXor(x, y); | 416 return %NumberXor(x, y); |
417 } | 417 } |
418 | 418 |
419 | 419 |
420 // Strong mode BIT_XOR throws if an implicit conversion would be performed | 420 // Strong mode BIT_XOR throws if an implicit conversion would be performed |
421 BIT_XOR_STRONG = function BIT_XOR_STRONG(y) { | 421 BIT_XOR_STRONG = function BIT_XOR_STRONG(y) { |
422 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 422 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
423 return %NumberXor(this, y); | 423 return %NumberXor(this, y); |
424 } | 424 } |
425 throw %MakeTypeError(kStrongImplicitCast); | 425 throw %MakeTypeError('strong_implicit_cast'); |
426 } | 426 } |
427 | 427 |
428 | 428 |
429 // ECMA-262, section 11.7.1, page 51. | 429 // ECMA-262, section 11.7.1, page 51. |
430 SHL = function SHL(y) { | 430 SHL = function SHL(y) { |
431 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 431 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); |
432 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 432 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
433 return %NumberShl(x, y); | 433 return %NumberShl(x, y); |
434 } | 434 } |
435 | 435 |
436 | 436 |
437 // Strong mode SHL throws if an implicit conversion would be performed | 437 // Strong mode SHL throws if an implicit conversion would be performed |
438 SHL_STRONG = function SHL_STRONG(y) { | 438 SHL_STRONG = function SHL_STRONG(y) { |
439 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 439 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
440 return %NumberShl(this, y); | 440 return %NumberShl(this, y); |
441 } | 441 } |
442 throw %MakeTypeError(kStrongImplicitCast); | 442 throw %MakeTypeError('strong_implicit_cast'); |
443 } | 443 } |
444 | 444 |
445 | 445 |
446 // ECMA-262, section 11.7.2, page 51. | 446 // ECMA-262, section 11.7.2, page 51. |
447 SAR = function SAR(y) { | 447 SAR = function SAR(y) { |
448 var x; | 448 var x; |
449 if (IS_NUMBER(this)) { | 449 if (IS_NUMBER(this)) { |
450 x = this; | 450 x = this; |
451 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 451 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
452 } else { | 452 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
463 } | 463 } |
464 return %NumberSar(x, y); | 464 return %NumberSar(x, y); |
465 } | 465 } |
466 | 466 |
467 | 467 |
468 // Strong mode SAR throws if an implicit conversion would be performed | 468 // Strong mode SAR throws if an implicit conversion would be performed |
469 SAR_STRONG = function SAR_STRONG(y) { | 469 SAR_STRONG = function SAR_STRONG(y) { |
470 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 470 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
471 return %NumberSar(this, y); | 471 return %NumberSar(this, y); |
472 } | 472 } |
473 throw %MakeTypeError(kStrongImplicitCast); | 473 throw %MakeTypeError('strong_implicit_cast'); |
474 } | 474 } |
475 | 475 |
476 | 476 |
477 // ECMA-262, section 11.7.3, page 52. | 477 // ECMA-262, section 11.7.3, page 52. |
478 SHR = function SHR(y) { | 478 SHR = function SHR(y) { |
479 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 479 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); |
480 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 480 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); |
481 return %NumberShr(x, y); | 481 return %NumberShr(x, y); |
482 } | 482 } |
483 | 483 |
484 | 484 |
485 // Strong mode SHR throws if an implicit conversion would be performed | 485 // Strong mode SHR throws if an implicit conversion would be performed |
486 SHR_STRONG = function SHR_STRONG(y) { | 486 SHR_STRONG = function SHR_STRONG(y) { |
487 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 487 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
488 return %NumberShr(this, y); | 488 return %NumberShr(this, y); |
489 } | 489 } |
490 throw %MakeTypeError(kStrongImplicitCast); | 490 throw %MakeTypeError('strong_implicit_cast'); |
491 } | 491 } |
492 | 492 |
493 | 493 |
494 /* ----------------------------- | 494 /* ----------------------------- |
495 - - - H e l p e r s - - - | 495 - - - H e l p e r s - - - |
496 ----------------------------- | 496 ----------------------------- |
497 */ | 497 */ |
498 | 498 |
499 // ECMA-262, section 11.4.1, page 46. | 499 // ECMA-262, section 11.4.1, page 46. |
500 DELETE = function DELETE(key, language_mode) { | 500 DELETE = function DELETE(key, language_mode) { |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 $toLength = ToLength; | 991 $toLength = ToLength; |
992 $toName = ToName; | 992 $toName = ToName; |
993 $toNumber = ToNumber; | 993 $toNumber = ToNumber; |
994 $toObject = ToObject; | 994 $toObject = ToObject; |
995 $toPositiveInteger = ToPositiveInteger; | 995 $toPositiveInteger = ToPositiveInteger; |
996 $toPrimitive = ToPrimitive; | 996 $toPrimitive = ToPrimitive; |
997 $toString = ToString; | 997 $toString = ToString; |
998 $toUint32 = ToUint32; | 998 $toUint32 = ToUint32; |
999 | 999 |
1000 })(); | 1000 })(); |
OLD | NEW |