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

Side by Side Diff: test/mjsunit/object-literal-computed-names.js

Issue 332443002: Add support for computed property names in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « src/x87/full-codegen-x87.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Test computed properties syntax.
6
7 // Flags: --harmony-symbols
8
9 function assertObjectEquals(expected, actual) {
10 var expected_props = Object.getOwnPropertyNames(expected);
11 var actual_props = Object.getOwnPropertyNames(actual);
12 expected_props += Object.getOwnPropertySymbols(expected);
13 actual_props += Object.getOwnPropertySymbols(actual);
14
15 assertEquals(expected_props.length, actual_props.length);
16 for (var i = 0; i < expected_props.length; i++) {
17 var prop = expected_props[i];
18 assertEquals(prop, actual_props[i]);
19 assertEquals(expected[prop], actual[prop]);
20 }
21 }
22
23 function preparse(str, strict) {
24 // Trigger the preparser by fooling it into thinking that the
25 // function is really big.
26 var buffer = '/* ' + (' ' * 4096) + '*/';
arv (Not doing code reviews) 2014/06/11 19:28:29 (' ' * 4096) This doesn't do what you think it do
27 var body = (strict ? '"use strict"; ' : '') + 'return ' + buffer + str;
28 return Function(body)();
29 }
30
31 function parse(str, strict) {
32 var indirect_eval = eval;
33 var body = (strict ? '"use strict"; ' : '') + '(' + str + ')';
34 return indirect_eval(body);
35 }
36
37 function test(expected, str) {
38 assertObjectEquals(expected, parse(str, true));
39 assertObjectEquals(expected, parse(str, false));
40 assertObjectEquals(expected, preparse(str, true));
41 assertObjectEquals(expected, preparse(str, false));
42 }
43
44 var sym = Symbol();
45 var expected_with_sym = {};
46 expected_with_sym[sym] = 'ohai';
47
arv (Not doing code reviews) 2014/06/11 19:28:29 Can you also add a test that ensures that a comput
48 test({foo: 42}, "{['foo']: 42}");
49 test({foo: 10}, "{['foo']: 42, foo: 10}");
50 test({foo: 42}, "{foo: 10, ['foo']: 42}");
51 test({foo: 42, bar: 35}, "{foo: 10, ['foo']: 42, bar: 35}");
52 test({foo: 42, bar: 35}, "{foo: 10, bar: 35, ['foo']: 42}");
53 test({bar: 35, foo: 42}, "{bar: 35, foo: 10, ['foo']: 42}");
54 test({bar: 35, foo: 10}, "{bar: 35, ['foo']: 42, foo: 10}");
55 test({bar: 35, foo: 10}, "{['bar']: 35, ['foo']: 42, foo: 10}");
56 test({bar: 35, foo: 42}, "{['bar']: 35, foo: 10, ['foo']: 42}");
57 test({foo: 42}, "{foo: 10, [1 ? 'foo' : 'bar']: 42}");
58 test({foo: 10, bar: 42}, "{foo: 10, [0 ? 'foo' : 'bar']: 42}");
59 test(expected_with_sym, "{[sym]: 'ohai'}");
60 test(expected_with_sym, "{[1 ? sym : 'foo']: 'ohai'}");
61 test({foo: 'ohai'}, "{[0 ? sym : 'foo']: 'ohai'}");
OLDNEW
« no previous file with comments | « src/x87/full-codegen-x87.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698