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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/x87/full-codegen-x87.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/object-literal-computed-names.js
diff --git a/test/mjsunit/object-literal-computed-names.js b/test/mjsunit/object-literal-computed-names.js
new file mode 100644
index 0000000000000000000000000000000000000000..b42977de1e9118d4b18f5bf36885f809b4337d9d
--- /dev/null
+++ b/test/mjsunit/object-literal-computed-names.js
@@ -0,0 +1,61 @@
+// 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-symbols
+
+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 = '/* ' + (' ' * 4096) + '*/';
arv (Not doing code reviews) 2014/06/11 19:28:29 (' ' * 4096) This doesn't do what you think it do
+ var body = (strict ? '"use strict"; ' : '') + 'return ' + buffer + str;
+ return Function(body)();
+}
+
+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';
+
arv (Not doing code reviews) 2014/06/11 19:28:29 Can you also add a test that ensures that a comput
+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'}");
« 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