From 58d695397906767c3d0d85ac012e1ee0baad2bee Mon Sep 17 00:00:00 2001 From: Toon Verwaest Date: Mon, 14 Nov 2016 10:49:23 +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/2497213003 . Cr-Commit-Position: refs/branch-heads/5.4@{#83} Cr-Branched-From: 5ce282769772d94937eb2cb88eb419a6890c8b2d-refs/heads/5.4.500@{#2} Cr-Branched-From: ad07b49d7b47b40a2d6f74d04d1b76ceae2a0253-refs/heads/master@{#38841} --- 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 54015d44c682..727465ee80ea 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -308,6 +308,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())); @@ -447,6 +452,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());