From 551fc556ace04a947ee20bd1ab8df36e1bd3c963 Mon Sep 17 00:00:00 2001 From: Toon Verwaest Date: Mon, 14 Nov 2016 10:52:33 +0100 Subject: [PATCH] Merged: Squashed multiple commits. Merged: Add test for making private symbols non-enumerable Revision: 942604dfb2895cf0e56173b271e66804ff41478a Merged: Make private symbols non-enumerable Revision: 135b9f9360342089de151990a7bf61c31caa6f1f BUG=chromium:664411,chromium:664411 LOG=N NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true R=cbruni@chromium.org Review URL: https://codereview.chromium.org/2498973002 . Cr-Commit-Position: refs/branch-heads/5.5@{#40} Cr-Branched-From: 3cbd5838bd8376103daa45d69dade929ee4e0092-refs/heads/5.5.372@{#1} Cr-Branched-From: b3c8b0ce2c9af0528837d8309625118d4096553b-refs/heads/master@{#40015} --- src/lookup.cc | 8 ++++++++ src/property.h | 3 +++ test/mjsunit/harmony/private.js | 4 ++-- test/mjsunit/regress/regress-private-enumerable.js | 8 ++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/mjsunit/regress/regress-private-enumerable.js diff --git a/src/lookup.cc b/src/lookup.cc index 3921e1657c85..b6c0b92a1751 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -307,6 +307,11 @@ void LookupIterator::PrepareTransitionToDataProperty( PropertyAttributes attributes, Object::StoreFromKeyed store_mode) { DCHECK(receiver.is_identical_to(GetStoreTarget())); if (state_ == TRANSITION) return; + + if (!IsElement() && name()->IsPrivate()) { + attributes = static_cast(attributes | DONT_ENUM); + } + DCHECK(state_ != LookupIterator::ACCESSOR || (GetAccessors()->IsAccessorInfo() && AccessorInfo::cast(*GetAccessors())->is_special_data_property())); @@ -441,6 +446,9 @@ void LookupIterator::TransitionToAccessorProperty( // handled via a trap. Adding properties to primitive values is not // observable. Handle receiver = GetStoreTarget(); + if (!IsElement() && name()->IsPrivate()) { + attributes = static_cast(attributes | DONT_ENUM); + } if (!IsElement() && !receiver->map()->is_dictionary_map()) { Handle old_map(receiver->map(), isolate_); diff --git a/src/property.h b/src/property.h index add9e4d11bfc..ebe7d3b6732a 100644 --- a/src/property.h +++ b/src/property.h @@ -36,6 +36,7 @@ class Descriptor BASE_EMBEDDED { void Init(Handle key, Handle value, PropertyDetails details) { DCHECK(key->IsUniqueName()); + DCHECK_IMPLIES(key->IsPrivate(), !details.IsEnumerable()); key_ = key; value_ = value; details_ = details; @@ -44,6 +45,7 @@ class Descriptor BASE_EMBEDDED { Descriptor(Handle key, Handle value, PropertyDetails details) : key_(key), value_(value), details_(details) { DCHECK(key->IsUniqueName()); + DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable()); } Descriptor(Handle key, Handle value, @@ -53,6 +55,7 @@ class Descriptor BASE_EMBEDDED { value_(value), details_(attributes, type, representation, field_index) { DCHECK(key->IsUniqueName()); + DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable()); } friend class DescriptorArray; diff --git a/test/mjsunit/harmony/private.js b/test/mjsunit/harmony/private.js index d44ff33aca44..7d34db40a8bf 100644 --- a/test/mjsunit/harmony/private.js +++ b/test/mjsunit/harmony/private.js @@ -278,8 +278,8 @@ function TestKeyDescriptor(obj) { assertEquals(i|0, desc.value) assertTrue(desc.configurable) assertEquals(i % 2 == 0, desc.writable) - assertEquals(i % 2 == 0, desc.enumerable) - assertEquals(i % 2 == 0, + assertEquals(false, desc.enumerable) + assertEquals(false, Object.prototype.propertyIsEnumerable.call(obj, symbols[i])) } } diff --git a/test/mjsunit/regress/regress-private-enumerable.js b/test/mjsunit/regress/regress-private-enumerable.js new file mode 100644 index 000000000000..ad41b51baec6 --- /dev/null +++ b/test/mjsunit/regress/regress-private-enumerable.js @@ -0,0 +1,8 @@ +// Copyright 2016 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. + +class A {} +class B {} +Object.assign(B, A); +assertEquals("class B {}", B.toString());