| Index: test/mjsunit/harmony/proxies-hash.js
|
| ===================================================================
|
| --- test/mjsunit/harmony/proxies-hash.js (revision 9808)
|
| +++ test/mjsunit/harmony/proxies-hash.js (working copy)
|
| @@ -25,42 +25,98 @@
|
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -// Flags: --harmony-proxies --harmony-weakmaps
|
| +// Flags: --harmony-proxies --harmony-collections
|
|
|
|
|
| // Helper.
|
|
|
| -function TestWithProxies(test, handler) {
|
| - test(handler, Proxy.create)
|
| - test(handler, function(h) {return Proxy.createFunction(h, function() {})})
|
| +function TestWithProxies(test, construct, handler) {
|
| + test(construct, handler, Proxy.create)
|
| + test(construct, handler, function(h) {
|
| + return Proxy.createFunction(h, function() {})
|
| + })
|
| }
|
|
|
|
|
| -// Weak maps.
|
| +// Sets.
|
|
|
| -function TestWeakMap(fix) {
|
| - TestWithProxies(TestWeakMap2, fix)
|
| +function TestSet(construct, fix) {
|
| + TestWithProxies(TestSet2, construct, fix)
|
| }
|
|
|
| -function TestWeakMap2(fix, create) {
|
| +function TestSet2(construct, fix, create) {
|
| var handler = {fix: function() { return {} }}
|
| var p1 = create(handler)
|
| var p2 = create(handler)
|
| var p3 = create(handler)
|
| fix(p3)
|
|
|
| - var m = new WeakMap
|
| + var s = construct();
|
| + s.add(p1);
|
| + s.add(p2);
|
| + assertTrue(s.has(p1));
|
| + assertTrue(s.has(p2));
|
| + assertFalse(s.has(p3));
|
| +
|
| + fix(p1)
|
| + fix(p2)
|
| + assertTrue(s.has(p1));
|
| + assertTrue(s.has(p2));
|
| + assertFalse(s.has(p3));
|
| +
|
| + s.delete(p2);
|
| + assertTrue(s.has(p1));
|
| + assertFalse(s.has(p2));
|
| + assertFalse(s.has(p3));
|
| +}
|
| +
|
| +TestSet(Set, Object.seal)
|
| +TestSet(Set, Object.freeze)
|
| +TestSet(Set, Object.preventExtensions)
|
| +
|
| +
|
| +// Maps and weak maps.
|
| +
|
| +function TestMap(construct, fix) {
|
| + TestWithProxies(TestMap2, construct, fix)
|
| +}
|
| +
|
| +function TestMap2(construct, fix, create) {
|
| + var handler = {fix: function() { return {} }}
|
| + var p1 = create(handler)
|
| + var p2 = create(handler)
|
| + var p3 = create(handler)
|
| + fix(p3)
|
| +
|
| + var m = construct();
|
| m.set(p1, 123);
|
| m.set(p2, 321);
|
| + assertTrue(m.has(p1));
|
| + assertTrue(m.has(p2));
|
| + assertFalse(m.has(p3));
|
| assertSame(123, m.get(p1));
|
| assertSame(321, m.get(p2));
|
|
|
| fix(p1)
|
| fix(p2)
|
| + assertTrue(m.has(p1));
|
| + assertTrue(m.has(p2));
|
| + assertFalse(m.has(p3));
|
| assertSame(123, m.get(p1));
|
| assertSame(321, m.get(p2));
|
| +
|
| + m.delete(p2);
|
| + assertTrue(m.has(p1));
|
| + assertFalse(m.has(p2));
|
| + assertFalse(m.has(p3));
|
| + assertSame(123, m.get(p1));
|
| + assertSame(undefined, m.get(p2));
|
| }
|
|
|
| -TestWeakMap(Object.seal)
|
| -TestWeakMap(Object.freeze)
|
| -TestWeakMap(Object.preventExtensions)
|
| +TestMap(Map, Object.seal)
|
| +TestMap(Map, Object.freeze)
|
| +TestMap(Map, Object.preventExtensions)
|
| +
|
| +TestMap(WeakMap, Object.seal)
|
| +TestMap(WeakMap, Object.freeze)
|
| +TestMap(WeakMap, Object.preventExtensions)
|
|
|