| Index: test/mjsunit/harmony/proxies.js
|
| diff --git a/test/mjsunit/harmony/proxies.js b/test/mjsunit/harmony/proxies.js
|
| index e49ea7fab8c304831523e1b926a32e83b46df296..d558b0b4ad4535a2489a06cb3ef3ca0170a71a0a 100644
|
| --- a/test/mjsunit/harmony/proxies.js
|
| +++ b/test/mjsunit/harmony/proxies.js
|
| @@ -35,8 +35,10 @@
|
| // Helper.
|
|
|
| function TestWithProxies(test, x, y, z) {
|
| - test(Proxy.create, x, y, z)
|
| - test(function(h) {return Proxy.createFunction(h, function() {})}, x, y, z)
|
| + test(function(handler) { return new Proxy({}, handler) }, x, y, z)
|
| + test(function(handler) {
|
| + return Proxy.createFunction(handler, function() {})
|
| + }, x, y, z)
|
| }
|
|
|
|
|
| @@ -81,7 +83,7 @@ TestGetOwnProperty({
|
| }
|
| })
|
|
|
| -TestGetOwnProperty(Proxy.create({
|
| +TestGetOwnProperty(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) { key = k; return {value: 42, configurable: true} }
|
| }
|
| @@ -115,7 +117,7 @@ TestGetOwnPropertyThrow({
|
| }
|
| })
|
|
|
| -TestGetOwnPropertyThrow(Proxy.create({
|
| +TestGetOwnPropertyThrow(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) { throw "myexn" }
|
| }
|
| @@ -190,7 +192,7 @@ TestGet({
|
| getPropertyDescriptor: function(k) { key = k; return {value: 42} }
|
| })
|
|
|
| -TestGet(Proxy.create({
|
| +TestGet(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(r, k) { key = k; return 42 }
|
| }
|
| @@ -287,7 +289,7 @@ TestGetCall({
|
| }
|
| })
|
|
|
| -TestGetCall(Proxy.create({
|
| +TestGetCall(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(r, k) { return function() { return 55 } }
|
| }
|
| @@ -343,11 +345,11 @@ TestGetThrow({
|
| getPropertyDescriptor: function(k) { throw "myexn" }
|
| })
|
|
|
| -TestGetThrow(Proxy.create({
|
| +TestGetThrow(new Proxy({}, {
|
| get: function(pr, pk) { throw "myexn" }
|
| }))
|
|
|
| -TestGetThrow(Proxy.create({
|
| +TestGetThrow(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(r, k) { throw "myexn" }
|
| }
|
| @@ -451,7 +453,7 @@ TestSet({
|
| defineProperty: function(k, desc) { key = k, val = desc.value }
|
| })
|
|
|
| -TestSet(Proxy.create({
|
| +TestSet(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(r, k, v) { key = k; val = v; return true }
|
| }
|
| @@ -569,11 +571,11 @@ TestSetThrow({
|
| defineProperty: function(k, desc) { throw "myexn" }
|
| })
|
|
|
| -TestSetThrow(Proxy.create({
|
| +TestSetThrow(new Proxy({}, {
|
| get: function(pr, pk) { throw "myexn" }
|
| }))
|
|
|
| -TestSetThrow(Proxy.create({
|
| +TestSetThrow(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(r, k, v) { throw "myexn" }
|
| }
|
| @@ -816,7 +818,7 @@ TestDefine({
|
| defineProperty2: function(k, d) { key = k; desc = d; return true }
|
| })
|
|
|
| -TestDefine(Proxy.create({
|
| +TestDefine(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k, d) { key = k; desc = d; return true }
|
| }
|
| @@ -856,11 +858,11 @@ TestDefineThrow({
|
| defineProperty2: function(k, d) { throw "myexn" }
|
| })
|
|
|
| -TestDefineThrow(Proxy.create({
|
| +TestDefineThrow(new Proxy({}, {
|
| get: function(pr, pk) { throw "myexn" }
|
| }))
|
|
|
| -TestDefineThrow(Proxy.create({
|
| +TestDefineThrow(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k, d) { throw "myexn" }
|
| }
|
| @@ -915,7 +917,7 @@ TestDelete({
|
| delete2: function(k) { key = k; return k < "z" }
|
| })
|
|
|
| -TestDelete(Proxy.create({
|
| +TestDelete(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) { key = k; return k < "z" }
|
| }
|
| @@ -949,11 +951,11 @@ TestDeleteThrow({
|
| delete2: function(k) { throw "myexn" }
|
| })
|
|
|
| -TestDeleteThrow(Proxy.create({
|
| +TestDeleteThrow(new Proxy({}, {
|
| get: function(pr, pk) { throw "myexn" }
|
| }))
|
|
|
| -TestDeleteThrow(Proxy.create({
|
| +TestDeleteThrow(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) { throw "myexn" }
|
| }
|
| @@ -1052,9 +1054,9 @@ TestComparison(function(o1, o2) { return !(o1 !== o2) })
|
| // Type (typeof).
|
|
|
| function TestTypeof() {
|
| - assertEquals("object", typeof Proxy.create({}))
|
| - assertTrue(typeof Proxy.create({}) == "object")
|
| - assertTrue("object" == typeof Proxy.create({}))
|
| + assertEquals("object", typeof new Proxy({}, {}))
|
| + assertTrue(typeof new Proxy({}, {}) == "object")
|
| + assertTrue("object" == typeof new Proxy({}, {}))
|
|
|
| assertEquals("function", typeof Proxy.createFunction({}, function() {}))
|
| assertTrue(typeof Proxy.createFunction({}, function() {}) == "function")
|
| @@ -1146,7 +1148,7 @@ TestIn({
|
| }
|
| })
|
|
|
| -TestIn(Proxy.create({
|
| +TestIn(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) { key = k; return k < "z" }
|
| }
|
| @@ -1191,11 +1193,11 @@ TestInThrow({
|
| getPropertyDescriptor: function(k) { throw "myexn" }
|
| })
|
|
|
| -TestInThrow(Proxy.create({
|
| +TestInThrow(new Proxy({}, {
|
| get: function(pr, pk) { throw "myexn" }
|
| }))
|
|
|
| -TestInThrow(Proxy.create({
|
| +TestInThrow(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) { throw "myexn" }
|
| }
|
| @@ -1290,7 +1292,7 @@ TestInForDerived({
|
| })
|
| */
|
|
|
| -TestInForDerived(Proxy.create({
|
| +TestInForDerived(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) {
|
| key = k; return k < "z" ? {value: 42, configurable: true} : void 0
|
| @@ -1305,7 +1307,7 @@ TestInForDerived(Proxy.create({
|
| var descget
|
|
|
| function TestDescriptorGetOrder(handler) {
|
| - var p = Proxy.create(handler)
|
| + var p = new Proxy({}, handler)
|
| var o = Object.create(p, {b: {value: 0}})
|
| TestDescriptorGetOrder2(function(n) { return p[n] }, "vV")
|
| TestDescriptorGetOrder2(function(n) { return n in p }, "")
|
| @@ -1329,7 +1331,7 @@ TestDescriptorGetOrder({
|
| getPropertyDescriptor: function(k) {
|
| if (k >= "z") return void 0
|
| // Return a proxy as property descriptor, so that we can log accesses.
|
| - return Proxy.create({
|
| + return new Proxy({}, {
|
| get: function(r, attr) {
|
| descget += attr[0].toUpperCase()
|
| return true
|
| @@ -1410,7 +1412,7 @@ TestHasOwn({
|
| }
|
| })
|
|
|
| -TestHasOwn(Proxy.create({
|
| +TestHasOwn(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) { key = k; return k < "z" }
|
| }
|
| @@ -1454,11 +1456,11 @@ TestHasOwnThrow({
|
| getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
| })
|
|
|
| -TestHasOwnThrow(Proxy.create({
|
| +TestHasOwnThrow(new Proxy({}, {
|
| get: function(pr, pk) { throw "myexn" }
|
| }))
|
|
|
| -TestHasOwnThrow(Proxy.create({
|
| +TestHasOwnThrow(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) { throw "myexn" }
|
| }
|
| @@ -1470,9 +1472,9 @@ TestHasOwnThrow(Proxy.create({
|
|
|
| function TestProxyInstanceof() {
|
| var o1 = {}
|
| - var p1 = Proxy.create({})
|
| - var p2 = Proxy.create({}, o1)
|
| - var p3 = Proxy.create({}, p2)
|
| + var p1 = new Proxy({}, {})
|
| + var p2 = new Proxy(o1, {})
|
| + var p3 = new Proxy(p2, {})
|
| var o2 = Object.create(p2)
|
|
|
| var f0 = function() {}
|
| @@ -1488,8 +1490,8 @@ function TestProxyInstanceof() {
|
| assertFalse(o1 instanceof f0)
|
| assertFalse(o1 instanceof f1)
|
| assertFalse(o1 instanceof f2)
|
| - assertFalse(o1 instanceof f3)
|
| - assertFalse(p1 instanceof Object)
|
| + assertFalse(o1 instanceof f3);
|
| + assertTrue(p1 instanceof Object)
|
| assertFalse(p1 instanceof f0)
|
| assertFalse(p1 instanceof f1)
|
| assertFalse(p1 instanceof f2)
|
| @@ -1584,31 +1586,31 @@ TestInstanceofProxy()
|
| // Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf).
|
|
|
| function TestPrototype() {
|
| - var o1 = {}
|
| - var p1 = Proxy.create({})
|
| - var p2 = Proxy.create({}, o1)
|
| - var p3 = Proxy.create({}, p2)
|
| - var p4 = Proxy.create({}, null)
|
| + var o1 = {o1:true}
|
| + var p1 = new Proxy({p1:true}, {handler_p1:true})
|
| + var p2 = new Proxy(o1, {handler_p2:true})
|
| + var p3 = new Proxy(p2, {handler_p3:true})
|
| + var p4 = new Proxy({p4:true}, {handler_p4:true})
|
| var o2 = Object.create(p3)
|
|
|
| assertSame(Object.getPrototypeOf(o1), Object.prototype)
|
| - assertSame(Object.getPrototypeOf(p1), null)
|
| - assertSame(Object.getPrototypeOf(p2), o1)
|
| - assertSame(Object.getPrototypeOf(p3), p2)
|
| - assertSame(Object.getPrototypeOf(p4), null)
|
| + assertSame(Object.getPrototypeOf(p1), Object.prototype)
|
| + assertSame(Object.getPrototypeOf(p2), Object.prototype)
|
| + assertSame(Object.getPrototypeOf(p3), Object.prototype)
|
| + assertSame(Object.getPrototypeOf(p4), Object.prototype)
|
| assertSame(Object.getPrototypeOf(o2), p3)
|
|
|
| assertTrue(Object.prototype.isPrototypeOf(o1))
|
| - assertFalse(Object.prototype.isPrototypeOf(p1))
|
| + assertTrue(Object.prototype.isPrototypeOf(p1))
|
| assertTrue(Object.prototype.isPrototypeOf(p2))
|
| assertTrue(Object.prototype.isPrototypeOf(p3))
|
| - assertFalse(Object.prototype.isPrototypeOf(p4))
|
| + assertTrue(Object.prototype.isPrototypeOf(p4))
|
| assertTrue(Object.prototype.isPrototypeOf(o2))
|
| assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o1))
|
| - assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p1))
|
| + assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p1))
|
| assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p2))
|
| assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p3))
|
| - assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p4))
|
| + assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p4))
|
| assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o2))
|
| assertFalse(Object.prototype.isPrototypeOf.call(o1, o1))
|
| assertFalse(Object.prototype.isPrototypeOf.call(o1, p1))
|
| @@ -1636,10 +1638,11 @@ function TestPrototype() {
|
| assertFalse(Object.prototype.isPrototypeOf.call(o2, p4))
|
| assertFalse(Object.prototype.isPrototypeOf.call(o2, o2))
|
|
|
| - var f = Proxy.createFunction({}, function() {})
|
| - assertSame(Object.getPrototypeOf(f), Function.prototype)
|
| - assertTrue(Object.prototype.isPrototypeOf(f))
|
| - assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f))
|
| + // TODO(1543): enable once we have a working solution.
|
| + // var f = Proxy.createFunction({}, function() {})
|
| + // assertSame(Object.getPrototypeOf(f), Function.prototype)
|
| + // assertTrue(Object.prototype.isPrototypeOf(f))
|
| + // assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f))
|
| }
|
|
|
| TestPrototype()
|
| @@ -1824,35 +1827,35 @@ TestKeysThrow({
|
| // Object.isFrozen, Object.isSealed, Object.isExtensible)
|
|
|
| function TestFix(names, handler) {
|
| - var proto = {p: 77}
|
| + var target = {p: 77}
|
| var assertFixing = function(o, s, f, e) {
|
| assertEquals(s, Object.isSealed(o))
|
| assertEquals(f, Object.isFrozen(o))
|
| assertEquals(e, Object.isExtensible(o))
|
| }
|
|
|
| - var p1 = Proxy.create(handler, proto)
|
| + var p1 = new Proxy(target, handler)
|
| assertFixing(p1, false, false, true)
|
| Object.seal(p1)
|
| assertFixing(p1, true, names.length === 0, false)
|
| assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p1).sort())
|
| assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
|
| Object.keys(p1).sort())
|
| - assertEquals(proto, Object.getPrototypeOf(p1))
|
| + assertEquals(target, Object.getPrototypeOf(p1))
|
| assertEquals(77, p1.p)
|
| for (var n in p1) {
|
| var desc = Object.getOwnPropertyDescriptor(p1, n)
|
| if (desc !== undefined) assertFalse(desc.configurable)
|
| }
|
|
|
| - var p2 = Proxy.create(handler, proto)
|
| + var p2 = new Proxy(target, handler)
|
| assertFixing(p2, false, false, true)
|
| Object.freeze(p2)
|
| assertFixing(p2, true, true, false)
|
| assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p2).sort())
|
| assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
|
| Object.keys(p2).sort())
|
| - assertEquals(proto, Object.getPrototypeOf(p2))
|
| + assertEquals(target, Object.getPrototypeOf(p2))
|
| assertEquals(77, p2.p)
|
| for (var n in p2) {
|
| var desc = Object.getOwnPropertyDescriptor(p2, n)
|
| @@ -1860,17 +1863,17 @@ function TestFix(names, handler) {
|
| if (desc !== undefined) assertFalse(desc.configurable)
|
| }
|
|
|
| - var p3 = Proxy.create(handler, proto)
|
| + var p3 = new Proxy(target, handler)
|
| assertFixing(p3, false, false, true)
|
| Object.preventExtensions(p3)
|
| assertFixing(p3, names.length === 0, names.length === 0, false)
|
| assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort())
|
| assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
|
| Object.keys(p3).sort())
|
| - assertEquals(proto, Object.getPrototypeOf(p3))
|
| + assertEquals(target, Object.getPrototypeOf(p3))
|
| assertEquals(77, p3.p)
|
|
|
| - var p = Proxy.create(handler, proto)
|
| + var p = new Proxy(target, handler)
|
| var o = Object.create(p)
|
| assertFixing(p, false, false, true)
|
| assertFixing(o, false, false, true)
|
| @@ -2104,7 +2107,7 @@ TestReentrantFix(function(create, freeze) {
|
| var key
|
|
|
| function TestToString(handler) {
|
| - var p = Proxy.create(handler)
|
| + var p = new Proxy({}, handler)
|
| key = ""
|
| assertEquals("[object Object]", Object.prototype.toString.call(p))
|
| assertEquals("", key)
|
| @@ -2136,7 +2139,7 @@ TestToString({
|
| get2: function(r, k) { key = k; return function() { return "my_proxy" } }
|
| })
|
|
|
| -TestToString(Proxy.create({
|
| +TestToString(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(r, k) { key = k; return function() { return "my_proxy" } }
|
| }
|
| @@ -2144,7 +2147,7 @@ TestToString(Proxy.create({
|
|
|
|
|
| function TestToStringThrow(handler) {
|
| - var p = Proxy.create(handler)
|
| + var p = new Proxy({}, handler)
|
| assertEquals("[object Object]", Object.prototype.toString.call(p))
|
| assertThrows(function(){ Object.prototype.toLocaleString.call(p) }, "myexn")
|
|
|
| @@ -2170,11 +2173,11 @@ TestToStringThrow({
|
| get2: function(r, k) { throw "myexn" }
|
| })
|
|
|
| -TestToStringThrow(Proxy.create({
|
| +TestToStringThrow(new Proxy({}, {
|
| get: function(pr, pk) { throw "myexn" }
|
| }))
|
|
|
| -TestToStringThrow(Proxy.create({
|
| +TestToStringThrow(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(r, k) { throw "myexn" }
|
| }
|
| @@ -2241,7 +2244,7 @@ TestIsEnumerable({
|
| },
|
| })
|
|
|
| -TestIsEnumerable(Proxy.create({
|
| +TestIsEnumerable(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) {
|
| key = k; return {enumerable: k < "z", configurable: true}
|
| @@ -2279,11 +2282,11 @@ TestIsEnumerableThrow({
|
| },
|
| })
|
|
|
| -TestIsEnumerableThrow(Proxy.create({
|
| +TestIsEnumerableThrow(new Proxy({}, {
|
| get: function(pr, pk) { throw "myexn" }
|
| }))
|
|
|
| -TestIsEnumerableThrow(Proxy.create({
|
| +TestIsEnumerableThrow(new Proxy({}, {
|
| get: function(pr, pk) {
|
| return function(k) { throw "myexn" }
|
| }
|
| @@ -2315,7 +2318,7 @@ function TestOptWithProxyPrototype() {
|
| };
|
|
|
| function C() {};
|
| - C.prototype = Proxy.create(handler);
|
| + C.prototype = new Proxy({}, handler);
|
| var o = new C();
|
|
|
| function f() {
|
|
|