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

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

Issue 1427743011: [proxies] Remove "fix" functionality, add (still unused) target property. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Test 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 | « src/runtime/runtime-proxy.cc ('k') | test/mjsunit/harmony/proxies-function.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 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 }, 1817 },
1818 getOwnPropertyDescriptor: function(k) { throw "myexn" } 1818 getOwnPropertyDescriptor: function(k) { throw "myexn" }
1819 }) 1819 })
1820 1820
1821 1821
1822 1822
1823 // Fixing (Object.freeze, Object.seal, Object.preventExtensions, 1823 // Fixing (Object.freeze, Object.seal, Object.preventExtensions,
1824 // Object.isFrozen, Object.isSealed, Object.isExtensible) 1824 // Object.isFrozen, Object.isSealed, Object.isExtensible)
1825 1825
1826 function TestFix(names, handler) { 1826 function TestFix(names, handler) {
1827 var proto = {p: 77} 1827 // TODO(neis): Reenable/adapt once proxies properly support these operations.
1828 var assertFixing = function(o, s, f, e) { 1828 //
1829 assertEquals(s, Object.isSealed(o)) 1829 // var proto = {p: 77}
1830 assertEquals(f, Object.isFrozen(o)) 1830 // var assertFixing = function(o, s, f, e) {
1831 assertEquals(e, Object.isExtensible(o)) 1831 // assertEquals(s, Object.isSealed(o))
1832 } 1832 // assertEquals(f, Object.isFrozen(o))
1833 1833 // assertEquals(e, Object.isExtensible(o))
1834 var p1 = Proxy.create(handler, proto) 1834 // }
1835 assertFixing(p1, false, false, true) 1835 //
1836 Object.seal(p1) 1836 // var p1 = Proxy.create(handler, proto)
1837 assertFixing(p1, true, names.length === 0, false) 1837 // assertFixing(p1, false, false, true)
1838 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p1).sort()) 1838 // Object.seal(p1)
1839 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), 1839 // assertFixing(p1, true, names.length === 0, false)
1840 Object.keys(p1).sort()) 1840 // assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p1).sort())
1841 assertEquals(proto, Object.getPrototypeOf(p1)) 1841 // assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
1842 assertEquals(77, p1.p) 1842 // Object.keys(p1).sort())
1843 for (var n in p1) { 1843 // assertEquals(proto, Object.getPrototypeOf(p1))
1844 var desc = Object.getOwnPropertyDescriptor(p1, n) 1844 // assertEquals(77, p1.p)
1845 if (desc !== undefined) assertFalse(desc.configurable) 1845 // for (var n in p1) {
1846 } 1846 // var desc = Object.getOwnPropertyDescriptor(p1, n)
1847 1847 // if (desc !== undefined) assertFalse(desc.configurable)
1848 var p2 = Proxy.create(handler, proto) 1848 // }
1849 assertFixing(p2, false, false, true) 1849 //
1850 Object.freeze(p2) 1850 // var p2 = Proxy.create(handler, proto)
1851 assertFixing(p2, true, true, false) 1851 // assertFixing(p2, false, false, true)
1852 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p2).sort()) 1852 // Object.freeze(p2)
1853 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), 1853 // assertFixing(p2, true, true, false)
1854 Object.keys(p2).sort()) 1854 // assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p2).sort())
1855 assertEquals(proto, Object.getPrototypeOf(p2)) 1855 // assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
1856 assertEquals(77, p2.p) 1856 // Object.keys(p2).sort())
1857 for (var n in p2) { 1857 // assertEquals(proto, Object.getPrototypeOf(p2))
1858 var desc = Object.getOwnPropertyDescriptor(p2, n) 1858 // assertEquals(77, p2.p)
1859 if (desc !== undefined) assertFalse(desc.writable) 1859 // for (var n in p2) {
1860 if (desc !== undefined) assertFalse(desc.configurable) 1860 // var desc = Object.getOwnPropertyDescriptor(p2, n)
1861 } 1861 // if (desc !== undefined) assertFalse(desc.writable)
1862 1862 // if (desc !== undefined) assertFalse(desc.configurable)
1863 var p3 = Proxy.create(handler, proto) 1863 // }
1864 assertFixing(p3, false, false, true) 1864 //
1865 Object.preventExtensions(p3) 1865 // var p3 = Proxy.create(handler, proto)
1866 assertFixing(p3, names.length === 0, names.length === 0, false) 1866 // assertFixing(p3, false, false, true)
1867 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort()) 1867 // Object.preventExtensions(p3)
1868 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), 1868 // assertFixing(p3, names.length === 0, names.length === 0, false)
1869 Object.keys(p3).sort()) 1869 // assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort())
1870 assertEquals(proto, Object.getPrototypeOf(p3)) 1870 // assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
1871 assertEquals(77, p3.p) 1871 // Object.keys(p3).sort())
1872 1872 // assertEquals(proto, Object.getPrototypeOf(p3))
1873 var p = Proxy.create(handler, proto) 1873 // assertEquals(77, p3.p)
1874 var o = Object.create(p) 1874 //
1875 assertFixing(p, false, false, true) 1875 // var p = Proxy.create(handler, proto)
1876 assertFixing(o, false, false, true) 1876 // var o = Object.create(p)
1877 Object.freeze(o) 1877 // assertFixing(p, false, false, true)
1878 assertFixing(p, false, false, true) 1878 // assertFixing(o, false, false, true)
1879 assertFixing(o, true, true, false) 1879 // Object.freeze(o)
1880 // assertFixing(p, false, false, true)
1881 // assertFixing(o, true, true, false)
1880 } 1882 }
1881 1883
1882 TestFix([], { 1884 TestFix([], {
1883 fix: function() { return {} } 1885 fix: function() { return {} }
1884 }) 1886 })
1885 1887
1886 TestFix(["a", "b", "c", "3", "zz"], { 1888 TestFix(["a", "b", "c", "3", "zz"], {
1887 fix: function() { 1889 fix: function() {
1888 return { 1890 return {
1889 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
1905 TestFix(["b"], { 1907 TestFix(["b"], {
1906 get fix() { 1908 get fix() {
1907 return function() { 1909 return function() {
1908 return {b: {configurable: true, writable: true, enumerable: true}} 1910 return {b: {configurable: true, writable: true, enumerable: true}}
1909 } 1911 }
1910 } 1912 }
1911 }) 1913 })
1912 1914
1913 1915
1914 function TestFixFunction(fix) { 1916 function TestFixFunction(fix) {
1915 var f1 = Proxy.createFunction({ 1917 // TODO(neis): Reenable/adapt once proxies properly support these operations.
1916 fix: function() { return {} } 1918 //
1917 }, function() {}) 1919 // var f1 = Proxy.createFunction({
1918 fix(f1) 1920 // fix: function() { return {} }
1919 assertEquals(0, f1.length) 1921 // }, function() {})
1920 1922 // fix(f1)
1921 var f2 = Proxy.createFunction({ 1923 // assertEquals(0, f1.length)
1922 fix: function() { return {length: {value: 3}} } 1924 //
1923 }, function() {}) 1925 // var f2 = Proxy.createFunction({
1924 fix(f2) 1926 // fix: function() { return {length: {value: 3}} }
1925 assertEquals(3, f2.length) 1927 // }, function() {})
1926 1928 // fix(f2)
1927 var f3 = Proxy.createFunction({ 1929 // assertEquals(3, f2.length)
1928 fix: function() { return {length: {value: "huh"}} } 1930 //
1929 }, function() {}) 1931 // var f3 = Proxy.createFunction({
1930 fix(f3) 1932 // fix: function() { return {length: {value: "huh"}} }
1931 assertEquals(0, f1.length) 1933 // }, function() {})
1934 // fix(f3)
1935 // assertEquals(0, f1.length)
1932 } 1936 }
1933 1937
1934 TestFixFunction(Object.seal) 1938 TestFixFunction(Object.seal)
1935 TestFixFunction(Object.freeze) 1939 TestFixFunction(Object.freeze)
1936 TestFixFunction(Object.preventExtensions) 1940 TestFixFunction(Object.preventExtensions)
1937 1941
1938 1942
1939 function TestFixThrow(handler) { 1943 function TestFixThrow(handler) {
1940 TestWithProxies(TestFixThrow2, handler) 1944 TestWithProxies(TestFixThrow2, handler)
1941 } 1945 }
1942 1946
1943 function TestFixThrow2(create, handler) { 1947 function TestFixThrow2(create, handler) {
1944 var p = create(handler, {}) 1948 // TODO(neis): Reenable/adapt once proxies properly support these operations.
1945 assertThrows(function(){ Object.seal(p) }, "myexn") 1949 //
1946 assertThrows(function(){ Object.freeze(p) }, "myexn") 1950 // var p = create(handler, {})
1947 assertThrows(function(){ Object.preventExtensions(p) }, "myexn") 1951 // assertThrows(function(){ Object.seal(p) }, "myexn")
1952 // assertThrows(function(){ Object.freeze(p) }, "myexn")
1953 // assertThrows(function(){ Object.preventExtensions(p) }, "myexn")
1948 } 1954 }
1949 1955
1950 TestFixThrow({ 1956 TestFixThrow({
1951 fix: function() { throw "myexn" } 1957 fix: function() { throw "myexn" }
1952 }) 1958 })
1953 1959
1954 TestFixThrow({ 1960 TestFixThrow({
1955 fix: function() { return this.fix2() }, 1961 fix: function() { return this.fix2() },
1956 fix2: function() { throw "myexn" } 1962 fix2: function() { throw "myexn" }
1957 }) 1963 })
1958 1964
1959 TestFixThrow({ 1965 TestFixThrow({
1960 get fix() { throw "myexn" } 1966 get fix() { throw "myexn" }
1961 }) 1967 })
1962 1968
1963 TestFixThrow({ 1969 TestFixThrow({
1964 get fix() { 1970 get fix() {
1965 return function() { throw "myexn" } 1971 return function() { throw "myexn" }
1966 } 1972 }
1967 }) 1973 })
1968 1974
1969 1975
1970 // Freeze a proxy in the middle of operations on it. 1976 // Freeze a proxy in the middle of operations on it.
1971 // TODO(rossberg): actual behaviour not specified consistently at the moment, 1977 // TODO(rossberg): actual behaviour not specified consistently at the moment,
1972 // just make sure that we do not crash. 1978 // just make sure that we do not crash.
1973 function TestReentrantFix(f) { 1979 function TestReentrantFix(f) {
1974 TestWithProxies(f, Object.freeze) 1980 // TODO(neis): Reenable/adapt once proxies properly support these operations.
1975 TestWithProxies(f, Object.seal) 1981 //
1976 TestWithProxies(f, Object.preventExtensions) 1982 // TestWithProxies(f, Object.freeze)
1983 // TestWithProxies(f, Object.seal)
1984 // TestWithProxies(f, Object.preventExtensions)
1977 } 1985 }
1978 1986
1979 TestReentrantFix(function(create, freeze) { 1987 TestReentrantFix(function(create, freeze) {
1980 var handler = { 1988 var handler = {
1981 get get() { freeze(p); return undefined }, 1989 get get() { freeze(p); return undefined },
1982 fix: function() { return {} } 1990 fix: function() { return {} }
1983 } 1991 }
1984 var p = create(handler) 1992 var p = create(handler)
1985 // Freeze while getting get trap. 1993 // Freeze while getting get trap.
1986 try { p.x } catch (e) { assertInstanceof(e, Error) } 1994 try { p.x } catch (e) { assertInstanceof(e, Error) }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 function f() { 2329 function f() {
2322 return o.x; 2330 return o.x;
2323 } 2331 }
2324 assertEquals(10, f()); 2332 assertEquals(10, f());
2325 assertEquals(10, f()); 2333 assertEquals(10, f());
2326 %OptimizeFunctionOnNextCall(f); 2334 %OptimizeFunctionOnNextCall(f);
2327 assertEquals(10, f()); 2335 assertEquals(10, f());
2328 } 2336 }
2329 2337
2330 TestOptWithProxyPrototype(); 2338 TestOptWithProxyPrototype();
OLDNEW
« no previous file with comments | « src/runtime/runtime-proxy.cc ('k') | test/mjsunit/harmony/proxies-function.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698