Reviewers: Michael Starzinger,

Description:
Adapt to latest spec changes for Proxy.create[Function].

[email protected]
BUG=
TEST=


Please review this at http://codereview.chromium.org/8271005/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/messages.js
  M src/proxy.js
  M test/mjsunit/harmony/proxies.js


Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index be236a4a34a95bd4ccd31bfcabfb437d87df2b3f..7adb6b10126b2f28617d324ffacae64d19c65ae9 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -185,6 +185,7 @@ function FormatMessage(message) {
"define_disallowed", ["Cannot define property:", "%0", ", object is not extensible."],
       "non_extensible_proto",         ["%0", " is not extensible"],
"handler_non_object", ["Proxy.", "%0", " called with non-object as handler"], + "proto_non_object", ["Proxy.", "%0", " called with non-object as prototype"], "trap_function_expected", ["Proxy.", "%0", " called with non-function for '", "%1", "' trap"], "handler_trap_missing", ["Proxy handler ", "%0", " has no '", "%1", "' trap"], "handler_trap_must_be_callable", ["Proxy handler ", "%0", " has non-callable '", "%1", "' trap"],
Index: src/proxy.js
diff --git a/src/proxy.js b/src/proxy.js
index a51f09ae50ff3eee75840e970413ddd75909d9a9..d93b58ac6a4b9e281347b733a0a98eca9b630d9d 100644
--- a/src/proxy.js
+++ b/src/proxy.js
@@ -32,7 +32,10 @@ var $Proxy = global.Proxy
 $Proxy.create = function(handler, proto) {
   if (!IS_SPEC_OBJECT(handler))
     throw MakeTypeError("handler_non_object", ["create"])
-  if (!IS_SPEC_OBJECT(proto)) proto = null  // Mozilla does this...
+  if (IS_UNDEFINED(proto))
+    proto = null
+  else if (!(IS_SPEC_OBJECT(proto) || proto === null))
+    throw MakeTypeError("proto_non_object", ["create"])
   return %CreateJSProxy(handler, proto)
 }

@@ -43,18 +46,13 @@ $Proxy.createFunction = function(handler, callTrap, constructTrap) { throw MakeTypeError("trap_function_expected", ["createFunction", "call"])
   var construct
   if (IS_UNDEFINED(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 {
+    constructTrap = DerivedConstructTrap(callTrap)
+  } else if (!IS_SPEC_FUNCTION(constructTrap)) {
     throw MakeTypeError("trap_function_expected",
                         ["createFunction", "construct"])
   }
   return %CreateJSFunctionProxy(
-    handler, callTrap, construct, $Function.prototype)
+    handler, callTrap, constructTrap, $Function.prototype)
 }


Index: test/mjsunit/harmony/proxies.js
diff --git a/test/mjsunit/harmony/proxies.js b/test/mjsunit/harmony/proxies.js index ad8d86a5dd26acf26629f0d4ef2a1a72deb1a635..3d17e9f4b8779e34b41be79e127af27b2dbfb90f 100644
--- a/test/mjsunit/harmony/proxies.js
+++ b/test/mjsunit/harmony/proxies.js
@@ -1468,7 +1468,7 @@ function TestPrototype() {
   var p1 = Proxy.create({})
   var p2 = Proxy.create({}, o1)
   var p3 = Proxy.create({}, p2)
-  var p4 = Proxy.create({}, 666)
+  var p4 = Proxy.create({}, null)
   var o2 = Object.create(p3)

   assertSame(Object.getPrototypeOf(o1), Object.prototype)


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to