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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 313 |
314 // ECMA-262, section 11.4.1, page 46. | 314 // ECMA-262, section 11.4.1, page 46. |
315 function DELETE(key, language_mode) { | 315 function DELETE(key, language_mode) { |
316 return %DeleteProperty(%ToObject(this), %ToName(key), language_mode); | 316 return %DeleteProperty(%ToObject(this), %ToName(key), language_mode); |
317 } | 317 } |
318 | 318 |
319 | 319 |
320 // ECMA-262, section 11.8.7, page 54. | 320 // ECMA-262, section 11.8.7, page 54. |
321 function IN(x) { | 321 function IN(x) { |
322 if (!IS_SPEC_OBJECT(x)) { | 322 if (!IS_SPEC_OBJECT(x)) { |
323 throw %MakeTypeError('invalid_in_operator_use', [this, x]); | 323 throw %MakeTypeError(kInvalidInOperatorUse, this, x); |
324 } | 324 } |
325 if (%_IsNonNegativeSmi(this)) { | 325 if (%_IsNonNegativeSmi(this)) { |
326 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) { | 326 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) { |
327 return this < x.length; | 327 return this < x.length; |
328 } | 328 } |
329 return %HasElement(x, this); | 329 return %HasElement(x, this); |
330 } | 330 } |
331 return %HasProperty(x, %ToName(this)); | 331 return %HasProperty(x, %ToName(this)); |
332 } | 332 } |
333 | 333 |
334 | 334 |
335 // ECMA-262, section 11.8.6, page 54. To make the implementation more | 335 // ECMA-262, section 11.8.6, page 54. To make the implementation more |
336 // efficient, the return value should be zero if the 'this' is an | 336 // efficient, the return value should be zero if the 'this' is an |
337 // instance of F, and non-zero if not. This makes it possible to avoid | 337 // instance of F, and non-zero if not. This makes it possible to avoid |
338 // an expensive ToBoolean conversion in the generated code. | 338 // an expensive ToBoolean conversion in the generated code. |
339 function INSTANCE_OF(F) { | 339 function INSTANCE_OF(F) { |
340 var V = this; | 340 var V = this; |
341 if (!IS_SPEC_FUNCTION(F)) { | 341 if (!IS_SPEC_FUNCTION(F)) { |
342 throw %MakeTypeError('instanceof_function_expected', [F]); | 342 throw %MakeTypeError(kInstanceofFunctionExpected, F); |
343 } | 343 } |
344 | 344 |
345 // If V is not an object, return false. | 345 // If V is not an object, return false. |
346 if (!IS_SPEC_OBJECT(V)) { | 346 if (!IS_SPEC_OBJECT(V)) { |
347 return 1; | 347 return 1; |
348 } | 348 } |
349 | 349 |
350 // Check if function is bound, if so, get [[BoundFunction]] from it | 350 // Check if function is bound, if so, get [[BoundFunction]] from it |
351 // and use that instead of F. | 351 // and use that instead of F. |
352 var bindings = %BoundFunctionGetBindings(F); | 352 var bindings = %BoundFunctionGetBindings(F); |
353 if (bindings) { | 353 if (bindings) { |
354 F = bindings[kBoundFunctionIndex]; // Always a non-bound function. | 354 F = bindings[kBoundFunctionIndex]; // Always a non-bound function. |
355 } | 355 } |
356 // Get the prototype of F; if it is not an object, throw an error. | 356 // Get the prototype of F; if it is not an object, throw an error. |
357 var O = F.prototype; | 357 var O = F.prototype; |
358 if (!IS_SPEC_OBJECT(O)) { | 358 if (!IS_SPEC_OBJECT(O)) { |
359 throw %MakeTypeError('instanceof_nonobject_proto', [O]); | 359 throw %MakeTypeError(kInstanceofNonobjectProto, O); |
360 } | 360 } |
361 | 361 |
362 // Return whether or not O is in the prototype chain of V. | 362 // Return whether or not O is in the prototype chain of V. |
363 return %IsInPrototypeChain(O, V) ? 0 : 1; | 363 return %IsInPrototypeChain(O, V) ? 0 : 1; |
364 } | 364 } |
365 | 365 |
366 | 366 |
367 // Filter a given key against an object by checking if the object | 367 // Filter a given key against an object by checking if the object |
368 // has a property with the given key; return the key as a string if | 368 // has a property with the given key; return the key as a string if |
369 // it has. Otherwise returns 0 (smi). Used in for-in statements. | 369 // it has. Otherwise returns 0 (smi). Used in for-in statements. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 IS_SPEC_FUNCTION(this)) { | 422 IS_SPEC_FUNCTION(this)) { |
423 return length; | 423 return length; |
424 } | 424 } |
425 } | 425 } |
426 | 426 |
427 length = (args == null) ? 0 : %ToUint32(args.length); | 427 length = (args == null) ? 0 : %ToUint32(args.length); |
428 | 428 |
429 // We can handle any number of apply arguments if the stack is | 429 // We can handle any number of apply arguments if the stack is |
430 // big enough, but sanity check the value to avoid overflow when | 430 // big enough, but sanity check the value to avoid overflow when |
431 // multiplying with pointer size. | 431 // multiplying with pointer size. |
432 if (length > kSafeArgumentsLength) { | 432 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); |
433 throw %MakeRangeError('stack_overflow', []); | |
434 } | |
435 | 433 |
436 if (!IS_SPEC_FUNCTION(this)) { | 434 if (!IS_SPEC_FUNCTION(this)) { |
437 throw %MakeTypeError('apply_non_function', | 435 throw %MakeTypeError(kApplyNonFunction, %ToString(this), typeof this); |
438 [ %ToString(this), typeof this ]); | |
439 } | 436 } |
440 | 437 |
441 // Make sure the arguments list has the right type. | 438 // Make sure the arguments list has the right type. |
442 if (args != null && !IS_SPEC_OBJECT(args)) { | 439 if (args != null && !IS_SPEC_OBJECT(args)) { |
443 throw %MakeTypeError('apply_wrong_args', []); | 440 throw %MakeTypeError(kWrongArgs, "Function.prototype.apply"); |
444 } | 441 } |
445 | 442 |
446 // Return the length which is the number of arguments to copy to the | 443 // Return the length which is the number of arguments to copy to the |
447 // stack. It is guaranteed to be a small integer at this point. | 444 // stack. It is guaranteed to be a small integer at this point. |
448 return length; | 445 return length; |
449 } | 446 } |
450 | 447 |
451 | 448 |
452 function REFLECT_APPLY_PREPARE(args) { | 449 function REFLECT_APPLY_PREPARE(args) { |
453 var length; | 450 var length; |
454 // First check whether length is a positive Smi and args is an | 451 // First check whether length is a positive Smi and args is an |
455 // array. This is the fast case. If this fails, we do the slow case | 452 // array. This is the fast case. If this fails, we do the slow case |
456 // that takes care of more eventualities. | 453 // that takes care of more eventualities. |
457 if (IS_ARRAY(args)) { | 454 if (IS_ARRAY(args)) { |
458 length = args.length; | 455 length = args.length; |
459 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && | 456 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && |
460 IS_SPEC_FUNCTION(this)) { | 457 IS_SPEC_FUNCTION(this)) { |
461 return length; | 458 return length; |
462 } | 459 } |
463 } | 460 } |
464 | 461 |
465 if (!IS_SPEC_FUNCTION(this)) { | 462 if (!IS_SPEC_FUNCTION(this)) { |
466 throw %MakeTypeError(kCalledNonCallable, %ToString(this)); | 463 throw %MakeTypeError(kCalledNonCallable, %ToString(this)); |
467 } | 464 } |
468 | 465 |
469 if (!IS_SPEC_OBJECT(args)) { | 466 if (!IS_SPEC_OBJECT(args)) { |
470 throw %MakeTypeError('reflect_apply_wrong_args', [ ]); | 467 throw %MakeTypeError(kWrongArgs, "Reflect.apply"); |
471 } | 468 } |
472 | 469 |
473 length = %ToLength(args.length); | 470 length = %ToLength(args.length); |
474 | 471 |
475 // We can handle any number of apply arguments if the stack is | 472 // We can handle any number of apply arguments if the stack is |
476 // big enough, but sanity check the value to avoid overflow when | 473 // big enough, but sanity check the value to avoid overflow when |
477 // multiplying with pointer size. | 474 // multiplying with pointer size. |
478 if (length > kSafeArgumentsLength) { | 475 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); |
479 throw %MakeRangeError('stack_overflow', []); | |
480 } | |
481 | 476 |
482 // Return the length which is the number of arguments to copy to the | 477 // Return the length which is the number of arguments to copy to the |
483 // stack. It is guaranteed to be a small integer at this point. | 478 // stack. It is guaranteed to be a small integer at this point. |
484 return length; | 479 return length; |
485 } | 480 } |
486 | 481 |
487 | 482 |
488 function REFLECT_CONSTRUCT_PREPARE(args, newTarget) { | 483 function REFLECT_CONSTRUCT_PREPARE(args, newTarget) { |
489 var length; | 484 var length; |
490 var ctorOk = IS_SPEC_FUNCTION(this) && %IsConstructor(this); | 485 var ctorOk = IS_SPEC_FUNCTION(this) && %IsConstructor(this); |
491 var newTargetOk = IS_SPEC_FUNCTION(newTarget) && %IsConstructor(newTarget); | 486 var newTargetOk = IS_SPEC_FUNCTION(newTarget) && %IsConstructor(newTarget); |
492 | 487 |
493 // First check whether length is a positive Smi and args is an | 488 // First check whether length is a positive Smi and args is an |
494 // array. This is the fast case. If this fails, we do the slow case | 489 // array. This is the fast case. If this fails, we do the slow case |
495 // that takes care of more eventualities. | 490 // that takes care of more eventualities. |
496 if (IS_ARRAY(args)) { | 491 if (IS_ARRAY(args)) { |
497 length = args.length; | 492 length = args.length; |
498 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && | 493 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && |
499 ctorOk && newTargetOk) { | 494 ctorOk && newTargetOk) { |
500 return length; | 495 return length; |
501 } | 496 } |
502 } | 497 } |
503 | 498 |
504 if (!ctorOk) { | 499 if (!ctorOk) { |
505 if (!IS_SPEC_FUNCTION(this)) { | 500 if (!IS_SPEC_FUNCTION(this)) { |
506 throw %MakeTypeError(kCalledNonCallable, %ToString(this)); | 501 throw %MakeTypeError(kCalledNonCallable, %ToString(this)); |
507 } else { | 502 } else { |
508 throw %MakeTypeError('not_constructor', [ %ToString(this) ]); | 503 throw %MakeTypeError(kNotConstructor, %ToString(this)); |
509 } | 504 } |
510 } | 505 } |
511 | 506 |
512 if (!newTargetOk) { | 507 if (!newTargetOk) { |
513 if (!IS_SPEC_FUNCTION(newTarget)) { | 508 if (!IS_SPEC_FUNCTION(newTarget)) { |
514 throw %MakeTypeError(kCalledNonCallable, %ToString(newTarget)); | 509 throw %MakeTypeError(kCalledNonCallable, %ToString(newTarget)); |
515 } else { | 510 } else { |
516 throw %MakeTypeError('not_constructor', [ %ToString(newTarget) ]); | 511 throw %MakeTypeError(kNotConstructor, %ToString(newTarget)); |
517 } | 512 } |
518 } | 513 } |
519 | 514 |
520 if (!IS_SPEC_OBJECT(args)) { | 515 if (!IS_SPEC_OBJECT(args)) { |
521 throw %MakeTypeError('reflect_construct_wrong_args', [ ]); | 516 throw %MakeTypeError(kWrongArgs, "Reflect.construct"); |
522 } | 517 } |
523 | 518 |
524 length = %ToLength(args.length); | 519 length = %ToLength(args.length); |
525 | 520 |
526 // We can handle any number of apply arguments if the stack is | 521 // We can handle any number of apply arguments if the stack is |
527 // big enough, but sanity check the value to avoid overflow when | 522 // big enough, but sanity check the value to avoid overflow when |
528 // multiplying with pointer size. | 523 // multiplying with pointer size. |
529 if (length > kSafeArgumentsLength) { | 524 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); |
530 throw %MakeRangeError('stack_overflow', []); | |
531 } | |
532 | 525 |
533 // Return the length which is the number of arguments to copy to the | 526 // Return the length which is the number of arguments to copy to the |
534 // stack. It is guaranteed to be a small integer at this point. | 527 // stack. It is guaranteed to be a small integer at this point. |
535 return length; | 528 return length; |
536 } | 529 } |
537 | 530 |
538 | 531 |
539 function STACK_OVERFLOW(length) { | 532 function STACK_OVERFLOW(length) { |
540 throw %MakeRangeError('stack_overflow', []); | 533 throw %MakeRangeError(kStackOverflow); |
541 } | 534 } |
542 | 535 |
543 | 536 |
544 // Convert the receiver to an object - forward to ToObject. | 537 // Convert the receiver to an object - forward to ToObject. |
545 function TO_OBJECT() { | 538 function TO_OBJECT() { |
546 return %ToObject(this); | 539 return %ToObject(this); |
547 } | 540 } |
548 | 541 |
549 | 542 |
550 // Convert the receiver to a number - forward to ToNumber. | 543 // Convert the receiver to a number - forward to ToNumber. |
(...skipping 19 matching lines...) Expand all Loading... |
570 ------------------------------------- | 563 ------------------------------------- |
571 */ | 564 */ |
572 | 565 |
573 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 566 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
574 // (1) for number hint, and (2) for string hint. | 567 // (1) for number hint, and (2) for string hint. |
575 function ToPrimitive(x, hint) { | 568 function ToPrimitive(x, hint) { |
576 // Fast case check. | 569 // Fast case check. |
577 if (IS_STRING(x)) return x; | 570 if (IS_STRING(x)) return x; |
578 // Normal behavior. | 571 // Normal behavior. |
579 if (!IS_SPEC_OBJECT(x)) return x; | 572 if (!IS_SPEC_OBJECT(x)) return x; |
580 if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError('symbol_to_primitive', []); | 573 if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError(kSymbolToPrimitive); |
581 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; | 574 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; |
582 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); | 575 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); |
583 } | 576 } |
584 | 577 |
585 | 578 |
586 // ECMA-262, section 9.2, page 30 | 579 // ECMA-262, section 9.2, page 30 |
587 function ToBoolean(x) { | 580 function ToBoolean(x) { |
588 if (IS_BOOLEAN(x)) return x; | 581 if (IS_BOOLEAN(x)) return x; |
589 if (IS_STRING(x)) return x.length != 0; | 582 if (IS_STRING(x)) return x.length != 0; |
590 if (x == null) return false; | 583 if (x == null) return false; |
591 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x)); | 584 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x)); |
592 return true; | 585 return true; |
593 } | 586 } |
594 | 587 |
595 | 588 |
596 // ECMA-262, section 9.3, page 31. | 589 // ECMA-262, section 9.3, page 31. |
597 function ToNumber(x) { | 590 function ToNumber(x) { |
598 if (IS_NUMBER(x)) return x; | 591 if (IS_NUMBER(x)) return x; |
599 if (IS_STRING(x)) { | 592 if (IS_STRING(x)) { |
600 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 593 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
601 : %StringToNumber(x); | 594 : %StringToNumber(x); |
602 } | 595 } |
603 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 596 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
604 if (IS_UNDEFINED(x)) return NAN; | 597 if (IS_UNDEFINED(x)) return NAN; |
605 if (IS_SYMBOL(x)) throw MakeTypeError('symbol_to_number', []); | 598 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); |
606 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 599 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
607 } | 600 } |
608 | 601 |
609 function NonNumberToNumber(x) { | 602 function NonNumberToNumber(x) { |
610 if (IS_STRING(x)) { | 603 if (IS_STRING(x)) { |
611 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 604 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
612 : %StringToNumber(x); | 605 : %StringToNumber(x); |
613 } | 606 } |
614 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 607 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
615 if (IS_UNDEFINED(x)) return NAN; | 608 if (IS_UNDEFINED(x)) return NAN; |
616 if (IS_SYMBOL(x)) throw MakeTypeError('symbol_to_number', []); | 609 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); |
617 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 610 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
618 } | 611 } |
619 | 612 |
620 | 613 |
621 // ECMA-262, section 9.8, page 35. | 614 // ECMA-262, section 9.8, page 35. |
622 function ToString(x) { | 615 function ToString(x) { |
623 if (IS_STRING(x)) return x; | 616 if (IS_STRING(x)) return x; |
624 if (IS_NUMBER(x)) return %_NumberToString(x); | 617 if (IS_NUMBER(x)) return %_NumberToString(x); |
625 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 618 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
626 if (IS_UNDEFINED(x)) return 'undefined'; | 619 if (IS_UNDEFINED(x)) return 'undefined'; |
627 if (IS_SYMBOL(x)) throw %MakeTypeError('symbol_to_string', []); | 620 if (IS_SYMBOL(x)) throw %MakeTypeError(kSymbolToString); |
628 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); | 621 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); |
629 } | 622 } |
630 | 623 |
631 function NonStringToString(x) { | 624 function NonStringToString(x) { |
632 if (IS_NUMBER(x)) return %_NumberToString(x); | 625 if (IS_NUMBER(x)) return %_NumberToString(x); |
633 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 626 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
634 if (IS_UNDEFINED(x)) return 'undefined'; | 627 if (IS_UNDEFINED(x)) return 'undefined'; |
635 if (IS_SYMBOL(x)) throw %MakeTypeError('symbol_to_string', []); | 628 if (IS_SYMBOL(x)) throw %MakeTypeError(kSymbolToString); |
636 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); | 629 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); |
637 } | 630 } |
638 | 631 |
639 | 632 |
640 // ES6 symbols | 633 // ES6 symbols |
641 function ToName(x) { | 634 function ToName(x) { |
642 return IS_SYMBOL(x) ? x : %ToString(x); | 635 return IS_SYMBOL(x) ? x : %ToString(x); |
643 } | 636 } |
644 | 637 |
645 | 638 |
646 // ECMA-262, section 9.9, page 36. | 639 // ECMA-262, section 9.9, page 36. |
647 function ToObject(x) { | 640 function ToObject(x) { |
648 if (IS_STRING(x)) return new $String(x); | 641 if (IS_STRING(x)) return new $String(x); |
649 if (IS_NUMBER(x)) return new $Number(x); | 642 if (IS_NUMBER(x)) return new $Number(x); |
650 if (IS_BOOLEAN(x)) return new $Boolean(x); | 643 if (IS_BOOLEAN(x)) return new $Boolean(x); |
651 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x); | 644 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x); |
652 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { | 645 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { |
653 throw %MakeTypeError('undefined_or_null_to_object', []); | 646 throw %MakeTypeError(kUndefinedOrNullToObject); |
654 } | 647 } |
655 return x; | 648 return x; |
656 } | 649 } |
657 | 650 |
658 | 651 |
659 // ECMA-262, section 9.4, page 34. | 652 // ECMA-262, section 9.4, page 34. |
660 function ToInteger(x) { | 653 function ToInteger(x) { |
661 if (%_IsSmi(x)) return x; | 654 if (%_IsSmi(x)) return x; |
662 return %NumberToInteger(ToNumber(x)); | 655 return %NumberToInteger(ToNumber(x)); |
663 } | 656 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 var v = %_CallFunction(x, valueOf); | 733 var v = %_CallFunction(x, valueOf); |
741 if (%IsPrimitive(v)) return v; | 734 if (%IsPrimitive(v)) return v; |
742 } | 735 } |
743 | 736 |
744 var toString = x.toString; | 737 var toString = x.toString; |
745 if (IS_SPEC_FUNCTION(toString)) { | 738 if (IS_SPEC_FUNCTION(toString)) { |
746 var s = %_CallFunction(x, toString); | 739 var s = %_CallFunction(x, toString); |
747 if (%IsPrimitive(s)) return s; | 740 if (%IsPrimitive(s)) return s; |
748 } | 741 } |
749 } | 742 } |
750 throw %MakeTypeError('cannot_convert_to_primitive', []); | 743 throw %MakeTypeError(kCannotConvertToPrimitive); |
751 } | 744 } |
752 | 745 |
753 // ECMA-262, section 8.6.2.6, page 28. | 746 // ECMA-262, section 8.6.2.6, page 28. |
754 function DefaultString(x) { | 747 function DefaultString(x) { |
755 if (!IS_SYMBOL_WRAPPER(x)) { | 748 if (!IS_SYMBOL_WRAPPER(x)) { |
756 var toString = x.toString; | 749 var toString = x.toString; |
757 if (IS_SPEC_FUNCTION(toString)) { | 750 if (IS_SPEC_FUNCTION(toString)) { |
758 var s = %_CallFunction(x, toString); | 751 var s = %_CallFunction(x, toString); |
759 if (%IsPrimitive(s)) return s; | 752 if (%IsPrimitive(s)) return s; |
760 } | 753 } |
761 | 754 |
762 var valueOf = x.valueOf; | 755 var valueOf = x.valueOf; |
763 if (IS_SPEC_FUNCTION(valueOf)) { | 756 if (IS_SPEC_FUNCTION(valueOf)) { |
764 var v = %_CallFunction(x, valueOf); | 757 var v = %_CallFunction(x, valueOf); |
765 if (%IsPrimitive(v)) return v; | 758 if (%IsPrimitive(v)) return v; |
766 } | 759 } |
767 } | 760 } |
768 throw %MakeTypeError('cannot_convert_to_primitive', []); | 761 throw %MakeTypeError(kCannotConvertToPrimitive); |
769 } | 762 } |
770 | 763 |
771 function ToPositiveInteger(x, rangeErrorName) { | 764 function ToPositiveInteger(x, rangeErrorName) { |
772 var i = TO_INTEGER_MAP_MINUS_ZERO(x); | 765 var i = TO_INTEGER_MAP_MINUS_ZERO(x); |
773 if (i < 0) throw MakeRangeError(rangeErrorName); | 766 if (i < 0) throw MakeRangeError(rangeErrorName); |
774 return i; | 767 return i; |
775 } | 768 } |
776 | 769 |
777 | 770 |
778 // NOTE: Setting the prototype for Array must take place as early as | 771 // NOTE: Setting the prototype for Array must take place as early as |
779 // possible due to code generation for array literals. When | 772 // possible due to code generation for array literals. When |
780 // generating code for a array literal a boilerplate array is created | 773 // generating code for a array literal a boilerplate array is created |
781 // that is cloned when running the code. It is essential that the | 774 // that is cloned when running the code. It is essential that the |
782 // boilerplate gets the right prototype. | 775 // boilerplate gets the right prototype. |
783 %FunctionSetPrototype($Array, new $Array(0)); | 776 %FunctionSetPrototype($Array, new $Array(0)); |
784 | 777 |
785 | 778 |
786 /* ----------------------------------------------- | 779 /* ----------------------------------------------- |
787 - - - J a v a S c r i p t S t u b s - - - | 780 - - - J a v a S c r i p t S t u b s - - - |
788 ----------------------------------------------- | 781 ----------------------------------------------- |
789 */ | 782 */ |
790 | 783 |
791 function STRING_LENGTH_STUB(name) { | 784 function STRING_LENGTH_STUB(name) { |
792 var receiver = this; // implicit first parameter | 785 var receiver = this; // implicit first parameter |
793 return %_StringGetLength(%_JSValueGetValue(receiver)); | 786 return %_StringGetLength(%_JSValueGetValue(receiver)); |
794 } | 787 } |
OLD | NEW |