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}
This commit is contained in:
parent
45439b92e7
commit
a1a7cfd6ba
@ -676,17 +676,9 @@ Handle<Symbol> Factory::NewSymbol() {
|
||||
}
|
||||
|
||||
|
||||
Handle<Symbol> Factory::NewPrivateSymbol() {
|
||||
Handle<Symbol> Factory::NewPrivateSymbol(Handle<Object> name) {
|
||||
Handle<Symbol> symbol = NewSymbol();
|
||||
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()) {
|
||||
symbol->set_name(*name);
|
||||
} else {
|
||||
|
@ -225,8 +225,7 @@ class Factory final {
|
||||
|
||||
// Create a symbol.
|
||||
Handle<Symbol> NewSymbol();
|
||||
Handle<Symbol> NewPrivateSymbol();
|
||||
Handle<Symbol> NewPrivateOwnSymbol(Handle<Object> name);
|
||||
Handle<Symbol> NewPrivateSymbol(Handle<Object> name);
|
||||
|
||||
// Create a global (but otherwise uninitialized) context.
|
||||
Handle<Context> NewNativeContext();
|
||||
|
@ -3262,11 +3262,11 @@ void Heap::CreateInitialObjects() {
|
||||
|
||||
{
|
||||
HandleScope scope(isolate());
|
||||
#define SYMBOL_INIT(name) \
|
||||
{ \
|
||||
Handle<String> name##d = factory->NewStringFromStaticChars(#name); \
|
||||
Handle<Object> symbol(isolate()->factory()->NewPrivateOwnSymbol(name##d)); \
|
||||
roots_[k##name##RootIndex] = *symbol; \
|
||||
#define SYMBOL_INIT(name) \
|
||||
{ \
|
||||
Handle<String> name##d = factory->NewStringFromStaticChars(#name); \
|
||||
Handle<Object> symbol(isolate()->factory()->NewPrivateSymbol(name##d)); \
|
||||
roots_[k##name##RootIndex] = *symbol; \
|
||||
}
|
||||
PRIVATE_SYMBOL_LIST(SYMBOL_INIT)
|
||||
#undef SYMBOL_INIT
|
||||
|
@ -774,8 +774,7 @@ void Isolate::ReportFailedAccessCheck(Handle<JSObject> receiver) {
|
||||
|
||||
bool Isolate::IsInternallyUsedPropertyName(Handle<Object> name) {
|
||||
if (name->IsSymbol()) {
|
||||
return Handle<Symbol>::cast(name)->is_private() &&
|
||||
Handle<Symbol>::cast(name)->is_own();
|
||||
return Handle<Symbol>::cast(name)->is_private();
|
||||
}
|
||||
return name.is_identical_to(factory()->hidden_string());
|
||||
}
|
||||
@ -783,7 +782,7 @@ bool Isolate::IsInternallyUsedPropertyName(Handle<Object> name) {
|
||||
|
||||
bool Isolate::IsInternallyUsedPropertyName(Object* name) {
|
||||
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();
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ class LookupIterator final BASE_EMBEDDED {
|
||||
|
||||
static Configuration ComputeConfiguration(
|
||||
Configuration configuration, Handle<Name> name) {
|
||||
if (name->IsOwn()) {
|
||||
if (name->IsPrivate()) {
|
||||
return static_cast<Configuration>(configuration &
|
||||
HIDDEN_SKIP_INTERCEPTOR);
|
||||
} else {
|
||||
|
@ -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));
|
||||
|
||||
# Private names.
|
||||
# GET_PRIVATE should only be used if the property is known to exists on obj
|
||||
# itself (it should really use %GetOwnProperty, but that would be way slower).
|
||||
macro GLOBAL_PRIVATE(name) = (%CreateGlobalPrivateOwnSymbol(name));
|
||||
macro NEW_PRIVATE_OWN(name) = (%CreatePrivateOwnSymbol(name));
|
||||
macro GLOBAL_PRIVATE(name) = (%CreateGlobalPrivateSymbol(name));
|
||||
macro NEW_PRIVATE(name) = (%CreatePrivateSymbol(name));
|
||||
macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym));
|
||||
macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym));
|
||||
macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym]));
|
||||
|
@ -543,10 +543,10 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) {
|
||||
// ----------------------------------------------------------------------------
|
||||
// Error implementation
|
||||
|
||||
var CallSiteReceiverKey = NEW_PRIVATE_OWN("CallSite#receiver");
|
||||
var CallSiteFunctionKey = NEW_PRIVATE_OWN("CallSite#function");
|
||||
var CallSitePositionKey = NEW_PRIVATE_OWN("CallSite#position");
|
||||
var CallSiteStrictModeKey = NEW_PRIVATE_OWN("CallSite#strict_mode");
|
||||
var CallSiteReceiverKey = NEW_PRIVATE("CallSite#receiver");
|
||||
var CallSiteFunctionKey = NEW_PRIVATE("CallSite#function");
|
||||
var CallSitePositionKey = NEW_PRIVATE("CallSite#position");
|
||||
var CallSiteStrictModeKey = NEW_PRIVATE("CallSite#strict_mode");
|
||||
|
||||
function CallSite(receiver, fun, pos, strict_mode) {
|
||||
SET_PRIVATE(this, CallSiteReceiverKey, receiver);
|
||||
@ -863,7 +863,7 @@ function GetTypeName(receiver, requireConstructor) {
|
||||
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.
|
||||
|
@ -3198,7 +3198,6 @@ bool Name::Equals(Handle<Name> one, Handle<Name> two) {
|
||||
ACCESSORS(Symbol, name, Object, kNameOffset)
|
||||
ACCESSORS(Symbol, flags, Smi, kFlagsOffset)
|
||||
BOOL_ACCESSORS(Symbol, flags, is_private, kPrivateBit)
|
||||
BOOL_ACCESSORS(Symbol, flags, is_own, kOwnBit)
|
||||
|
||||
|
||||
bool String::Equals(String* other) {
|
||||
@ -6400,8 +6399,9 @@ uint32_t Name::Hash() {
|
||||
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
|
||||
os << " (" << PrivateSymbolToName() << ")";
|
||||
}
|
||||
os << "\n - private: " << is_private();
|
||||
os << "\n - own: " << is_own();
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
|
@ -8581,8 +8581,8 @@ class Name: public HeapObject {
|
||||
// Conversion.
|
||||
inline bool AsArrayIndex(uint32_t* index);
|
||||
|
||||
// Whether name can only name own properties.
|
||||
inline bool IsOwn();
|
||||
// If the name is private, it can only name own properties.
|
||||
inline bool IsPrivate();
|
||||
|
||||
DECLARE_CAST(Name)
|
||||
|
||||
@ -8660,18 +8660,15 @@ class Name: public HeapObject {
|
||||
// ES6 symbols.
|
||||
class Symbol: public Name {
|
||||
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(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)
|
||||
|
||||
// [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)
|
||||
|
||||
// Dispatched behavior.
|
||||
@ -8689,7 +8686,6 @@ class Symbol: public Name {
|
||||
|
||||
private:
|
||||
static const int kPrivateBit = 0;
|
||||
static const int kOwnBit = 1;
|
||||
|
||||
const char* PrivateSymbolToName() const;
|
||||
|
||||
|
@ -26,22 +26,11 @@ RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) {
|
||||
DCHECK(args.length() == 1);
|
||||
CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
|
||||
RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
|
||||
Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol();
|
||||
if (name->IsString()) symbol->set_name(*name);
|
||||
return *symbol;
|
||||
return *isolate->factory()->NewPrivateSymbol(name);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
DCHECK(args.length() == 1);
|
||||
CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
|
||||
@ -55,7 +44,7 @@ RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateOwnSymbol) {
|
||||
Object::GetProperty(privates, name));
|
||||
if (!symbol->IsSymbol()) {
|
||||
DCHECK(symbol->IsUndefined());
|
||||
symbol = isolate->factory()->NewPrivateOwnSymbol(name);
|
||||
symbol = isolate->factory()->NewPrivateSymbol(name);
|
||||
JSObject::AddProperty(Handle<JSObject>::cast(privates), name, symbol, NONE);
|
||||
}
|
||||
return *symbol;
|
||||
|
@ -586,14 +586,13 @@ namespace internal {
|
||||
F(StringGetLength, 1, 1)
|
||||
|
||||
|
||||
#define FOR_EACH_INTRINSIC_SYMBOL(F) \
|
||||
F(CreateSymbol, 1, 1) \
|
||||
F(CreatePrivateSymbol, 1, 1) \
|
||||
F(CreatePrivateOwnSymbol, 1, 1) \
|
||||
F(CreateGlobalPrivateOwnSymbol, 1, 1) \
|
||||
F(NewSymbolWrapper, 1, 1) \
|
||||
F(SymbolDescription, 1, 1) \
|
||||
F(SymbolRegistry, 0, 1) \
|
||||
#define FOR_EACH_INTRINSIC_SYMBOL(F) \
|
||||
F(CreateSymbol, 1, 1) \
|
||||
F(CreatePrivateSymbol, 1, 1) \
|
||||
F(CreateGlobalPrivateSymbol, 1, 1) \
|
||||
F(NewSymbolWrapper, 1, 1) \
|
||||
F(SymbolDescription, 1, 1) \
|
||||
F(SymbolRegistry, 0, 1) \
|
||||
F(SymbolIsPrivate, 1, 1)
|
||||
|
||||
|
||||
|
@ -241,7 +241,8 @@ function TestKeyGet(obj) {
|
||||
var obj2 = Object.create(obj)
|
||||
for (var i in symbols) {
|
||||
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) {
|
||||
TestSealAndFreeze(Object.seal)
|
||||
TestSealAndFreeze(Object.freeze)
|
||||
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();
|
||||
|
@ -1,55 +0,0 @@
|
||||
// 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();
|
Loading…
Reference in New Issue
Block a user