| Index: test/mjsunit/harmony/object-literal-computed-names.js
|
| diff --git a/test/mjsunit/harmony/object-literal-computed-names.js b/test/mjsunit/harmony/object-literal-computed-names.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c8e408e8bf298b087d45f53e284a7e7fbfe732dd
|
| --- /dev/null
|
| +++ b/test/mjsunit/harmony/object-literal-computed-names.js
|
| @@ -0,0 +1,74 @@
|
| +// Copyright 2014 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.
|
| +
|
| +// Test computed properties syntax.
|
| +
|
| +// Flags: --harmony-object-literals --harmony-symbols --harmony-strings
|
| +
|
| +function assertObjectEquals(expected, actual) {
|
| + var expected_props = Object.getOwnPropertyNames(expected);
|
| + var actual_props = Object.getOwnPropertyNames(actual);
|
| + expected_props += Object.getOwnPropertySymbols(expected);
|
| + actual_props += Object.getOwnPropertySymbols(actual);
|
| +
|
| + assertEquals(expected_props.length, actual_props.length);
|
| + for (var i = 0; i < expected_props.length; i++) {
|
| + var prop = expected_props[i];
|
| + assertEquals(prop, actual_props[i]);
|
| + assertEquals(expected[prop], actual[prop]);
|
| + }
|
| +}
|
| +
|
| +function preparse(str, strict) {
|
| + // Trigger the preparser by fooling it into thinking that the
|
| + // function is really big.
|
| + var buffer = '/* ' + ' '.repeat(4096) + '*/';
|
| + var body = (strict ? '"use strict"; ' : '') + 'return ' + buffer + str;
|
| + var indirect_eval = eval;
|
| + var f = 'function preparsed_function() {' + body + '}'
|
| + indirect_eval(f);
|
| + return preparsed_function();
|
| +}
|
| +
|
| +function parse(str, strict) {
|
| + var indirect_eval = eval;
|
| + var body = (strict ? '"use strict"; ' : '') + '(' + str + ')';
|
| + return indirect_eval(body);
|
| +}
|
| +
|
| +function test(expected, str) {
|
| + assertObjectEquals(expected, parse(str, true));
|
| + assertObjectEquals(expected, parse(str, false));
|
| + assertObjectEquals(expected, preparse(str, true));
|
| + assertObjectEquals(expected, preparse(str, false));
|
| +}
|
| +
|
| +var sym = Symbol();
|
| +var expected_with_sym = {};
|
| +expected_with_sym[sym] = 'ohai';
|
| +
|
| +test({foo: 42}, "{['foo']: 42}");
|
| +test({foo: 10}, "{['foo']: 42, foo: 10}");
|
| +test({foo: 42}, "{foo: 10, ['foo']: 42}");
|
| +test({foo: 42, bar: 35}, "{foo: 10, ['foo']: 42, bar: 35}");
|
| +test({foo: 42, bar: 35}, "{foo: 10, bar: 35, ['foo']: 42}");
|
| +test({bar: 35, foo: 42}, "{bar: 35, foo: 10, ['foo']: 42}");
|
| +test({bar: 35, foo: 10}, "{bar: 35, ['foo']: 42, foo: 10}");
|
| +test({bar: 35, foo: 10}, "{['bar']: 35, ['foo']: 42, foo: 10}");
|
| +test({bar: 35, foo: 42}, "{['bar']: 35, foo: 10, ['foo']: 42}");
|
| +test({foo: 42}, "{foo: 10, [1 ? 'foo' : 'bar']: 42}");
|
| +test({foo: 10, bar: 42}, "{foo: 10, [0 ? 'foo' : 'bar']: 42}");
|
| +test(expected_with_sym, "{[sym]: 'ohai'}");
|
| +test(expected_with_sym, "{[1 ? sym : 'foo']: 'ohai'}");
|
| +test({foo: 'ohai'}, "{[0 ? sym : 'foo']: 'ohai'}");
|
| +test({foo: 42}, "{['foo']: 10, get foo() { return 42 }}");
|
| +test({foo: 10}, "{get foo() { return 42 }, ['foo']: 10}");
|
| +test({0: 10}, "{0: 42, [0]: 10}");
|
| +test({0: 10}, "{[0]: 42, 0: 10}");
|
| +
|
| +var test_proto = {};
|
| +var test_obj = {['__proto__']: test_proto};
|
| +assertEquals(Object.prototype, Object.getPrototypeOf(test_obj));
|
| +assertTrue(test_obj.hasOwnProperty('__proto__'));
|
| +assertEquals(test_proto, test_obj.__proto__);
|
|
|