Commit 46dde044 authored by rossberg@chromium.org's avatar rossberg@chromium.org

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

R=mstarzinger@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/8271005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9761 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 70dc2fe9
...@@ -185,6 +185,7 @@ function FormatMessage(message) { ...@@ -185,6 +185,7 @@ function FormatMessage(message) {
"define_disallowed", ["Cannot define property:", "%0", ", object is not extensible."], "define_disallowed", ["Cannot define property:", "%0", ", object is not extensible."],
"non_extensible_proto", ["%0", " is not extensible"], "non_extensible_proto", ["%0", " is not extensible"],
"handler_non_object", ["Proxy.", "%0", " called with non-object as handler"], "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"], "trap_function_expected", ["Proxy.", "%0", " called with non-function for '", "%1", "' trap"],
"handler_trap_missing", ["Proxy handler ", "%0", " has no '", "%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"], "handler_trap_must_be_callable", ["Proxy handler ", "%0", " has non-callable '", "%1", "' trap"],
......
...@@ -32,7 +32,10 @@ var $Proxy = global.Proxy ...@@ -32,7 +32,10 @@ var $Proxy = global.Proxy
$Proxy.create = function(handler, proto) { $Proxy.create = function(handler, proto) {
if (!IS_SPEC_OBJECT(handler)) if (!IS_SPEC_OBJECT(handler))
throw MakeTypeError("handler_non_object", ["create"]) 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) return %CreateJSProxy(handler, proto)
} }
...@@ -41,20 +44,20 @@ $Proxy.createFunction = function(handler, callTrap, constructTrap) { ...@@ -41,20 +44,20 @@ $Proxy.createFunction = function(handler, callTrap, constructTrap) {
throw MakeTypeError("handler_non_object", ["create"]) throw MakeTypeError("handler_non_object", ["create"])
if (!IS_SPEC_FUNCTION(callTrap)) if (!IS_SPEC_FUNCTION(callTrap))
throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) throw MakeTypeError("trap_function_expected", ["createFunction", "call"])
var construct
if (IS_UNDEFINED(constructTrap)) { if (IS_UNDEFINED(constructTrap)) {
construct = DerivedConstructTrap(callTrap) constructTrap = DerivedConstructTrap(callTrap)
} else if (IS_SPEC_FUNCTION(constructTrap)) { } else if (IS_SPEC_FUNCTION(constructTrap)) {
construct = function() { // Make sure the trap receives 'undefined' as this.
// Make sure the trap receives 'undefined' as this. var construct = constructTrap
return %Apply(constructTrap, void 0, arguments, 0, %_ArgumentsLength()); constructTrap = function() {
return %Apply(construct, void 0, arguments, 0, %_ArgumentsLength());
} }
} else { } else {
throw MakeTypeError("trap_function_expected", throw MakeTypeError("trap_function_expected",
["createFunction", "construct"]) ["createFunction", "construct"])
} }
return %CreateJSFunctionProxy( return %CreateJSFunctionProxy(
handler, callTrap, construct, $Function.prototype) handler, callTrap, constructTrap, $Function.prototype)
} }
......
...@@ -286,24 +286,11 @@ function TestConstruct2(proto, constructTrap, handler) { ...@@ -286,24 +286,11 @@ function TestConstruct2(proto, constructTrap, handler) {
assertEquals(42, o.sum) assertEquals(42, o.sum)
assertSame(proto, Object.getPrototypeOf(o)) assertSame(proto, Object.getPrototypeOf(o))
// TODO(rossberg): does not work yet.
// var ff = Function.prototype.bind.call(f, o, 10)
// var o = new ff(32)
// assertEquals(undefined, receiver)
// assertEquals(42, o.sum)
// assertSame(proto, Object.getPrototypeOf(o))
var f = CreateFrozen(handler, function() {}, constructTrap) var f = CreateFrozen(handler, function() {}, constructTrap)
var o = new f(11, 32) var o = new f(11, 32)
assertEquals(undefined, receiver) assertEquals(undefined, receiver)
assertEquals(43, o.sum) assertEquals(43, o.sum)
assertSame(proto, Object.getPrototypeOf(o)) assertSame(proto, Object.getPrototypeOf(o))
var ff = Function.prototype.bind.call(f, o, 10)
var o = new ff(32)
assertEquals(undefined, receiver)
assertEquals(42, o.sum)
assertSame(proto, Object.getPrototypeOf(o))
} }
TestConstruct(Object.prototype, ReturnNew) TestConstruct(Object.prototype, ReturnNew)
...@@ -331,25 +318,11 @@ function TestConstructFromCall2(proto, returnsThis, callTrap, handler) { ...@@ -331,25 +318,11 @@ function TestConstructFromCall2(proto, returnsThis, callTrap, handler) {
assertEquals(42, o.sum) assertEquals(42, o.sum)
assertSame(proto, Object.getPrototypeOf(o)) assertSame(proto, Object.getPrototypeOf(o))
// TODO(rossberg): does not work yet.
// var ff = Function.prototype.bind.call(f, o, 10)
// var o = new ff(32)
// assertEquals(undefined, receiver)
// assertEquals(42, o.sum)
// assertSame(proto, Object.getPrototypeOf(o))
var f = CreateFrozen(handler, callTrap) var f = CreateFrozen(handler, callTrap)
var o = new f(11, 32) var o = new f(11, 32)
if (returnsThis) assertEquals(o, receiver) if (returnsThis) assertEquals(o, receiver)
assertEquals(43, o.sum) assertEquals(43, o.sum)
assertSame(proto, Object.getPrototypeOf(o)) assertSame(proto, Object.getPrototypeOf(o))
// TODO(rossberg): does not work yet.
// var ff = Function.prototype.bind.call(f, o, 10)
// var o = new ff(32)
// assertEquals(undefined, receiver)
// assertEquals(42, o.sum)
// assertSame(proto, Object.getPrototypeOf(o))
} }
TestConstructFromCall(Object.prototype, true, ReturnUndef) TestConstructFromCall(Object.prototype, true, ReturnUndef)
......
...@@ -1464,7 +1464,7 @@ function TestPrototype() { ...@@ -1464,7 +1464,7 @@ function TestPrototype() {
var p1 = Proxy.create({}) var p1 = Proxy.create({})
var p2 = Proxy.create({}, o1) var p2 = Proxy.create({}, o1)
var p3 = Proxy.create({}, p2) var p3 = Proxy.create({}, p2)
var p4 = Proxy.create({}, 666) var p4 = Proxy.create({}, null)
var o2 = Object.create(p3) var o2 = Object.create(p3)
assertSame(Object.getPrototypeOf(o1), Object.prototype) assertSame(Object.getPrototypeOf(o1), Object.prototype)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment