Chromium Code Reviews| Index: test/mjsunit/harmony/object-spread-basic.js |
| diff --git a/test/mjsunit/harmony/object-spread-basic.js b/test/mjsunit/harmony/object-spread-basic.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ab4d91d0a5b8ca4c522df974e3848f5a4a893dbc |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/object-spread-basic.js |
| @@ -0,0 +1,109 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --harmony-object-spread --allow-natives-syntax |
|
adamk
2017/01/05 22:39:14
No need for --allow-natives-syntax, that's only re
gsathya
2017/01/05 22:56:29
Done.
|
| + |
| +// assertEquals(42, proxy[symbol] = 42); |
| +// assertThrows(function() { "use strict"; proxy[symbol] = 42 }, TypeError); |
|
adamk
2017/01/05 22:39:14
What's up with these two lines?
gsathya
2017/01/05 22:56:29
copy paste fail
|
| + |
| +var x = {a: 1}; |
| +var y = { ...x}; |
| +assertEquals(x, y); |
| +assertEquals(x, y = { ...x}); |
|
adamk
2017/01/05 22:39:14
What is this testing that's different from the abo
gsathya
2017/01/05 22:56:29
testing AssignmentExpression actually, since i use
|
| + |
| +assertEquals({}, y = { ...{} } ); |
| +assertEquals({}, y = { ...undefined }); |
| +assertEquals({}, y = { ...null }); |
| + |
| +assertEquals({}, y = { ...1 }); |
| +assertEquals({0: 'f', 1: 'o', 2: 'o'}, y = { ...'foo' }); |
| +assertEquals({0: 0, 1: 1}, y = { ...[0, 1] }); |
| +assertEquals({}, { ...new Proxy({}, {}) }); |
| + |
| +assertEquals({a: 2}, y = { ...x, a: 2 }); |
| +assertEquals({a: 1, b: 1}, y = { ...x, b: 1 }); |
| +assertEquals({a: 1}, y = { a: 2, ...x }); |
| +assertEquals({a: 1, b: 1}, y = { a:2, ...x, b: 1 }); |
| +assertEquals({a: 3}, y = { a: 2, ...x, a: 3 }); |
| + |
| +var z = { b: 1} |
| +assertEquals({a: 1, b: 1}, y = { ...x, ...z }); |
| +assertEquals({a: 1, b: 1}, y = { a: 2, ...x, ...z }); |
| +assertEquals({a: 1, b: 1}, y = { b: 2, ...z, ...x }); |
| +assertEquals({a: 1, b: 1}, y = { a: 1, ...x, b: 2, ...z }); |
| +assertEquals({a: 1, b: 2}, y = { a: 1, ...x, ...z, b: 2 }); |
| +assertEquals({a: 2, b: 2}, y = { ...x, ...z, a:2, b: 2 }); |
| + |
| +var x = {} |
| +Object.defineProperty(x, 'a', { |
| + enumerable: false, |
| + configurable: false, |
| + writable: false, |
| + value: 1 |
| +}); |
| +assertEquals({}, { ...x }); |
| + |
| +var x = {} |
| +Object.defineProperty(x, 'a', { |
| + enumerable: true, |
| + configurable: false, |
| + writable: false, |
| + value: 1 |
| +}); |
| +var y = { ...x }; |
| +var prop = Object.getOwnPropertyDescriptor(y, 'a'); |
| +assertEquals(prop.value, 1); |
| +assertTrue(prop.enumerable); |
| +assertTrue(prop.configurable); |
| +assertTrue(prop.writable); |
| + |
| +var x = { __proto__: z } |
| +assertEquals({}, { ...x }); |
| + |
| +var x = { [1+1]: 2, ['a']: 1}; |
| +assertEquals({2: 2, a: 1}, y = { ...x }); |
|
adamk
2017/01/05 22:39:14
Don't think you need this test, it's just testing
gsathya
2017/01/05 22:56:29
Done.
|
| + |
| +var x = { |
| + get a() { return 1; }, |
| + set a(_) { assertUnreachable("setter called"); }, |
| +}; |
| +assertEquals({ a: 1 }, y = { ...x }); |
| + |
| +var x = { |
| + method() { return 1; }, |
| +}; |
| +assertEquals(x, y = { ...x }); |
| + |
| +var x = { |
| + *gen() { return {value: 1, done: true} ; }, |
| +}; |
| +assertEquals(x, y = { ...x }); |
| + |
| +var x = { |
| + get a() { throw new Error(); }, |
| +}; |
| +assertThrows(() => { y = { ...x } }); |
| + |
| +var p = new Proxy({}, { |
| + ownKeys() { throw new Error(); } |
| +}); |
| +assertThrows(() => { y = { ...p } }); |
| + |
| +var p = new Proxy({}, { |
| + ownKeys() { [1]; }, |
| + get() { throw new Error(); } |
| +}); |
| +assertThrows(() => { y = { ...p } }); |
| + |
| +var p = new Proxy({}, { |
| + ownKeys() { [1]; }, |
| + getOwnPropertyDescriptor() { throw new Error(); } |
| +}); |
| +assertThrows(() => { y = { ...p } }); |
|
adamk
2017/01/05 22:39:14
Can you also add a non-error, non-empty Proxy case
gsathya
2017/01/05 22:56:29
Done.
|
| + |
| +var x = { a:1 }; |
| +assertEquals(x, y = { set a(_) { throw new Error(); }, ...x }); |
| + |
| +var x = { a:1 }; |
| +assertEquals(x, y = { get a() { throw new Error(); }, ...x }); |