Index: test/mjsunit/harmony/proxies-function.js |
diff --git a/test/mjsunit/harmony/proxies-function.js b/test/mjsunit/harmony/proxies-function.js |
index 541bca8cc82258550e0ebb8310982357d3c35279..1bd094e98d0f8caae313893b0fbf06056812def1 100644 |
--- a/test/mjsunit/harmony/proxies-function.js |
+++ b/test/mjsunit/harmony/proxies-function.js |
@@ -46,48 +46,73 @@ var receiver |
function TestCall(isStrict, callTrap) { |
assertEquals(42, callTrap(5, 37)) |
- // TODO(rossberg): unrelated bug: this does not succeed for optimized code: |
- // assertEquals(isStrict ? undefined : global_object, receiver) |
+ assertEquals(isStrict ? undefined : global_object, receiver) |
var f = Proxy.createFunction({}, callTrap) |
receiver = 333 |
assertEquals(42, f(11, 31)) |
assertEquals(isStrict ? undefined : global_object, receiver) |
- var o = {} |
+ var o = {f: f} |
+ receiver = 333 |
+ assertEquals(42, o.f(10, 32)) |
+ assertSame(o, receiver) |
+ receiver = 333 |
+ assertEquals(42, o["f"](9, 33)) |
+ assertSame(o, receiver) |
+ receiver = 333 |
+ assertEquals(42, (1, o).f(8, 34)) |
+ assertSame(o, receiver) |
+ receiver = 333 |
+ assertEquals(42, (1, o)["f"](7, 35)) |
+ assertSame(o, receiver) |
+ receiver = 333 |
assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) |
- assertEquals(o, receiver) |
+ assertSame(o, receiver) |
+ receiver = 333 |
assertEquals(43, Function.prototype.call.call(f, null, 20, 23)) |
assertEquals(isStrict ? null : global_object, receiver) |
assertEquals(44, Function.prototype.call.call(f, 2, 21, 23)) |
assertEquals(2, receiver.valueOf()) |
receiver = 333 |
assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) |
- assertEquals(o, receiver) |
+ assertSame(o, receiver) |
var ff = Function.prototype.bind.call(f, o, 12) |
receiver = 333 |
assertEquals(42, ff(30)) |
- assertEquals(o, receiver) |
+ assertSame(o, receiver) |
receiver = 333 |
assertEquals(32, Function.prototype.apply.call(ff, {}, [20])) |
- assertEquals(o, receiver) |
+ assertSame(o, receiver) |
var f = CreateFrozen({}, callTrap) |
receiver = 333 |
assertEquals(42, f(11, 31)) |
- // TODO(rossberg): unrelated bug: this does not succeed for optimized code. |
- // assertEquals(isStrict ? undefined : global, receiver) |
+ assertEquals(isStrict ? undefined : global_object, receiver) |
+ var o = {f: f} |
+ receiver = 333 |
+ assertEquals(42, o.f(10, 32)) |
+ assertSame(o, receiver) |
+ receiver = 333 |
+ assertEquals(42, o["f"](9, 33)) |
+ assertSame(o, receiver) |
+ receiver = 333 |
+ assertEquals(42, (1, o).f(8, 34)) |
+ assertSame(o, receiver) |
+ receiver = 333 |
+ assertEquals(42, (1, o)["f"](7, 35)) |
+ assertSame(o, receiver) |
receiver = 333 |
assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) |
- assertEquals(o, receiver) |
+ assertSame(o, receiver) |
receiver = 333 |
assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) |
- assertEquals(o, receiver) |
+ assertSame(o, receiver) |
receiver = 333 |
assertEquals(42, ff(30)) |
- assertEquals(o, receiver) |
+ assertSame(o, receiver) |
receiver = 333 |
assertEquals(32, Function.prototype.apply.call(ff, {}, [20])) |
- assertEquals(o, receiver) |
+ assertSame(o, receiver) |
} |
TestCall(false, function(x, y) { |
@@ -113,14 +138,31 @@ TestCall(false, CreateFrozen({}, function(x, y) { |
})) |
+function TestCallIntrinsic(type, callTrap) { |
+ var f = Proxy.createFunction({}, callTrap) |
+ var x = f() |
+ assertTrue(typeof x == type) |
+} |
+ |
+TestCallIntrinsic("boolean", Boolean) |
+TestCallIntrinsic("number", Number) |
+TestCallIntrinsic("string", String) |
+TestCallIntrinsic("object", Object) |
+TestCallIntrinsic("function", Function) |
+ |
+ |
function TestCallThrow(callTrap) { |
var f = Proxy.createFunction({}, callTrap) |
assertThrows(function(){ f(11) }, "myexn") |
+ assertThrows(function(){ ({x: f}).x(11) }, "myexn") |
+ assertThrows(function(){ ({x: f})["x"](11) }, "myexn") |
assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") |
assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") |
var f = CreateFrozen({}, callTrap) |
assertThrows(function(){ f(11) }, "myexn") |
+ assertThrows(function(){ ({x: f}).x(11) }, "myexn") |
+ assertThrows(function(){ ({x: f})["x"](11) }, "myexn") |
assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") |
assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") |
} |
@@ -165,15 +207,13 @@ function TestConstruct(proto, constructTrap) { |
function TestConstruct2(proto, constructTrap, handler) { |
var f = Proxy.createFunction(handler, function() {}, constructTrap) |
var o = new f(11, 31) |
- // TODO(rossberg): doesn't hold, due to unrelated bug. |
- // assertEquals(undefined, receiver) |
+ assertEquals(undefined, receiver) |
assertEquals(42, o.sum) |
assertSame(proto, Object.getPrototypeOf(o)) |
var f = CreateFrozen(handler, function() {}, constructTrap) |
var o = new f(11, 32) |
- // TODO(rossberg): doesn't hold, due to unrelated bug. |
- // assertEquals(undefined, receiver) |
+ assertEquals(undefined, receiver) |
assertEquals(43, o.sum) |
assertSame(proto, Object.getPrototypeOf(o)) |
} |