Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: test/harmony/proxies.js

Issue 6992072: Implement set trap for proxies, and revamp class hierarchy in preparation (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Renamed range constants for InstanceType enum. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.

Powered by Google App Engine
This is Rietveld 408576698