| 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 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 function FILTER_KEY(key) { | 398 function FILTER_KEY(key) { |
| 399 var string = %ToString(key); | 399 var string = %ToString(key); |
| 400 if (%HasProperty(this, string)) return string; | 400 if (%HasProperty(this, string)) return string; |
| 401 return 0; | 401 return 0; |
| 402 } | 402 } |
| 403 | 403 |
| 404 | 404 |
| 405 function CALL_NON_FUNCTION() { | 405 function CALL_NON_FUNCTION() { |
| 406 var delegate = %GetFunctionDelegate(this); | 406 var delegate = %GetFunctionDelegate(this); |
| 407 if (!IS_FUNCTION(delegate)) { | 407 if (!IS_FUNCTION(delegate)) { |
| 408 if (%IsJSFunctionProxy(this)) { | 408 throw %MakeTypeError('called_non_callable', [typeof this]); |
| 409 delegate = %GetCallTrap(this); | |
| 410 } else { | |
| 411 throw %MakeTypeError('called_non_callable', [typeof this]); | |
| 412 } | |
| 413 } | 409 } |
| 414 return delegate.apply(this, arguments); | 410 return delegate.apply(this, arguments); |
| 415 } | 411 } |
| 416 | 412 |
| 417 | 413 |
| 418 function CALL_NON_FUNCTION_AS_CONSTRUCTOR() { | 414 function CALL_NON_FUNCTION_AS_CONSTRUCTOR() { |
| 419 var delegate = %GetConstructorDelegate(this); | 415 var delegate = %GetConstructorDelegate(this); |
| 420 if (!IS_FUNCTION(delegate)) { | 416 if (!IS_FUNCTION(delegate)) { |
| 421 if (%IsJSFunctionProxy(this)) { | 417 throw %MakeTypeError('called_non_callable', [typeof this]); |
| 422 delegate = %GetConstructTrap(this); | |
| 423 } else { | |
| 424 throw %MakeTypeError('called_non_callable', [typeof this]); | |
| 425 } | |
| 426 } | 418 } |
| 427 return delegate.apply(this, arguments); | 419 return delegate.apply(this, arguments); |
| 428 } | 420 } |
| 429 | 421 |
| 430 | 422 |
| 431 function CALL_FUNCTION_PROXY() { | 423 function CALL_FUNCTION_PROXY() { |
| 432 var arity = %_ArgumentsLength() - 1; | 424 var arity = %_ArgumentsLength() - 1; |
| 433 var proxy = arguments[arity]; // The proxy comes in as an additional arg. | 425 var proxy = arguments[arity]; // The proxy comes in as an additional arg. |
| 434 var trap = %GetCallTrap(proxy); | 426 var trap = %GetCallTrap(proxy); |
| 435 // TODO(rossberg): hm, shouldn't I be using $Function and friends? | 427 // TODO(rossberg): hm, shouldn't I be using $Function and friends? |
| 436 // But how do I get it in a builtin? | 428 // But how do I get it in a builtin? |
| 437 return global.Function.prototype.apply.call( | 429 return Function.prototype.apply.call( |
| 438 trap, this, global.Array.prototype.slice.call(arguments, 0, arity)); | 430 trap, this, Array.prototype.slice.call(arguments, 0, arity)); |
| 439 } | 431 } |
| 440 | 432 |
| 441 | 433 |
| 442 function CALL_FUNCTION_PROXY_AS_CONSTRUCTOR(proxy) { | 434 function CALL_FUNCTION_PROXY_AS_CONSTRUCTOR() { |
| 435 var proxy = this; |
| 443 var trap = %GetConstructTrap(proxy); | 436 var trap = %GetConstructTrap(proxy); |
| 444 var receiver = void 0; | 437 // TODO(rossberg): should be using $Function or a builtin somehow. |
| 445 if (!IS_UNDEFINED(trap)) { | 438 return Function.prototype.apply.call(trap, this, arguments); |
| 446 trap = %GetCallTrap(proxy); | |
| 447 var proto = proxy.prototype; | |
| 448 if (!IS_SPEC_OBJECT(proto) && proto !== null) { | |
| 449 throw MakeTypeError("proto_object_or_null", [proto]); | |
| 450 } | |
| 451 receiver = new global.Object(); | |
| 452 receiver.__proto__ = proto; | |
| 453 } | |
| 454 return global.Function.prototype.apply.call( | |
| 455 trap, this, global.Array.prototype.shift.call(arguments)); | |
| 456 } | 439 } |
| 457 | 440 |
| 458 | 441 |
| 459 function APPLY_PREPARE(args) { | 442 function APPLY_PREPARE(args) { |
| 460 var length; | 443 var length; |
| 461 // First check whether length is a positive Smi and args is an | 444 // First check whether length is a positive Smi and args is an |
| 462 // array. This is the fast case. If this fails, we do the slow case | 445 // array. This is the fast case. If this fails, we do the slow case |
| 463 // that takes care of more eventualities. | 446 // that takes care of more eventualities. |
| 464 if (IS_ARRAY(args)) { | 447 if (IS_ARRAY(args)) { |
| 465 length = args.length; | 448 length = args.length; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 throw %MakeTypeError('cannot_convert_to_primitive', []); | 660 throw %MakeTypeError('cannot_convert_to_primitive', []); |
| 678 } | 661 } |
| 679 | 662 |
| 680 | 663 |
| 681 // NOTE: Setting the prototype for Array must take place as early as | 664 // NOTE: Setting the prototype for Array must take place as early as |
| 682 // possible due to code generation for array literals. When | 665 // possible due to code generation for array literals. When |
| 683 // generating code for a array literal a boilerplate array is created | 666 // generating code for a array literal a boilerplate array is created |
| 684 // that is cloned when running the code. It is essential that the | 667 // that is cloned when running the code. It is essential that the |
| 685 // boilerplate gets the right prototype. | 668 // boilerplate gets the right prototype. |
| 686 %FunctionSetPrototype($Array, new $Array(0)); | 669 %FunctionSetPrototype($Array, new $Array(0)); |
| OLD | NEW |