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

Side by Side Diff: test/mjsunit/harmony/proxies.js

Issue 1417063011: [runtime] support new Proxy() instead of Proxy.create and install getPrototypeOf trap (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: removing unreachable code Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « test/mjsunit/for-in-opt.js ('k') | test/mjsunit/harmony/proxies-example-membrane.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 17 matching lines...) Expand all
28 // We change the stack size for the ARM64 simulator because at one point this 28 // We change the stack size for the ARM64 simulator because at one point this
29 // test enters an infinite recursion which goes through the runtime and we 29 // test enters an infinite recursion which goes through the runtime and we
30 // overflow the system stack before the simulator stack. 30 // overflow the system stack before the simulator stack.
31 31
32 // Flags: --harmony-proxies --sim-stack-size=500 --allow-natives-syntax 32 // Flags: --harmony-proxies --sim-stack-size=500 --allow-natives-syntax
33 33
34 34
35 // Helper. 35 // Helper.
36 36
37 function TestWithProxies(test, x, y, z) { 37 function TestWithProxies(test, x, y, z) {
38 test(Proxy.create, x, y, z) 38 test(function(handler) { return new Proxy({}, handler) }, x, y, z)
39 test(function(h) {return Proxy.createFunction(h, function() {})}, x, y, z) 39 test(function(handler) {
40 return Proxy.createFunction(handler, function() {})
41 }, x, y, z)
40 } 42 }
41 43
42 44
43 45
44 // Getting property descriptors (Object.getOwnPropertyDescriptor). 46 // Getting property descriptors (Object.getOwnPropertyDescriptor).
45 47
46 var key 48 var key
47 49
48 function TestGetOwnProperty(handler) { 50 function TestGetOwnProperty(handler) {
49 TestWithProxies(TestGetOwnProperty2, handler) 51 TestWithProxies(TestGetOwnProperty2, handler)
(...skipping 24 matching lines...) Expand all
74 } 76 }
75 }) 77 })
76 78
77 TestGetOwnProperty({ 79 TestGetOwnProperty({
78 getOwnPropertyDescriptor: function(k) { 80 getOwnPropertyDescriptor: function(k) {
79 key = k 81 key = k
80 return {get value() { return 42 }, get configurable() { return true }} 82 return {get value() { return 42 }, get configurable() { return true }}
81 } 83 }
82 }) 84 })
83 85
84 TestGetOwnProperty(Proxy.create({ 86 TestGetOwnProperty(new Proxy({}, {
85 get: function(pr, pk) { 87 get: function(pr, pk) {
86 return function(k) { key = k; return {value: 42, configurable: true} } 88 return function(k) { key = k; return {value: 42, configurable: true} }
87 } 89 }
88 })) 90 }))
89 91
90 92
91 function TestGetOwnPropertyThrow(handler) { 93 function TestGetOwnPropertyThrow(handler) {
92 TestWithProxies(TestGetOwnPropertyThrow2, handler) 94 TestWithProxies(TestGetOwnPropertyThrow2, handler)
93 } 95 }
94 96
(...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 }, 1819 },
1818 getOwnPropertyDescriptor: function(k) { throw "myexn" } 1820 getOwnPropertyDescriptor: function(k) { throw "myexn" }
1819 }) 1821 })
1820 1822
1821 1823
1822 1824
1823 // Fixing (Object.freeze, Object.seal, Object.preventExtensions, 1825 // Fixing (Object.freeze, Object.seal, Object.preventExtensions,
1824 // Object.isFrozen, Object.isSealed, Object.isExtensible) 1826 // Object.isFrozen, Object.isSealed, Object.isExtensible)
1825 1827
1826 function TestFix(names, handler) { 1828 function TestFix(names, handler) {
1827 // TODO(neis): Reenable/adapt once proxies properly support these operations. 1829 var target = {p: 77}
1828 // 1830 var assertFixing = function(o, s, f, e) {
1829 // var proto = {p: 77} 1831 assertEquals(s, Object.isSealed(o))
1830 // var assertFixing = function(o, s, f, e) { 1832 assertEquals(f, Object.isFrozen(o))
1831 // assertEquals(s, Object.isSealed(o)) 1833 assertEquals(e, Object.isExtensible(o))
1832 // assertEquals(f, Object.isFrozen(o)) 1834 }
1833 // assertEquals(e, Object.isExtensible(o)) 1835
1834 // } 1836 var p1 = new Proxy(target, handler)
1835 // 1837 assertFixing(p1, false, false, true)
1836 // var p1 = Proxy.create(handler, proto) 1838 Object.seal(p1)
1837 // assertFixing(p1, false, false, true) 1839 assertFixing(p1, true, names.length === 0, false)
1838 // Object.seal(p1) 1840 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p1).sort())
1839 // assertFixing(p1, true, names.length === 0, false) 1841 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
1840 // assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p1).sort()) 1842 Object.keys(p1).sort())
1841 // assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), 1843 assertEquals(target, Object.getPrototypeOf(p1))
1842 // Object.keys(p1).sort()) 1844 assertEquals(77, p1.p)
1843 // assertEquals(proto, Object.getPrototypeOf(p1)) 1845 for (var n in p1) {
1844 // assertEquals(77, p1.p) 1846 var desc = Object.getOwnPropertyDescriptor(p1, n)
1845 // for (var n in p1) { 1847 if (desc !== undefined) assertFalse(desc.configurable)
1846 // var desc = Object.getOwnPropertyDescriptor(p1, n) 1848 }
1847 // if (desc !== undefined) assertFalse(desc.configurable) 1849
1848 // } 1850 var p2 = new Proxy(target, handler)
1849 // 1851 assertFixing(p2, false, false, true)
1850 // var p2 = Proxy.create(handler, proto) 1852 Object.freeze(p2)
1851 // assertFixing(p2, false, false, true) 1853 assertFixing(p2, true, true, false)
1852 // Object.freeze(p2) 1854 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p2).sort())
1853 // assertFixing(p2, true, true, false) 1855 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
1854 // assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p2).sort()) 1856 Object.keys(p2).sort())
1855 // assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), 1857 assertEquals(target, Object.getPrototypeOf(p2))
1856 // Object.keys(p2).sort()) 1858 assertEquals(77, p2.p)
1857 // assertEquals(proto, Object.getPrototypeOf(p2)) 1859 for (var n in p2) {
1858 // assertEquals(77, p2.p) 1860 var desc = Object.getOwnPropertyDescriptor(p2, n)
1859 // for (var n in p2) { 1861 if (desc !== undefined) assertFalse(desc.writable)
1860 // var desc = Object.getOwnPropertyDescriptor(p2, n) 1862 if (desc !== undefined) assertFalse(desc.configurable)
1861 // if (desc !== undefined) assertFalse(desc.writable) 1863 }
1862 // if (desc !== undefined) assertFalse(desc.configurable) 1864
1863 // } 1865 var p3 = new Proxy(target, handler)
1864 // 1866 assertFixing(p3, false, false, true)
1865 // var p3 = Proxy.create(handler, proto) 1867 Object.preventExtensions(p3)
1866 // assertFixing(p3, false, false, true) 1868 assertFixing(p3, names.length === 0, names.length === 0, false)
1867 // Object.preventExtensions(p3) 1869 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort())
1868 // assertFixing(p3, names.length === 0, names.length === 0, false) 1870 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
1869 // assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort()) 1871 Object.keys(p3).sort())
1870 // assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), 1872 assertEquals(target, Object.getPrototypeOf(p3))
1871 // Object.keys(p3).sort()) 1873 assertEquals(77, p3.p)
1872 // assertEquals(proto, Object.getPrototypeOf(p3)) 1874
1873 // assertEquals(77, p3.p) 1875 var p = new Proxy(target, handler)
1874 // 1876 var o = Object.create(p)
1875 // var p = Proxy.create(handler, proto) 1877 assertFixing(p, false, false, true)
1876 // var o = Object.create(p) 1878 assertFixing(o, false, false, true)
1877 // assertFixing(p, false, false, true) 1879 Object.freeze(o)
1878 // assertFixing(o, false, false, true) 1880 assertFixing(p, false, false, true)
1879 // Object.freeze(o) 1881 assertFixing(o, true, true, false)
1880 // assertFixing(p, false, false, true)
1881 // assertFixing(o, true, true, false)
1882 } 1882 }
1883 1883
1884 TestFix([], { 1884 TestFix([], {
1885 fix: function() { return {} } 1885 fix: function() { return {} }
1886 }) 1886 })
1887 1887
1888 TestFix(["a", "b", "c", "3", "zz"], { 1888 TestFix(["a", "b", "c", "3", "zz"], {
1889 fix: function() { 1889 fix: function() {
1890 return { 1890 return {
1891 a: {value: "a", writable: true, configurable: false, enumerable: true}, 1891 a: {value: "a", writable: true, configurable: false, enumerable: true},
(...skipping 15 matching lines...) Expand all
1907 TestFix(["b"], { 1907 TestFix(["b"], {
1908 get fix() { 1908 get fix() {
1909 return function() { 1909 return function() {
1910 return {b: {configurable: true, writable: true, enumerable: true}} 1910 return {b: {configurable: true, writable: true, enumerable: true}}
1911 } 1911 }
1912 } 1912 }
1913 }) 1913 })
1914 1914
1915 1915
1916 function TestFixFunction(fix) { 1916 function TestFixFunction(fix) {
1917 // TODO(neis): Reenable/adapt once proxies properly support these operations. 1917 var f1 = Proxy.createFunction({
1918 // 1918 fix: function() { return {} }
1919 // var f1 = Proxy.createFunction({ 1919 }, function() {})
1920 // fix: function() { return {} } 1920 fix(f1)
1921 // }, function() {}) 1921 assertEquals(0, f1.length)
1922 // fix(f1) 1922
1923 // assertEquals(0, f1.length) 1923 var f2 = Proxy.createFunction({
1924 // 1924 fix: function() { return {length: {value: 3}} }
1925 // var f2 = Proxy.createFunction({ 1925 }, function() {})
1926 // fix: function() { return {length: {value: 3}} } 1926 fix(f2)
1927 // }, function() {}) 1927 assertEquals(3, f2.length)
1928 // fix(f2) 1928
1929 // assertEquals(3, f2.length) 1929 var f3 = Proxy.createFunction({
1930 // 1930 fix: function() { return {length: {value: "huh"}} }
1931 // var f3 = Proxy.createFunction({ 1931 }, function() {})
1932 // fix: function() { return {length: {value: "huh"}} } 1932 fix(f3)
1933 // }, function() {}) 1933 assertEquals(0, f1.length)
1934 // fix(f3)
1935 // assertEquals(0, f1.length)
1936 } 1934 }
1937 1935
1938 TestFixFunction(Object.seal) 1936 TestFixFunction(Object.seal)
1939 TestFixFunction(Object.freeze) 1937 TestFixFunction(Object.freeze)
1940 TestFixFunction(Object.preventExtensions) 1938 TestFixFunction(Object.preventExtensions)
1941 1939
1942 1940
1943 function TestFixThrow(handler) { 1941 function TestFixThrow(handler) {
1944 TestWithProxies(TestFixThrow2, handler) 1942 TestWithProxies(TestFixThrow2, handler)
1945 } 1943 }
1946 1944
1947 function TestFixThrow2(create, handler) { 1945 function TestFixThrow2(create, handler) {
1948 // TODO(neis): Reenable/adapt once proxies properly support these operations. 1946 var p = create(handler, {})
1949 // 1947 assertThrows(function(){ Object.seal(p) }, "myexn")
1950 // var p = create(handler, {}) 1948 assertThrows(function(){ Object.freeze(p) }, "myexn")
1951 // assertThrows(function(){ Object.seal(p) }, "myexn") 1949 assertThrows(function(){ Object.preventExtensions(p) }, "myexn")
1952 // assertThrows(function(){ Object.freeze(p) }, "myexn")
1953 // assertThrows(function(){ Object.preventExtensions(p) }, "myexn")
1954 } 1950 }
1955 1951
1956 TestFixThrow({ 1952 TestFixThrow({
1957 fix: function() { throw "myexn" } 1953 fix: function() { throw "myexn" }
1958 }) 1954 })
1959 1955
1960 TestFixThrow({ 1956 TestFixThrow({
1961 fix: function() { return this.fix2() }, 1957 fix: function() { return this.fix2() },
1962 fix2: function() { throw "myexn" } 1958 fix2: function() { throw "myexn" }
1963 }) 1959 })
1964 1960
1965 TestFixThrow({ 1961 TestFixThrow({
1966 get fix() { throw "myexn" } 1962 get fix() { throw "myexn" }
1967 }) 1963 })
1968 1964
1969 TestFixThrow({ 1965 TestFixThrow({
1970 get fix() { 1966 get fix() {
1971 return function() { throw "myexn" } 1967 return function() { throw "myexn" }
1972 } 1968 }
1973 }) 1969 })
1974 1970
1975 1971
1976 // Freeze a proxy in the middle of operations on it. 1972 // Freeze a proxy in the middle of operations on it.
1977 // TODO(rossberg): actual behaviour not specified consistently at the moment, 1973 // TODO(rossberg): actual behaviour not specified consistently at the moment,
1978 // just make sure that we do not crash. 1974 // just make sure that we do not crash.
1979 function TestReentrantFix(f) { 1975 function TestReentrantFix(f) {
1980 // TODO(neis): Reenable/adapt once proxies properly support these operations. 1976 TestWithProxies(f, Object.freeze)
1981 // 1977 TestWithProxies(f, Object.seal)
1982 // TestWithProxies(f, Object.freeze) 1978 TestWithProxies(f, Object.preventExtensions)
1983 // TestWithProxies(f, Object.seal)
1984 // TestWithProxies(f, Object.preventExtensions)
1985 } 1979 }
1986 1980
1987 TestReentrantFix(function(create, freeze) { 1981 TestReentrantFix(function(create, freeze) {
1988 var handler = { 1982 var handler = {
1989 get get() { freeze(p); return undefined }, 1983 get get() { freeze(p); return undefined },
1990 fix: function() { return {} } 1984 fix: function() { return {} }
1991 } 1985 }
1992 var p = create(handler) 1986 var p = create(handler)
1993 // Freeze while getting get trap. 1987 // Freeze while getting get trap.
1994 try { p.x } catch (e) { assertInstanceof(e, Error) } 1988 try { p.x } catch (e) { assertInstanceof(e, Error) }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
2329 function f() { 2323 function f() {
2330 return o.x; 2324 return o.x;
2331 } 2325 }
2332 assertEquals(10, f()); 2326 assertEquals(10, f());
2333 assertEquals(10, f()); 2327 assertEquals(10, f());
2334 %OptimizeFunctionOnNextCall(f); 2328 %OptimizeFunctionOnNextCall(f);
2335 assertEquals(10, f()); 2329 assertEquals(10, f());
2336 } 2330 }
2337 2331
2338 TestOptWithProxyPrototype(); 2332 TestOptWithProxyPrototype();
OLDNEW
« no previous file with comments | « test/mjsunit/for-in-opt.js ('k') | test/mjsunit/harmony/proxies-example-membrane.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698