| Index: test/mjsunit/harmony/proxies.js
|
| ===================================================================
|
| --- test/mjsunit/harmony/proxies.js (revision 8174)
|
| +++ test/mjsunit/harmony/proxies.js (working copy)
|
| @@ -38,12 +38,35 @@
|
| // assertEquals(Object.getOwnPropertyDescriptor(o, "b").value, 42)
|
| }
|
|
|
| -TestGet({get: function(r, k) { return 42 }})
|
| -TestGet({getPropertyDescriptor: function(k) { return {value: 42} }})
|
| -TestGet({getPropertyDescriptor: function(k) { return {get value() { return 42 }} }})
|
| -TestGet({get: undefined, getPropertyDescriptor: function(k) { return {value: 42} }})
|
| +TestGet({
|
| + get: function(r, k) { return 42 }
|
| +})
|
| +TestGet({
|
| + get: function(r, k) { return this.get2(r, k) },
|
| + get2: function(r, k) { return 42 }
|
| +})
|
| +TestGet({
|
| + getPropertyDescriptor: function(k) { return {value: 42} }
|
| +})
|
| +TestGet({
|
| + getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) },
|
| + getPropertyDescriptor2: function(k) { return {value: 42} }
|
| +})
|
| +TestGet({
|
| + getPropertyDescriptor: function(k) {
|
| + return {get value() { return 42 }}
|
| + }
|
| +})
|
| +TestGet({
|
| + get: undefined,
|
| + getPropertyDescriptor: function(k) { return {value: 42} }
|
| +})
|
|
|
| -TestGet(Proxy.create({get: function(pr, pk) { return function(r, k) { return 42 } }}))
|
| +TestGet(Proxy.create({
|
| + get: function(pr, pk) {
|
| + return function(r, k) { return 42 }
|
| + }
|
| +}))
|
|
|
|
|
|
|
| @@ -64,46 +87,86 @@
|
| // assertEquals(44, val)
|
| }
|
|
|
| -TestSet({set: function(r, k, v) { key = k; val = v; return true }})
|
| -TestSet({getOwnPropertyDescriptor: function(k) { return {writable: true} },
|
| - defineProperty: function(k, desc) { key = k, val = desc.value }})
|
| -TestSet({getOwnPropertyDescriptor: function(k) { return {get writable() { return true }} },
|
| - defineProperty: function(k, desc) { key = k, val = desc.value }})
|
| -TestSet({getOwnPropertyDescriptor: function(k) { return {set: function(v) { key = k, val = v }} }})
|
| -TestSet({getOwnPropertyDescriptor: function(k) { return null },
|
| - getPropertyDescriptor: function(k) { return {writable: true} },
|
| - defineProperty: function(k, desc) { key = k, val = desc.value }})
|
| -TestSet({getOwnPropertyDescriptor: function(k) { return null },
|
| - getPropertyDescriptor: function(k) { return {get writable() { return true }} },
|
| - defineProperty: function(k, desc) { key = k, val = desc.value }})
|
| -TestSet({getOwnPropertyDescriptor: function(k) { return null },
|
| - getPropertyDescriptor: function(k) { return {set: function(v) { key = k, val = v }} }})
|
| -TestSet({getOwnPropertyDescriptor: function(k) { return null },
|
| - getPropertyDescriptor: function(k) { return null },
|
| - defineProperty: function(k, desc) { key = k, val = desc.value }})
|
| +TestSet({
|
| + set: function(r, k, v) { key = k; val = v; return true }
|
| +})
|
| +TestSet({
|
| + set: function(r, k, v) { return this.set2(r, k, v) },
|
| + set2: function(r, k, v) { key = k; val = v; return true }
|
| +})
|
| +TestSet({
|
| + getOwnPropertyDescriptor: function(k) { return {writable: true} },
|
| + defineProperty: function(k, desc) { key = k; val = desc.value }
|
| +})
|
| +TestSet({
|
| + getOwnPropertyDescriptor: function(k) {
|
| + return this.getOwnPropertyDescriptor2(k)
|
| + },
|
| + getOwnPropertyDescriptor2: function(k) { return {writable: true} },
|
| + defineProperty: function(k, desc) { this.defineProperty2(k, desc) },
|
| + defineProperty2: function(k, desc) { key = k; val = desc.value }
|
| +})
|
| +TestSet({
|
| + getOwnPropertyDescriptor: function(k) {
|
| + return {get writable() { return true }}
|
| + },
|
| + defineProperty: function(k, desc) { key = k; val = desc.value }
|
| +})
|
| +TestSet({
|
| + getOwnPropertyDescriptor: function(k) {
|
| + return {set: function(v) { key = k; val = v }}
|
| + }
|
| +})
|
| +TestSet({
|
| + getOwnPropertyDescriptor: function(k) { return null },
|
| + getPropertyDescriptor: function(k) { return {writable: true} },
|
| + defineProperty: function(k, desc) { key = k; val = desc.value }
|
| +})
|
| +TestSet({
|
| + getOwnPropertyDescriptor: function(k) { return null },
|
| + getPropertyDescriptor: function(k) {
|
| + return {get writable() { return true }}
|
| + },
|
| + defineProperty: function(k, desc) { key = k; val = desc.value }
|
| +})
|
| +TestSet({
|
| + getOwnPropertyDescriptor: function(k) { return null },
|
| + getPropertyDescriptor: function(k) {
|
| + return {set: function(v) { key = k; val = v }}
|
| + }
|
| +})
|
| +TestSet({
|
| + getOwnPropertyDescriptor: function(k) { return null },
|
| + getPropertyDescriptor: function(k) { return null },
|
| + defineProperty: function(k, desc) { key = k, val = desc.value }
|
| +})
|
|
|
| -TestSet(Proxy.create({get: function(pr, pk) { return function(r, k, v) { key = k; val = v; return true } }}))
|
| +TestSet(Proxy.create({
|
| + get: function(pr, pk) {
|
| + return function(r, k, v) { key = k; val = v; return true }
|
| + }
|
| +}))
|
|
|
|
|
|
|
| // Comparison.
|
|
|
| -var o1 = Proxy.create({})
|
| -var o2 = Proxy.create({})
|
| +function TestComparison(eq) {
|
| + var o1 = Proxy.create({})
|
| + var o2 = Proxy.create({})
|
|
|
| -assertTrue(o1 == o1)
|
| -assertTrue(o2 == o2)
|
| -assertTrue(!(o1 == o2))
|
| -assertTrue(!(o1 == {}))
|
| -assertTrue(!({} == o2))
|
| -assertTrue(!({} == {}))
|
| + assertTrue(eq(o1, o1))
|
| + assertTrue(eq(o2, o2))
|
| + assertTrue(!eq(o1, o2))
|
| + assertTrue(!eq(o1, {}))
|
| + assertTrue(!eq({}, o2))
|
| + assertTrue(!eq({}, {}))
|
| +}
|
|
|
| -assertTrue(o1 === o1)
|
| -assertTrue(o2 === o2)
|
| -assertTrue(!(o1 === o2))
|
| -assertTrue(!(o1 === {}))
|
| -assertTrue(!({} === o2))
|
| -assertTrue(!({} === {}))
|
| +TestComparison(function(o1, o2) { return o1 == o2 })
|
| +TestComparison(function(o1, o2) { return o1 === o2 })
|
| +TestComparison(function(o1, o2) { return !(o1 != o2) })
|
| +TestComparison(function(o1, o2) { return !(o1 !== o2) })
|
|
|
|
|
|
|
| @@ -114,3 +177,85 @@
|
| assertTrue("object" == typeof Proxy.create({}))
|
|
|
| // No function proxies yet.
|
| +
|
| +
|
| +
|
| +// Instanceof (instanceof).
|
| +
|
| +function TestInstanceof() {
|
| + var o = {}
|
| + var p1 = Proxy.create({})
|
| + var p2 = Proxy.create({}, o)
|
| + var p3 = Proxy.create({}, p2)
|
| +
|
| + var f = function() {}
|
| + f.prototype = o
|
| + var f1 = function() {}
|
| + f1.prototype = p1
|
| + var f2 = function() {}
|
| + f2.prototype = p2
|
| +
|
| + assertTrue(o instanceof Object)
|
| + assertFalse(o instanceof f)
|
| + assertFalse(o instanceof f1)
|
| + assertFalse(o instanceof f2)
|
| + assertFalse(p1 instanceof Object)
|
| + assertFalse(p1 instanceof f)
|
| + assertFalse(p1 instanceof f1)
|
| + assertFalse(p1 instanceof f2)
|
| + assertTrue(p2 instanceof Object)
|
| + assertTrue(p2 instanceof f)
|
| + assertFalse(p2 instanceof f1)
|
| + assertFalse(p2 instanceof f2)
|
| + assertTrue(p3 instanceof Object)
|
| + assertTrue(p3 instanceof f)
|
| + assertFalse(p3 instanceof f1)
|
| + assertTrue(p3 instanceof f2)
|
| +}
|
| +
|
| +TestInstanceof()
|
| +
|
| +
|
| +
|
| +// Prototype (Object.getPrototypeOf).
|
| +
|
| +function TestPrototype() {
|
| + var o = {}
|
| + var p1 = Proxy.create({})
|
| + var p2 = Proxy.create({}, o)
|
| + var p3 = Proxy.create({}, p2)
|
| + var p4 = Proxy.create({}, 666)
|
| +
|
| + assertSame(Object.getPrototypeOf(o), Object.prototype)
|
| + assertSame(Object.getPrototypeOf(p1), null)
|
| + assertSame(Object.getPrototypeOf(p2), o)
|
| + assertSame(Object.getPrototypeOf(p3), p2)
|
| + assertSame(Object.getPrototypeOf(p4), null)
|
| +}
|
| +
|
| +TestPrototype()
|
| +
|
| +
|
| +
|
| +// Property names (Object.getOwnPropertyNames).
|
| +
|
| +function TestPropertyNames(names, handler) {
|
| + var p = Proxy.create(handler)
|
| + assertArrayEquals(names, Object.getOwnPropertyNames(p))
|
| +}
|
| +
|
| +TestPropertyNames([], {
|
| + getOwnPropertyNames: function() { return [] }
|
| +})
|
| +TestPropertyNames(["a", "zz", " ", "0"], {
|
| + getOwnPropertyNames: function() { return ["a", "zz", " ", 0] }
|
| +})
|
| +TestPropertyNames(["throw", "function "], {
|
| + getOwnPropertyNames: function() { return this.getOwnPropertyNames2() },
|
| + getOwnPropertyNames2: function() { return ["throw", "function "] }
|
| +})
|
| +TestPropertyNames(["[object Object]"], {
|
| + get getOwnPropertyNames() {
|
| + return function() { return [{}] }
|
| + }
|
| +})
|
|
|