Commit a1a7cfd6 authored by wingo's avatar wingo Committed by Commit bot

All private symbols are own symbols

R=rossberg@chromium.org
LOG=N
BUG=

Review URL: https://codereview.chromium.org/1182303004

Cr-Commit-Position: refs/heads/master@{#29041}
parent 45439b92
...@@ -676,17 +676,9 @@ Handle<Symbol> Factory::NewSymbol() { ...@@ -676,17 +676,9 @@ Handle<Symbol> Factory::NewSymbol() {
} }
Handle<Symbol> Factory::NewPrivateSymbol() { Handle<Symbol> Factory::NewPrivateSymbol(Handle<Object> name) {
Handle<Symbol> symbol = NewSymbol(); Handle<Symbol> symbol = NewSymbol();
symbol->set_is_private(true); symbol->set_is_private(true);
return symbol;
}
Handle<Symbol> Factory::NewPrivateOwnSymbol(Handle<Object> name) {
Handle<Symbol> symbol = NewSymbol();
symbol->set_is_private(true);
symbol->set_is_own(true);
if (name->IsString()) { if (name->IsString()) {
symbol->set_name(*name); symbol->set_name(*name);
} else { } else {
......
...@@ -225,8 +225,7 @@ class Factory final { ...@@ -225,8 +225,7 @@ class Factory final {
// Create a symbol. // Create a symbol.
Handle<Symbol> NewSymbol(); Handle<Symbol> NewSymbol();
Handle<Symbol> NewPrivateSymbol(); Handle<Symbol> NewPrivateSymbol(Handle<Object> name);
Handle<Symbol> NewPrivateOwnSymbol(Handle<Object> name);
// Create a global (but otherwise uninitialized) context. // Create a global (but otherwise uninitialized) context.
Handle<Context> NewNativeContext(); Handle<Context> NewNativeContext();
......
...@@ -3265,7 +3265,7 @@ void Heap::CreateInitialObjects() { ...@@ -3265,7 +3265,7 @@ void Heap::CreateInitialObjects() {
#define SYMBOL_INIT(name) \ #define SYMBOL_INIT(name) \
{ \ { \
Handle<String> name##d = factory->NewStringFromStaticChars(#name); \ Handle<String> name##d = factory->NewStringFromStaticChars(#name); \
Handle<Object> symbol(isolate()->factory()->NewPrivateOwnSymbol(name##d)); \ Handle<Object> symbol(isolate()->factory()->NewPrivateSymbol(name##d)); \
roots_[k##name##RootIndex] = *symbol; \ roots_[k##name##RootIndex] = *symbol; \
} }
PRIVATE_SYMBOL_LIST(SYMBOL_INIT) PRIVATE_SYMBOL_LIST(SYMBOL_INIT)
......
...@@ -774,8 +774,7 @@ void Isolate::ReportFailedAccessCheck(Handle<JSObject> receiver) { ...@@ -774,8 +774,7 @@ void Isolate::ReportFailedAccessCheck(Handle<JSObject> receiver) {
bool Isolate::IsInternallyUsedPropertyName(Handle<Object> name) { bool Isolate::IsInternallyUsedPropertyName(Handle<Object> name) {
if (name->IsSymbol()) { if (name->IsSymbol()) {
return Handle<Symbol>::cast(name)->is_private() && return Handle<Symbol>::cast(name)->is_private();
Handle<Symbol>::cast(name)->is_own();
} }
return name.is_identical_to(factory()->hidden_string()); return name.is_identical_to(factory()->hidden_string());
} }
...@@ -783,7 +782,7 @@ bool Isolate::IsInternallyUsedPropertyName(Handle<Object> name) { ...@@ -783,7 +782,7 @@ bool Isolate::IsInternallyUsedPropertyName(Handle<Object> name) {
bool Isolate::IsInternallyUsedPropertyName(Object* name) { bool Isolate::IsInternallyUsedPropertyName(Object* name) {
if (name->IsSymbol()) { if (name->IsSymbol()) {
return Symbol::cast(name)->is_private() && Symbol::cast(name)->is_own(); return Symbol::cast(name)->is_private();
} }
return name == heap()->hidden_string(); return name == heap()->hidden_string();
} }
......
...@@ -277,7 +277,7 @@ class LookupIterator final BASE_EMBEDDED { ...@@ -277,7 +277,7 @@ class LookupIterator final BASE_EMBEDDED {
static Configuration ComputeConfiguration( static Configuration ComputeConfiguration(
Configuration configuration, Handle<Name> name) { Configuration configuration, Handle<Name> name) {
if (name->IsOwn()) { if (name->IsPrivate()) {
return static_cast<Configuration>(configuration & return static_cast<Configuration>(configuration &
HIDDEN_SKIP_INTERCEPTOR); HIDDEN_SKIP_INTERCEPTOR);
} else { } else {
......
...@@ -159,10 +159,8 @@ macro SHOULD_CREATE_WRAPPER(functionName, receiver) = (!IS_SPEC_OBJECT(receiver) ...@@ -159,10 +159,8 @@ macro SHOULD_CREATE_WRAPPER(functionName, receiver) = (!IS_SPEC_OBJECT(receiver)
macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array)); macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array));
# Private names. # Private names.
# GET_PRIVATE should only be used if the property is known to exists on obj macro GLOBAL_PRIVATE(name) = (%CreateGlobalPrivateSymbol(name));
# itself (it should really use %GetOwnProperty, but that would be way slower). macro NEW_PRIVATE(name) = (%CreatePrivateSymbol(name));
macro GLOBAL_PRIVATE(name) = (%CreateGlobalPrivateOwnSymbol(name));
macro NEW_PRIVATE_OWN(name) = (%CreatePrivateOwnSymbol(name));
macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym)); macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym));
macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym)); macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym));
macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym])); macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym]));
......
...@@ -543,10 +543,10 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) { ...@@ -543,10 +543,10 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Error implementation // Error implementation
var CallSiteReceiverKey = NEW_PRIVATE_OWN("CallSite#receiver"); var CallSiteReceiverKey = NEW_PRIVATE("CallSite#receiver");
var CallSiteFunctionKey = NEW_PRIVATE_OWN("CallSite#function"); var CallSiteFunctionKey = NEW_PRIVATE("CallSite#function");
var CallSitePositionKey = NEW_PRIVATE_OWN("CallSite#position"); var CallSitePositionKey = NEW_PRIVATE("CallSite#position");
var CallSiteStrictModeKey = NEW_PRIVATE_OWN("CallSite#strict_mode"); var CallSiteStrictModeKey = NEW_PRIVATE("CallSite#strict_mode");
function CallSite(receiver, fun, pos, strict_mode) { function CallSite(receiver, fun, pos, strict_mode) {
SET_PRIVATE(this, CallSiteReceiverKey, receiver); SET_PRIVATE(this, CallSiteReceiverKey, receiver);
...@@ -863,7 +863,7 @@ function GetTypeName(receiver, requireConstructor) { ...@@ -863,7 +863,7 @@ function GetTypeName(receiver, requireConstructor) {
return constructorName; return constructorName;
} }
var formatted_stack_trace_symbol = NEW_PRIVATE_OWN("formatted stack trace"); var formatted_stack_trace_symbol = NEW_PRIVATE("formatted stack trace");
// Format the stack trace if not yet done, and return it. // Format the stack trace if not yet done, and return it.
......
...@@ -3198,7 +3198,6 @@ bool Name::Equals(Handle<Name> one, Handle<Name> two) { ...@@ -3198,7 +3198,6 @@ bool Name::Equals(Handle<Name> one, Handle<Name> two) {
ACCESSORS(Symbol, name, Object, kNameOffset) ACCESSORS(Symbol, name, Object, kNameOffset)
ACCESSORS(Symbol, flags, Smi, kFlagsOffset) ACCESSORS(Symbol, flags, Smi, kFlagsOffset)
BOOL_ACCESSORS(Symbol, flags, is_private, kPrivateBit) BOOL_ACCESSORS(Symbol, flags, is_private, kPrivateBit)
BOOL_ACCESSORS(Symbol, flags, is_own, kOwnBit)
bool String::Equals(String* other) { bool String::Equals(String* other) {
...@@ -6400,8 +6399,9 @@ uint32_t Name::Hash() { ...@@ -6400,8 +6399,9 @@ uint32_t Name::Hash() {
return String::cast(this)->ComputeAndSetHash(); return String::cast(this)->ComputeAndSetHash();
} }
bool Name::IsOwn() {
return this->IsSymbol() && Symbol::cast(this)->is_own(); bool Name::IsPrivate() {
return this->IsSymbol() && Symbol::cast(this)->is_private();
} }
......
...@@ -402,7 +402,6 @@ void Symbol::SymbolPrint(std::ostream& os) { // NOLINT ...@@ -402,7 +402,6 @@ void Symbol::SymbolPrint(std::ostream& os) { // NOLINT
os << " (" << PrivateSymbolToName() << ")"; os << " (" << PrivateSymbolToName() << ")";
} }
os << "\n - private: " << is_private(); os << "\n - private: " << is_private();
os << "\n - own: " << is_own();
os << "\n"; os << "\n";
} }
......
...@@ -8581,8 +8581,8 @@ class Name: public HeapObject { ...@@ -8581,8 +8581,8 @@ class Name: public HeapObject {
// Conversion. // Conversion.
inline bool AsArrayIndex(uint32_t* index); inline bool AsArrayIndex(uint32_t* index);
// Whether name can only name own properties. // If the name is private, it can only name own properties.
inline bool IsOwn(); inline bool IsPrivate();
DECLARE_CAST(Name) DECLARE_CAST(Name)
...@@ -8660,18 +8660,15 @@ class Name: public HeapObject { ...@@ -8660,18 +8660,15 @@ class Name: public HeapObject {
// ES6 symbols. // ES6 symbols.
class Symbol: public Name { class Symbol: public Name {
public: public:
// [name]: the print name of a symbol, or undefined if none. // [name]: The print name of a symbol, or undefined if none.
DECL_ACCESSORS(name, Object) DECL_ACCESSORS(name, Object)
DECL_ACCESSORS(flags, Smi) DECL_ACCESSORS(flags, Smi)
// [is_private]: whether this is a private symbol. // [is_private]: Whether this is a private symbol. Private symbols can only
// be used to designate own properties of objects.
DECL_BOOLEAN_ACCESSORS(is_private) DECL_BOOLEAN_ACCESSORS(is_private)
// [is_own]: whether this is an own symbol, that is, only used to designate
// own properties of objects.
DECL_BOOLEAN_ACCESSORS(is_own)
DECLARE_CAST(Symbol) DECLARE_CAST(Symbol)
// Dispatched behavior. // Dispatched behavior.
...@@ -8689,7 +8686,6 @@ class Symbol: public Name { ...@@ -8689,7 +8686,6 @@ class Symbol: public Name {
private: private:
static const int kPrivateBit = 0; static const int kPrivateBit = 0;
static const int kOwnBit = 1;
const char* PrivateSymbolToName() const; const char* PrivateSymbolToName() const;
......
...@@ -26,22 +26,11 @@ RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) { ...@@ -26,22 +26,11 @@ RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) {
DCHECK(args.length() == 1); DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol(); return *isolate->factory()->NewPrivateSymbol(name);
if (name->IsString()) symbol->set_name(*name);
return *symbol;
}
RUNTIME_FUNCTION(Runtime_CreatePrivateOwnSymbol) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
return *isolate->factory()->NewPrivateOwnSymbol(name);
} }
RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateOwnSymbol) { RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateSymbol) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 1); DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(String, name, 0); CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
...@@ -55,7 +44,7 @@ RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateOwnSymbol) { ...@@ -55,7 +44,7 @@ RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateOwnSymbol) {
Object::GetProperty(privates, name)); Object::GetProperty(privates, name));
if (!symbol->IsSymbol()) { if (!symbol->IsSymbol()) {
DCHECK(symbol->IsUndefined()); DCHECK(symbol->IsUndefined());
symbol = isolate->factory()->NewPrivateOwnSymbol(name); symbol = isolate->factory()->NewPrivateSymbol(name);
JSObject::AddProperty(Handle<JSObject>::cast(privates), name, symbol, NONE); JSObject::AddProperty(Handle<JSObject>::cast(privates), name, symbol, NONE);
} }
return *symbol; return *symbol;
......
...@@ -589,8 +589,7 @@ namespace internal { ...@@ -589,8 +589,7 @@ namespace internal {
#define FOR_EACH_INTRINSIC_SYMBOL(F) \ #define FOR_EACH_INTRINSIC_SYMBOL(F) \
F(CreateSymbol, 1, 1) \ F(CreateSymbol, 1, 1) \
F(CreatePrivateSymbol, 1, 1) \ F(CreatePrivateSymbol, 1, 1) \
F(CreatePrivateOwnSymbol, 1, 1) \ F(CreateGlobalPrivateSymbol, 1, 1) \
F(CreateGlobalPrivateOwnSymbol, 1, 1) \
F(NewSymbolWrapper, 1, 1) \ F(NewSymbolWrapper, 1, 1) \
F(SymbolDescription, 1, 1) \ F(SymbolDescription, 1, 1) \
F(SymbolRegistry, 0, 1) \ F(SymbolRegistry, 0, 1) \
......
...@@ -241,7 +241,8 @@ function TestKeyGet(obj) { ...@@ -241,7 +241,8 @@ function TestKeyGet(obj) {
var obj2 = Object.create(obj) var obj2 = Object.create(obj)
for (var i in symbols) { for (var i in symbols) {
assertEquals(i|0, obj[symbols[i]]) assertEquals(i|0, obj[symbols[i]])
assertEquals(i|0, obj2[symbols[i]]) // Private symbols key own-properties.
assertEquals(undefined, obj2[symbols[i]])
} }
} }
...@@ -352,3 +353,52 @@ function TestSealAndFreeze(freeze) { ...@@ -352,3 +353,52 @@ function TestSealAndFreeze(freeze) {
TestSealAndFreeze(Object.seal) TestSealAndFreeze(Object.seal)
TestSealAndFreeze(Object.freeze) TestSealAndFreeze(Object.freeze)
TestSealAndFreeze(Object.preventExtensions) TestSealAndFreeze(Object.preventExtensions)
var s = %CreatePrivateSymbol("s");
var s1 = %CreatePrivateSymbol("s1");
function TestSimple() {
var p = {}
p[s] = "moo";
var o = Object.create(p);
assertEquals(undefined, o[s]);
assertEquals("moo", p[s]);
o[s] = "bow-wow";
assertEquals("bow-wow", o[s]);
assertEquals("moo", p[s]);
}
TestSimple();
function TestICs() {
var p = {}
p[s] = "moo";
var o = Object.create(p);
o[s1] = "bow-wow";
function checkNonOwn(o) {
assertEquals(undefined, o[s]);
assertEquals("bow-wow", o[s1]);
}
checkNonOwn(o);
// Test monomorphic/optimized.
for (var i = 0; i < 1000; i++) {
checkNonOwn(o);
}
// Test non-monomorphic.
for (var i = 0; i < 1000; i++) {
var oNew = Object.create(p);
oNew["s" + i] = i;
oNew[s1] = "bow-wow";
checkNonOwn(oNew);
}
}
TestICs();
// 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.
//
// Flags: --allow-natives-syntax
var s = %CreatePrivateOwnSymbol("s");
var s1 = %CreatePrivateOwnSymbol("s1");
function TestSimple() {
var p = {}
p[s] = "moo";
var o = Object.create(p);
assertEquals(undefined, o[s]);
assertEquals("moo", p[s]);
o[s] = "bow-wow";
assertEquals("bow-wow", o[s]);
assertEquals("moo", p[s]);
}
TestSimple();
function TestICs() {
var p = {}
p[s] = "moo";
var o = Object.create(p);
o[s1] = "bow-wow";
function checkNonOwn(o) {
assertEquals(undefined, o[s]);
assertEquals("bow-wow", o[s1]);
}
checkNonOwn(o);
// Test monomorphic/optimized.
for (var i = 0; i < 1000; i++) {
checkNonOwn(o);
}
// Test non-monomorphic.
for (var i = 0; i < 1000; i++) {
var oNew = Object.create(p);
oNew["s" + i] = i;
oNew[s1] = "bow-wow";
checkNonOwn(oNew);
}
}
TestICs();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment