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'}"); |