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

Unified Diff: src/proxy.js

Issue 8139027: Version 3.6.5 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/property.h ('k') | src/regexp.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/proxy.js
===================================================================
--- src/proxy.js (revision 9531)
+++ src/proxy.js (working copy)
@@ -41,14 +41,20 @@
throw MakeTypeError("handler_non_object", ["create"])
if (!IS_SPEC_FUNCTION(callTrap))
throw MakeTypeError("trap_function_expected", ["createFunction", "call"])
+ var construct
if (IS_UNDEFINED(constructTrap)) {
- constructTrap = callTrap
- } else if (!IS_SPEC_FUNCTION(constructTrap)) {
+ construct = DerivedConstructTrap(callTrap)
+ } else if (IS_SPEC_FUNCTION(constructTrap)) {
+ construct = function() {
+ // Make sure the trap receives 'undefined' as this.
+ return %Apply(constructTrap, void 0, arguments, 0, %_ArgumentsLength());
+ }
+ } else {
throw MakeTypeError("trap_function_expected",
["createFunction", "construct"])
}
return %CreateJSFunctionProxy(
- handler, callTrap, constructTrap, $Function.prototype)
+ handler, callTrap, construct, $Function.prototype)
}
@@ -57,6 +63,17 @@
// Builtins
////////////////////////////////////////////////////////////////////////////////
+function DerivedConstructTrap(callTrap) {
+ return function() {
+ var proto = this.prototype
+ if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype
+ var obj = new $Object()
+ obj.__proto__ = proto
+ var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength());
+ return IS_SPEC_OBJECT(result) ? result : obj
+ }
+}
+
function DelegateCallAndConstruct(callTrap, constructTrap) {
return function() {
return %Apply(%_IsConstructCall() ? constructTrap : callTrap,
« no previous file with comments | « src/property.h ('k') | src/regexp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698