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

Unified Diff: test/mjsunit/harmony/proxies.js

Issue 7849021: Handle function proxies as getters/setters. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Micro-opt. Created 9 years, 3 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
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/proxies.js
diff --git a/test/mjsunit/harmony/proxies.js b/test/mjsunit/harmony/proxies.js
index 3c4e5f61c5862f7c9273e77b11422af0c53ee7e7..2e8df2677a2831a7814c3e22bb8ab294cd5ab238 100644
--- a/test/mjsunit/harmony/proxies.js
+++ b/test/mjsunit/harmony/proxies.js
@@ -1680,3 +1680,133 @@ var p = Proxy.createFunction(
{fix: function() {return {}}}, function() { throw "myexn" })
Object.freeze(p)
TestCallThrow(p)
+
+
+
+// TODO(rossberg): once we merge with 7799026, remove this.
+function createFrozen(handler, callTrap) {
+ if (!("fix" in handler)) handler.fix = function() { return {} }
+ var f = Proxy.createFunction(handler, callTrap)
+ Object.freeze(f)
+ return f
+}
+
+
+// Getters and setters.
+
+var value
+var receiver
+
+function TestAccessorCall(getterCallTrap, setterCallTrap) {
+ var handler = {fix: function() { return {} }}
+ var pgetter = Proxy.createFunction(handler, getterCallTrap)
+ var psetter = Proxy.createFunction(handler, setterCallTrap)
+
+ var o = {}
+ var oo = Object.create(o)
+ Object.defineProperty(o, "a", {get: pgetter, set: psetter})
+ Object.defineProperty(o, "b", {get: pgetter})
+ Object.defineProperty(o, "c", {set: psetter})
+ Object.defineProperty(o, "3", {get: pgetter, set: psetter})
+ Object.defineProperty(oo, "a", {value: 43})
+
+ receiver = ""
+ assertEquals(42, o.a)
+ assertSame(o, receiver)
+ receiver = ""
+ assertEquals(42, o.b)
+ assertSame(o, receiver)
+ receiver = ""
+ assertEquals(undefined, o.c)
+ assertSame("", receiver)
Jakob Kummerow 2011/09/22 12:23:19 This works, but you're implicitly testing an unrel
rossberg 2011/09/22 16:39:52 Done.
+ receiver = ""
+ assertEquals(42, o["a"])
+ assertSame(o, receiver)
+ receiver = ""
+// TODO(rossberg): test once we merge with elements branch
Jakob Kummerow 2011/09/22 12:23:19 nit: please indent to the same level as the surrou
rossberg 2011/09/22 16:39:52 Actually, uncommented the code, since the tests wo
+// assertEquals(42, o[3])
+// assertSame(o, receiver)
+
+ receiver = ""
+ assertEquals(43, oo.a)
+ assertSame("", receiver)
+ receiver = ""
+ assertEquals(42, oo.b)
+ assertSame(o, receiver)
+ receiver = ""
+ assertEquals(undefined, oo.c)
+ assertSame("", receiver)
+ receiver = ""
+ assertEquals(43, oo["a"])
+ assertSame("", receiver)
+ receiver = ""
+// TODO(rossberg): test once we merge with elements branch
+// assertEquals(42, oo[3])
+// assertSame(o, receiver)
+
+ receiver = ""
+ assertEquals(50, o.a = 50)
+ assertSame(o, receiver)
+ assertEquals(50, value)
+ receiver = ""
+ assertEquals(51, o.b = 51)
+ assertSame("", receiver)
+ assertEquals(50, value) // no setter
+ assertThrows(function(){ "use strict"; o.b = 51 }, TypeError)
Jakob Kummerow 2011/09/22 12:23:19 nit: space before '{'
rossberg 2011/09/22 16:39:52 Done.
+ receiver = ""
+ assertEquals(52, o.c = 52)
+ assertSame(o, receiver)
+ assertEquals(52, value)
+ receiver = ""
+ assertEquals(53, o["a"] = 53)
+ assertSame(o, receiver)
+ assertEquals(53, value)
+ receiver = ""
+ assertEquals(54, o[3] = 54)
+// TODO(rossberg): test once we merge with elements branch
+// assertSame(o, receiver)
+// assertEquals(54, value)
+
+ value = 0
+ receiver = ""
+ assertEquals(60, oo.a = 60)
+ assertSame("", receiver)
+ assertEquals(0, value) // oo has own `a'
Jakob Kummerow 2011/09/22 12:23:19 nit: s/`/'/
rossberg 2011/09/22 16:39:52 Done.
+ assertEquals(61, oo.b = 61)
+ assertSame("", receiver)
+ assertEquals(0, value) // no setter
+ assertThrows(function(){ "use strict"; oo.b = 61 }, TypeError)
Jakob Kummerow 2011/09/22 12:23:19 nit: space before '{'
rossberg 2011/09/22 16:39:52 Done.
+ receiver = ""
+ assertEquals(62, oo.c = 62)
+ assertSame(oo, receiver)
+ assertEquals(62, value)
+ receiver = ""
+ assertEquals(63, oo["c"] = 63)
+ assertSame(oo, receiver)
+ assertEquals(63, value)
+ receiver = ""
+ assertEquals(64, oo[3] = 64)
+// TODO(rossberg): test once we merge with elements branch
+// assertSame(oo, receiver)
+// assertEquals(64, value)
+}
+
+TestAccessorCall(
+ function() { receiver = this; return 42 },
+ function(x) { receiver = this; value = x }
+)
+
+TestAccessorCall(
+ function() { "use strict"; receiver = this; return 42 },
+ function(x) { "use strict"; receiver = this; value = x }
+)
+
+TestAccessorCall(
+ Proxy.createFunction({}, function() { receiver = this; return 42 }),
+ Proxy.createFunction({}, function(x) { receiver = this; value = x })
+)
+
+TestAccessorCall(
+ createFrozen({}, function() { receiver = this; return 42 }),
+ createFrozen({}, function(x) { receiver = this; value = x })
+)
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698