From 233d62f8e306e56d5ed0597b008c205700e744bd Mon Sep 17 00:00:00 2001 From: adamk Date: Tue, 25 Aug 2015 14:10:34 -0700 Subject: [PATCH] [es6] Fix computed property names in nested literals Make ObjectLiteral::is_simple() false for literals containing computed property names, which causes IsCompileTimeValue() to return false and thus force code to be generated for setting up such properties. This mirrors the handling of '__proto__' in literals. BUG=v8:4387 LOG=y Review URL: https://codereview.chromium.org/1307943007 Cr-Commit-Position: refs/heads/master@{#30362} --- src/ast.cc | 1 + test/mjsunit/es6/computed-property-names.js | 56 +++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/ast.cc b/src/ast.cc index 624d46232..c61c29bf5 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -446,6 +446,7 @@ void ObjectLiteral::BuildConstantProperties(Isolate* isolate) { if (position == boilerplate_properties_ * 2) { DCHECK(property->is_computed_name()); + is_simple = false; break; } DCHECK(!property->is_computed_name()); diff --git a/test/mjsunit/es6/computed-property-names.js b/test/mjsunit/es6/computed-property-names.js index 80a047cc9..d75278cfe 100644 --- a/test/mjsunit/es6/computed-property-names.js +++ b/test/mjsunit/es6/computed-property-names.js @@ -298,3 +298,59 @@ function ID(x) { }; }, MyError); })(); + + +(function TestNestedLiterals() { + var array = [ + 42, + { a: 'A', + ['b']: 'B', + c: 'C', + [ID('d')]: 'D', + }, + 43, + ]; + assertEquals(42, array[0]); + assertEquals(43, array[2]); + assertEquals('A', array[1].a); + assertEquals('B', array[1].b); + assertEquals('C', array[1].c); + assertEquals('D', array[1].d); + var object = { + outer: 42, + inner: { + a: 'A', + ['b']: 'B', + c: 'C', + [ID('d')]: 'D', + }, + outer2: 43, + }; + assertEquals(42, object.outer); + assertEquals(43, object.outer2); + assertEquals('A', object.inner.a); + assertEquals('B', object.inner.b); + assertEquals('C', object.inner.c); + assertEquals('D', object.inner.d); + var object = { + outer: 42, + array: [ + 43, + { a: 'A', + ['b']: 'B', + c: 'C', + [ID('d')]: 'D', + }, + 44, + ], + outer2: 45 + }; + assertEquals(42, object.outer); + assertEquals(45, object.outer2); + assertEquals(43, object.array[0]); + assertEquals(44, object.array[2]); + assertEquals('A', object.array[1].a); + assertEquals('B', object.array[1].b); + assertEquals('C', object.array[1].c); + assertEquals('D', object.array[1].d); +})(); -- 2.34.1