| 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 417 } |
| 418 throw %make_type_error(kStrongImplicitConversion); | 418 throw %make_type_error(kStrongImplicitConversion); |
| 419 } | 419 } |
| 420 | 420 |
| 421 | 421 |
| 422 /* ----------------------------- | 422 /* ----------------------------- |
| 423 - - - H e l p e r s - - - | 423 - - - H e l p e r s - - - |
| 424 ----------------------------- | 424 ----------------------------- |
| 425 */ | 425 */ |
| 426 | 426 |
| 427 function CALL_NON_FUNCTION() { |
| 428 var delegate = %GetFunctionDelegate(this); |
| 429 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); |
| 430 } |
| 431 |
| 432 |
| 427 function CALL_NON_FUNCTION_AS_CONSTRUCTOR() { | 433 function CALL_NON_FUNCTION_AS_CONSTRUCTOR() { |
| 428 var delegate = %GetConstructorDelegate(this); | 434 var delegate = %GetConstructorDelegate(this); |
| 429 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); | 435 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); |
| 430 } | 436 } |
| 431 | 437 |
| 432 | 438 |
| 439 function CALL_FUNCTION_PROXY() { |
| 440 var arity = %_ArgumentsLength() - 1; |
| 441 var proxy = %_Arguments(arity); // The proxy comes in as an additional arg. |
| 442 var trap = %GetCallTrap(proxy); |
| 443 return %Apply(trap, this, arguments, 0, arity); |
| 444 } |
| 445 |
| 446 |
| 433 function CALL_FUNCTION_PROXY_AS_CONSTRUCTOR () { | 447 function CALL_FUNCTION_PROXY_AS_CONSTRUCTOR () { |
| 434 var proxy = this; | 448 var proxy = this; |
| 435 var trap = %GetConstructTrap(proxy); | 449 var trap = %GetConstructTrap(proxy); |
| 436 return %Apply(trap, this, arguments, 0, %_ArgumentsLength()); | 450 return %Apply(trap, this, arguments, 0, %_ArgumentsLength()); |
| 437 } | 451 } |
| 438 | 452 |
| 439 | 453 |
| 440 function APPLY_PREPARE(args) { | 454 function APPLY_PREPARE(args) { |
| 441 var length; | 455 var length; |
| 442 | |
| 443 // First check that the receiver is callable. | |
| 444 if (!IS_CALLABLE(this)) { | |
| 445 throw %make_type_error(kApplyNonFunction, %to_string_fun(this), | |
| 446 typeof this); | |
| 447 } | |
| 448 | |
| 449 // First check whether length is a positive Smi and args is an | 456 // First check whether length is a positive Smi and args is an |
| 450 // array. This is the fast case. If this fails, we do the slow case | 457 // array. This is the fast case. If this fails, we do the slow case |
| 451 // that takes care of more eventualities. | 458 // that takes care of more eventualities. |
| 452 if (IS_ARRAY(args)) { | 459 if (IS_ARRAY(args)) { |
| 453 length = args.length; | 460 length = args.length; |
| 454 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength) { | 461 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && |
| 462 IS_CALLABLE(this)) { |
| 455 return length; | 463 return length; |
| 456 } | 464 } |
| 457 } | 465 } |
| 458 | 466 |
| 459 length = (args == null) ? 0 : TO_UINT32(args.length); | 467 length = (args == null) ? 0 : TO_UINT32(args.length); |
| 460 | 468 |
| 461 // We can handle any number of apply arguments if the stack is | 469 // We can handle any number of apply arguments if the stack is |
| 462 // big enough, but sanity check the value to avoid overflow when | 470 // big enough, but sanity check the value to avoid overflow when |
| 463 // multiplying with pointer size. | 471 // multiplying with pointer size. |
| 464 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow); | 472 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow); |
| 465 | 473 |
| 474 if (!IS_CALLABLE(this)) { |
| 475 throw %make_type_error(kApplyNonFunction, %to_string_fun(this), |
| 476 typeof this); |
| 477 } |
| 478 |
| 466 // Make sure the arguments list has the right type. | 479 // Make sure the arguments list has the right type. |
| 467 if (args != null && !IS_SPEC_OBJECT(args)) { | 480 if (args != null && !IS_SPEC_OBJECT(args)) { |
| 468 throw %make_type_error(kWrongArgs, "Function.prototype.apply"); | 481 throw %make_type_error(kWrongArgs, "Function.prototype.apply"); |
| 469 } | 482 } |
| 470 | 483 |
| 471 // Return the length which is the number of arguments to copy to the | 484 // Return the length which is the number of arguments to copy to the |
| 472 // stack. It is guaranteed to be a small integer at this point. | 485 // stack. It is guaranteed to be a small integer at this point. |
| 473 return length; | 486 return length; |
| 474 } | 487 } |
| 475 | 488 |
| 476 | 489 |
| 477 function REFLECT_APPLY_PREPARE(args) { | 490 function REFLECT_APPLY_PREPARE(args) { |
| 478 var length; | 491 var length; |
| 479 | |
| 480 // First check that the receiver is callable. | |
| 481 if (!IS_CALLABLE(this)) { | |
| 482 throw %make_type_error(kApplyNonFunction, %to_string_fun(this), | |
| 483 typeof this); | |
| 484 } | |
| 485 | |
| 486 // First check whether length is a positive Smi and args is an | 492 // First check whether length is a positive Smi and args is an |
| 487 // array. This is the fast case. If this fails, we do the slow case | 493 // array. This is the fast case. If this fails, we do the slow case |
| 488 // that takes care of more eventualities. | 494 // that takes care of more eventualities. |
| 489 if (IS_ARRAY(args)) { | 495 if (IS_ARRAY(args)) { |
| 490 length = args.length; | 496 length = args.length; |
| 491 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength) { | 497 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && |
| 498 IS_CALLABLE(this)) { |
| 492 return length; | 499 return length; |
| 493 } | 500 } |
| 494 } | 501 } |
| 495 | 502 |
| 503 if (!IS_CALLABLE(this)) { |
| 504 throw %make_type_error(kCalledNonCallable, %to_string_fun(this)); |
| 505 } |
| 506 |
| 496 if (!IS_SPEC_OBJECT(args)) { | 507 if (!IS_SPEC_OBJECT(args)) { |
| 497 throw %make_type_error(kWrongArgs, "Reflect.apply"); | 508 throw %make_type_error(kWrongArgs, "Reflect.apply"); |
| 498 } | 509 } |
| 499 | 510 |
| 500 length = %to_length_fun(args.length); | 511 length = %to_length_fun(args.length); |
| 501 | 512 |
| 502 // We can handle any number of apply arguments if the stack is | 513 // We can handle any number of apply arguments if the stack is |
| 503 // big enough, but sanity check the value to avoid overflow when | 514 // big enough, but sanity check the value to avoid overflow when |
| 504 // multiplying with pointer size. | 515 // multiplying with pointer size. |
| 505 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow); | 516 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 "add_builtin", ADD, | 795 "add_builtin", ADD, |
| 785 "add_strong_builtin", ADD_STRONG, | 796 "add_strong_builtin", ADD_STRONG, |
| 786 "apply_prepare_builtin", APPLY_PREPARE, | 797 "apply_prepare_builtin", APPLY_PREPARE, |
| 787 "bit_and_builtin", BIT_AND, | 798 "bit_and_builtin", BIT_AND, |
| 788 "bit_and_strong_builtin", BIT_AND_STRONG, | 799 "bit_and_strong_builtin", BIT_AND_STRONG, |
| 789 "bit_or_builtin", BIT_OR, | 800 "bit_or_builtin", BIT_OR, |
| 790 "bit_or_strong_builtin", BIT_OR_STRONG, | 801 "bit_or_strong_builtin", BIT_OR_STRONG, |
| 791 "bit_xor_builtin", BIT_XOR, | 802 "bit_xor_builtin", BIT_XOR, |
| 792 "bit_xor_strong_builtin", BIT_XOR_STRONG, | 803 "bit_xor_strong_builtin", BIT_XOR_STRONG, |
| 793 "call_function_proxy_as_constructor_builtin", CALL_FUNCTION_PROXY_AS_CONSTRUCT
OR, | 804 "call_function_proxy_as_constructor_builtin", CALL_FUNCTION_PROXY_AS_CONSTRUCT
OR, |
| 805 "call_function_proxy_builtin", CALL_FUNCTION_PROXY, |
| 794 "call_non_function_as_constructor_builtin", CALL_NON_FUNCTION_AS_CONSTRUCTOR, | 806 "call_non_function_as_constructor_builtin", CALL_NON_FUNCTION_AS_CONSTRUCTOR, |
| 807 "call_non_function_builtin", CALL_NON_FUNCTION, |
| 795 "compare_builtin", COMPARE, | 808 "compare_builtin", COMPARE, |
| 796 "compare_strong_builtin", COMPARE_STRONG, | 809 "compare_strong_builtin", COMPARE_STRONG, |
| 797 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY, | 810 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY, |
| 798 "div_builtin", DIV, | 811 "div_builtin", DIV, |
| 799 "div_strong_builtin", DIV_STRONG, | 812 "div_strong_builtin", DIV_STRONG, |
| 800 "equals_builtin", EQUALS, | 813 "equals_builtin", EQUALS, |
| 801 "mod_builtin", MOD, | 814 "mod_builtin", MOD, |
| 802 "mod_strong_builtin", MOD_STRONG, | 815 "mod_strong_builtin", MOD_STRONG, |
| 803 "mul_builtin", MUL, | 816 "mul_builtin", MUL, |
| 804 "mul_strong_builtin", MUL_STRONG, | 817 "mul_strong_builtin", MUL_STRONG, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 830 | 843 |
| 831 utils.Export(function(to) { | 844 utils.Export(function(to) { |
| 832 to.ToBoolean = ToBoolean; | 845 to.ToBoolean = ToBoolean; |
| 833 to.ToLength = ToLength; | 846 to.ToLength = ToLength; |
| 834 to.ToNumber = ToNumber; | 847 to.ToNumber = ToNumber; |
| 835 to.ToPrimitive = ToPrimitive; | 848 to.ToPrimitive = ToPrimitive; |
| 836 to.ToString = ToString; | 849 to.ToString = ToString; |
| 837 }); | 850 }); |
| 838 | 851 |
| 839 }) | 852 }) |
| OLD | NEW |