Chromium Code Reviews| Index: test/mjsunit/harmony/proxies.js |
| diff --git a/test/mjsunit/harmony/proxies.js b/test/mjsunit/harmony/proxies.js |
| index 84641d589e8e8f838ccc11d9157d74907c03b9b3..7221a9823fbc00e85237950f2e6040c61ea1e033 100644 |
| --- a/test/mjsunit/harmony/proxies.js |
| +++ b/test/mjsunit/harmony/proxies.js |
| @@ -404,7 +404,7 @@ assertTrue("object" == typeof Proxy.create({})) |
| -// Element (in). |
| +// Membership test (in). |
| var key |
| function TestIn(handler) { |
| @@ -477,7 +477,60 @@ TestIn(Proxy.create({ |
| -// Instanceof (instanceof). |
| +// Own Properties (Object.prototype.hasOwnProperty). |
| + |
| +var key |
| +function TestHasOwn(handler) { |
| + var o = Proxy.create(handler) |
| + assertTrue(Object.prototype.hasOwnProperty.call(o, "a")) |
| + assertEquals("a", key) |
| + assertTrue(Object.prototype.hasOwnProperty.call(o, 99)) |
| + assertEquals("99", key) |
| + assertFalse(Object.prototype.hasOwnProperty.call(o, "z")) |
| + assertEquals("z", key) |
| +} |
| + |
| +TestHasOwn({ |
| + hasOwn: function(k) { key = k; return k < "z" } |
| +}) |
| +TestHasOwn({ |
|
Mads Ager (chromium)
2011/07/19 15:41:05
Add whitespace between the calls?
rossberg
2011/07/21 11:08:42
Done, here and elsewhere.
|
| + hasOwn: function(k) { return this.hasOwn2(k) }, |
| + hasOwn2: function(k) { key = k; return k < "z" } |
| +}) |
| +TestHasOwn({ |
| + getOwnPropertyDescriptor: function(k) { |
| + key = k; return k < "z" ? {value: 42} : void 0 |
| + } |
| +}) |
| +TestHasOwn({ |
| + getOwnPropertyDescriptor: function(k) { |
| + return this.getOwnPropertyDescriptor2(k) |
| + }, |
| + getOwnPropertyDescriptor2: function(k) { |
| + key = k; return k < "z" ? {value: 42} : void 0 |
| + } |
| +}) |
| +TestHasOwn({ |
| + getOwnPropertyDescriptor: function(k) { |
| + key = k; return k < "z" ? {get value() { return 42 }} : void 0 |
| + } |
| +}) |
| +TestHasOwn({ |
| + hasOwn: undefined, |
| + getOwnPropertyDescriptor: function(k) { |
| + key = k; return k < "z" ? {value: 42} : void 0 |
| + } |
| +}) |
| + |
| +TestHasOwn(Proxy.create({ |
| + get: function(pr, pk) { |
| + return function(k) { key = k; return k < "z" } |
| + } |
| +})) |
| + |
| + |
| + |
| +// Instanceof (instanceof) |
| function TestInstanceof() { |
| var o = {} |
| @@ -514,7 +567,7 @@ TestInstanceof() |
| -// Prototype (Object.getPrototypeOf). |
| +// Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf). |
| function TestPrototype() { |
| var o = {} |
| @@ -528,6 +581,32 @@ function TestPrototype() { |
| assertSame(Object.getPrototypeOf(p2), o) |
| assertSame(Object.getPrototypeOf(p3), p2) |
| assertSame(Object.getPrototypeOf(p4), null) |
| + |
| + assertTrue(Object.prototype.isPrototypeOf(o)) |
| + assertFalse(Object.prototype.isPrototypeOf(p1)) |
| + assertTrue(Object.prototype.isPrototypeOf(p2)) |
| + assertTrue(Object.prototype.isPrototypeOf(p3)) |
| + assertFalse(Object.prototype.isPrototypeOf(p4)) |
| + assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o)) |
| + assertFalse(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)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(o, o)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(o, p1)) |
| + assertTrue(Object.prototype.isPrototypeOf.call(o, p2)) |
| + assertTrue(Object.prototype.isPrototypeOf.call(o, p3)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(o, p4)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(p1, p1)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(p1, o)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(p1, p2)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(p1, p3)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(p1, p4)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(p2, p1)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(p2, p2)) |
| + assertTrue(Object.prototype.isPrototypeOf.call(p2, p3)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(p2, p4)) |
| + assertFalse(Object.prototype.isPrototypeOf.call(p3, p2)) |
| } |
| TestPrototype() |
| @@ -685,3 +764,83 @@ TestFix(["b"], { |
| } |
| } |
| }) |
| + |
| + |
| + |
| +// String conversion (Object.prototype.toString, Object.prototype.toLocaleString) |
| + |
| +var key |
| +function TestToString(handler) { |
| + var o = Proxy.create(handler) |
| + key = "" |
| + assertEquals("[object Object]", Object.prototype.toString.call(o)) |
| + assertEquals("", key) |
| + assertEquals("my_proxy", Object.prototype.toLocaleString.call(o)) |
| + assertEquals("toString", key) |
| +} |
| + |
| +TestToString({ |
| + get: function(r, k) { key = k; return function() { return "my_proxy" } } |
| +}) |
| +TestToString({ |
|
Mads Ager (chromium)
2011/07/19 15:41:05
Ditto.
|
| + get: function(r, k) { return this.get2(r, k) }, |
| + get2: function(r, k) { key = k; return function() { return "my_proxy" } } |
| +}) |
| +TestToString(Proxy.create({ |
| + get: function(pr, pk) { |
| + return function(r, k) { key = k; return function() { return "my_proxy" } } |
| + } |
| +})) |
| + |
| + |
| + |
| +// Value conversion (Object.prototype.toValue) |
| + |
| +function TestValueOf(handler) { |
| + var o = Proxy.create(handler) |
| + assertSame(o, Object.prototype.valueOf.call(o)) |
| +} |
| + |
| +TestValueOf({}) |
| + |
| + |
| + |
| +// Enumerability (Object.prototype.propertyIsEnumerable) |
| + |
| +var key |
| +function TestIsEnumerable(handler) { |
| + var o = Proxy.create(handler) |
| + assertTrue(Object.prototype.propertyIsEnumerable.call(o, "a")) |
| + assertEquals("a", key) |
| + assertTrue(Object.prototype.propertyIsEnumerable.call(o, 2)) |
| + assertEquals("2", key) |
| + assertFalse(Object.prototype.propertyIsEnumerable.call(o, "z")) |
| + assertEquals("z", key) |
| +} |
| + |
| +TestIsEnumerable({ |
| + getOwnPropertyDescriptor: function(k) { |
| + key = k; return {enumerable: k < "z", configurable: true} |
| + }, |
| +}) |
| +TestIsEnumerable({ |
|
Mads Ager (chromium)
2011/07/19 15:41:05
Ditto.
|
| + getOwnPropertyDescriptor: function(k) { |
| + return this.getOwnPropertyDescriptor2(k) |
| + }, |
| + getOwnPropertyDescriptor2: function(k) { |
| + key = k; return {enumerable: k < "z", configurable: true} |
| + }, |
| +}) |
| +TestIsEnumerable({ |
| + getOwnPropertyDescriptor: function(k) { |
| + key = k; return {get enumerable() { return k < "z" }, configurable: true} |
| + }, |
| +}) |
| + |
| +TestIsEnumerable(Proxy.create({ |
| + get: function(pr, pk) { |
| + return function(k) { |
| + key = k; return {enumerable: k < "z", configurable: true} |
| + } |
| + } |
| +})) |