Chromium Code Reviews| Index: test/harmony/proxies.js |
| diff --git a/test/harmony/proxies.js b/test/harmony/proxies.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6e07e00c65fb69229da8ec80a5036026bb9642d4 |
| --- /dev/null |
| +++ b/test/harmony/proxies.js |
| @@ -0,0 +1,95 @@ |
| + |
|
Kevin Millikin (Chromium)
2011/05/30 16:32:29
This needs the license header.
I'd move it into a
rossberg
2011/05/31 14:50:24
Done.
|
| + |
| +function ASSERT(b) { |
| + print(b ? "OK." : "Error!") |
| +} |
| + |
| + |
| +// Getters. |
| +print("Getters:") |
| + |
| +function TestGet(handler) { |
| + var o = Proxy.create(handler) |
| + ASSERT(o.a === 42) |
| + ASSERT(o["b"] === 42) |
| +// ASSERT(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(Proxy.create({get: function(pr, pk) { return function(r, k) { return 42 } }})) |
| + |
| + |
| +// Setters. |
| +print("Setters:") |
| + |
| +var key |
| +var val |
| +function TestSet(handler) { |
| + var o = Proxy.create(handler) |
| + ASSERT(o.a = 42) |
| + ASSERT(key === "a") |
| + ASSERT(val === 42) |
| + ASSERT(o["b"] = 43) |
| + ASSERT(key === "b") |
| + ASSERT(val === 43) |
| +// ASSERT(Object.defineProperty(o, "c", {value: 44})) |
| +// ASSERT(key === "c") |
| +// ASSERT(val === 44) |
| +} |
| + |
| +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(Proxy.create({get: function(pr, pk) { return function(r, k, v) { key = k; val = v; return true } }})) |
| + |
| + |
| + |
| +// Comparison. |
| +print("Comparison:") |
| + |
| +var o1 = Proxy.create({}) |
| +var o2 = Proxy.create({}) |
| + |
| +ASSERT(o1 == o1) |
| +ASSERT(o2 == o2) |
| +ASSERT(!(o1 == o2)) |
| +ASSERT(!(o1 == {})) |
| +ASSERT(!({} == o2)) |
| +ASSERT(!({} == {})) |
| + |
| +ASSERT(o1 === o1) |
| +ASSERT(o2 === o2) |
| +ASSERT(!(o1 === o2)) |
| +ASSERT(!(o1 === {})) |
| +ASSERT(!({} === o2)) |
| +ASSERT(!({} === {})) |
| + |
| + |
| + |
| +// Type. |
| +print("Type:") |
| + |
| +ASSERT(typeof Proxy.create({}) == "object") |
| +ASSERT("object" == typeof Proxy.create({})) |
| +ASSERT((function(o) { return typeof o })(Proxy.create({})) == "object") |
| + |
| +// No function proxies yet. |