Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(606)

Unified Diff: src/runtime.cc

Issue 12330012: ES6 symbols: Allow symbols as property names (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Platform ports Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/proxy.js ('k') | src/runtime.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index a3690c45c3f163238284a41706b8adb73eee5bce..a8a0b4f8d35bfa4e8bddbcc0e4db46cf0bbba2bd 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -1045,7 +1045,7 @@ static AccessCheckResult CheckElementAccess(
static AccessCheckResult CheckPropertyAccess(
JSObject* obj,
- String* name,
+ Name* name,
v8::AccessType access_type) {
uint32_t index;
if (name->AsArrayIndex(&index)) {
@@ -1105,7 +1105,7 @@ enum PropertyDescriptorIndices {
static MaybeObject* GetOwnProperty(Isolate* isolate,
Handle<JSObject> obj,
- Handle<String> name) {
+ Handle<Name> name) {
Heap* heap = isolate->heap();
// Due to some WebKit tests, we want to make sure that we do not log
// more than one access failure here.
@@ -1159,7 +1159,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOwnProperty) {
ASSERT(args.length() == 2);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
- CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
+ CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
return GetOwnProperty(isolate, obj, name);
}
@@ -2116,7 +2116,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionSetReadOnlyPrototype) {
} else { // Dictionary properties.
// Directly manipulate the property details.
int entry = function->property_dictionary()->FindEntry(name);
- ASSERT(entry != StringDictionary::kNotFound);
+ ASSERT(entry != NameDictionary::kNotFound);
PropertyDetails details = function->property_dictionary()->DetailsAt(entry);
PropertyDetails new_details(
static_cast<PropertyAttributes>(details.attributes() | READ_ONLY),
@@ -3929,16 +3929,16 @@ MaybeObject* Runtime::GetObjectProperty(Isolate* isolate,
return GetElementOrCharAt(isolate, object, index);
}
- // Convert the key to a string - possibly by calling back into JavaScript.
- Handle<String> name;
- if (key->IsString()) {
- name = Handle<String>::cast(key);
+ // Convert the key to a name - possibly by calling back into JavaScript.
+ Handle<Name> name;
+ if (key->IsName()) {
+ name = Handle<Name>::cast(key);
} else {
bool has_pending_exception = false;
Handle<Object> converted =
Execution::ToString(key, &has_pending_exception);
if (has_pending_exception) return Failure::Exception();
- name = Handle<String>::cast(converted);
+ name = Handle<Name>::cast(converted);
}
// Check if the name is trivially convertible to an index and get
@@ -3962,7 +3962,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetProperty) {
}
-// KeyedStringGetProperty is called from KeyedLoadIC::GenerateGeneric.
+// KeyedGetProperty is called from KeyedLoadIC::GenerateGeneric.
RUNTIME_FUNCTION(MaybeObject*, Runtime_KeyedGetProperty) {
NoHandleAllocation ha;
ASSERT(args.length() == 2);
@@ -3981,9 +3981,9 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_KeyedGetProperty) {
if (args[0]->IsJSObject()) {
if (!args[0]->IsJSGlobalProxy() &&
!args[0]->IsAccessCheckNeeded() &&
- args[1]->IsString()) {
+ args[1]->IsName()) {
JSObject* receiver = JSObject::cast(args[0]);
- String* key = String::cast(args[1]);
+ Name* key = Name::cast(args[1]);
if (receiver->HasFastProperties()) {
// Attempt to use lookup cache.
Map* receiver_map = receiver->map();
@@ -4006,9 +4006,9 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_KeyedGetProperty) {
}
} else {
// Attempt dictionary lookup.
- StringDictionary* dictionary = receiver->property_dictionary();
+ NameDictionary* dictionary = receiver->property_dictionary();
int entry = dictionary->FindEntry(key);
- if ((entry != StringDictionary::kNotFound) &&
+ if ((entry != NameDictionary::kNotFound) &&
(dictionary->DetailsAt(entry).type() == NORMAL)) {
Object* value = dictionary->ValueAt(entry);
if (!receiver->IsGlobalObject()) return value;
@@ -4018,7 +4018,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_KeyedGetProperty) {
}
}
} else if (FLAG_smi_only_arrays && args.at<Object>(1)->IsSmi()) {
- // JSObject without a string key. If the key is a Smi, check for a
+ // JSObject without a name key. If the key is a Smi, check for a
// definite out-of-bounds access to elements, which is a strong indicator
// that subsequent accesses will also call the runtime. Proactively
// transition elements to FAST_*_ELEMENTS to avoid excessive boxing of
@@ -4078,7 +4078,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DefineOrRedefineAccessorProperty) {
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
RUNTIME_ASSERT(!obj->IsNull());
- CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
+ CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, getter, 2);
RUNTIME_ASSERT(IsValidAccessor(getter));
CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3);
@@ -4103,7 +4103,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DefineOrRedefineDataProperty) {
ASSERT(args.length() == 4);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSObject, js_object, 0);
- CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
+ CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, obj_value, 2);
CONVERT_SMI_ARG_CHECKED(unchecked, 3);
RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
@@ -4168,7 +4168,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DefineOrRedefineDataProperty) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDataProperty) {
ASSERT(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
- CONVERT_ARG_HANDLE_CHECKED(String, key, 1);
+ CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
LookupResult lookup(isolate);
object->LookupRealNamedProperty(*key, &lookup);
if (!lookup.IsFound()) return isolate->heap()->undefined_value();
@@ -4211,10 +4211,11 @@ MaybeObject* Runtime::SetObjectProperty(Isolate* isolate,
if (object->IsJSProxy()) {
bool has_pending_exception = false;
- Handle<Object> name = Execution::ToString(key, &has_pending_exception);
+ Handle<Object> name = key->IsSymbol()
+ ? key : Execution::ToString(key, &has_pending_exception);
if (has_pending_exception) return Failure::Exception();
return JSProxy::cast(*object)->SetProperty(
- String::cast(*name), *value, attr, strict_mode);
+ Name::cast(*name), *value, attr, strict_mode);
}
// If the object isn't a JavaScript object, we ignore the store.
@@ -4244,16 +4245,16 @@ MaybeObject* Runtime::SetObjectProperty(Isolate* isolate,
return *value;
}
- if (key->IsString()) {
+ if (key->IsName()) {
Handle<Object> result;
- if (Handle<String>::cast(key)->AsArrayIndex(&index)) {
+ Handle<Name> name = Handle<Name>::cast(key);
+ if (name->AsArrayIndex(&index)) {
result = JSObject::SetElement(
js_object, index, value, attr, strict_mode, set_mode);
} else {
- Handle<String> key_string = Handle<String>::cast(key);
- key_string->TryFlatten();
+ if (name->IsString()) Handle<String>::cast(name)->TryFlatten();
result = JSReceiver::SetProperty(
- js_object, key_string, value, attr, strict_mode);
+ js_object, name, value, attr, strict_mode);
}
if (result.is_null()) return Failure::Exception();
return *value;
@@ -4299,16 +4300,14 @@ MaybeObject* Runtime::ForceSetObjectProperty(Isolate* isolate,
index, *value, attr, kNonStrictMode, false, DEFINE_PROPERTY);
}
- if (key->IsString()) {
- if (Handle<String>::cast(key)->AsArrayIndex(&index)) {
+ if (key->IsName()) {
+ Handle<Name> name = Handle<Name>::cast(key);
+ if (name->AsArrayIndex(&index)) {
return js_object->SetElement(
index, *value, attr, kNonStrictMode, false, DEFINE_PROPERTY);
} else {
- Handle<String> key_string = Handle<String>::cast(key);
- key_string->TryFlatten();
- return js_object->SetLocalPropertyIgnoreAttributes(*key_string,
- *value,
- attr);
+ if (name->IsString()) Handle<String>::cast(name)->TryFlatten();
+ return js_object->SetLocalPropertyIgnoreAttributes(*name, *value, attr);
}
}
@@ -4348,19 +4347,19 @@ MaybeObject* Runtime::ForceDeleteObjectProperty(Isolate* isolate,
return receiver->DeleteElement(index, JSReceiver::FORCE_DELETION);
}
- Handle<String> key_string;
- if (key->IsString()) {
- key_string = Handle<String>::cast(key);
+ Handle<Name> name;
+ if (key->IsName()) {
+ name = Handle<Name>::cast(key);
} else {
// Call-back into JavaScript to convert the key to a string.
bool has_pending_exception = false;
Handle<Object> converted = Execution::ToString(key, &has_pending_exception);
if (has_pending_exception) return Failure::Exception();
- key_string = Handle<String>::cast(converted);
+ name = Handle<String>::cast(converted);
}
- key_string->TryFlatten();
- return receiver->DeleteProperty(*key_string, JSReceiver::FORCE_DELETION);
+ if (name->IsString()) Handle<String>::cast(name)->TryFlatten();
+ return receiver->DeleteProperty(*name, JSReceiver::FORCE_DELETION);
}
@@ -4547,7 +4546,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_IgnoreAttributesAndSetProperty) {
NoHandleAllocation ha;
RUNTIME_ASSERT(args.length() == 3 || args.length() == 4);
CONVERT_ARG_CHECKED(JSObject, object, 0);
- CONVERT_ARG_CHECKED(String, name, 1);
+ CONVERT_ARG_CHECKED(Name, name, 1);
// Compute attributes.
PropertyAttributes attributes = NONE;
if (args.length() == 4) {
@@ -4568,7 +4567,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) {
ASSERT(args.length() == 3);
CONVERT_ARG_CHECKED(JSReceiver, object, 0);
- CONVERT_ARG_CHECKED(String, key, 1);
+ CONVERT_ARG_CHECKED(Name, key, 1);
CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 2);
return object->DeleteProperty(key, (strict_mode == kStrictMode)
? JSReceiver::STRICT_DELETION
@@ -4578,7 +4577,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) {
static Object* HasLocalPropertyImplementation(Isolate* isolate,
Handle<JSObject> object,
- Handle<String> key) {
+ Handle<Name> key) {
if (object->HasLocalProperty(*key)) return isolate->heap()->true_value();
// Handle hidden prototypes. If there's a hidden prototype above this thing
// then we have to check it for properties, because they are supposed to
@@ -4597,7 +4596,7 @@ static Object* HasLocalPropertyImplementation(Isolate* isolate,
RUNTIME_FUNCTION(MaybeObject*, Runtime_HasLocalProperty) {
NoHandleAllocation ha;
ASSERT(args.length() == 2);
- CONVERT_ARG_CHECKED(String, key, 1);
+ CONVERT_ARG_CHECKED(Name, key, 1);
uint32_t index;
const bool key_is_array_index = key->AsArrayIndex(&index);
@@ -4620,7 +4619,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_HasLocalProperty) {
HandleScope scope(isolate);
return HasLocalPropertyImplementation(isolate,
Handle<JSObject>(object),
- Handle<String>(key));
+ Handle<Name>(key));
} else if (obj->IsString() && key_is_array_index) {
// Well, there is one exception: Handle [] on strings.
String* string = String::cast(obj);
@@ -4636,7 +4635,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_HasProperty) {
NoHandleAllocation na;
ASSERT(args.length() == 2);
CONVERT_ARG_CHECKED(JSReceiver, receiver, 0);
- CONVERT_ARG_CHECKED(String, key, 1);
+ CONVERT_ARG_CHECKED(Name, key, 1);
bool result = receiver->HasProperty(key);
if (isolate->has_pending_exception()) return Failure::Exception();
@@ -4661,7 +4660,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_IsPropertyEnumerable) {
ASSERT(args.length() == 2);
CONVERT_ARG_CHECKED(JSObject, object, 0);
- CONVERT_ARG_CHECKED(String, key, 1);
+ CONVERT_ARG_CHECKED(Name, key, 1);
PropertyAttributes att = object->GetLocalPropertyAttribute(key);
return isolate->heap()->ToBoolean(att != ABSENT && (att & DONT_ENUM) == 0);
@@ -4905,7 +4904,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LocalKeys) {
Handle<FixedArray> copy = isolate->factory()->NewFixedArray(length);
for (int i = 0; i < length; i++) {
Object* entry = contents->get(i);
- if (entry->IsString()) {
+ if (entry->IsName()) {
copy->set(i, entry);
} else {
ASSERT(entry->IsNumber());
@@ -4939,6 +4938,12 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetArgumentsProperty) {
return frame->GetParameter(index);
}
+ if (args[0]->IsSymbol()) {
+ // Lookup in the initial Object.prototype object.
+ return isolate->initial_object_prototype()->GetProperty(
+ Symbol::cast(args[0]));
+ }
+
// Convert the key to a string.
HandleScope scope(isolate);
bool exception = false;
@@ -10079,7 +10084,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetArrayKeys) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_LookupAccessor) {
ASSERT(args.length() == 3);
CONVERT_ARG_CHECKED(JSReceiver, receiver, 0);
- CONVERT_ARG_CHECKED(String, name, 1);
+ CONVERT_ARG_CHECKED(Name, name, 1);
CONVERT_SMI_ARG_CHECKED(flag, 2);
AccessorComponent component = flag == 0 ? ACCESSOR_GETTER : ACCESSOR_SETTER;
if (!receiver->IsJSObject()) return isolate->heap()->undefined_value();
@@ -10132,7 +10137,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_Break) {
static MaybeObject* DebugLookupResultValue(Heap* heap,
Object* receiver,
- String* name,
+ Name* name,
LookupResult* result,
bool* caught_exception) {
Object* value;
@@ -10204,7 +10209,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPropertyDetails) {
ASSERT(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
- CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
+ CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
// Make sure to set the current context to the context before the debugger was
// entered (if the debugger is entered). The reason for switching context here
@@ -10302,7 +10307,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetProperty) {
ASSERT(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
- CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
+ CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
LookupResult result(isolate);
obj->Lookup(*name, &result);
@@ -10349,7 +10354,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugNamedInterceptorPropertyValue) {
ASSERT(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
RUNTIME_ASSERT(obj->HasNamedInterceptor());
- CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
+ CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
PropertyAttributes attributes;
return obj->GetPropertyWithInterceptor(*obj, *name, &attributes);
@@ -13478,15 +13483,15 @@ MaybeObject* Runtime::InitializeIntrinsicFunctionNames(Heap* heap,
Object* dictionary) {
ASSERT(Isolate::Current()->heap() == heap);
ASSERT(dictionary != NULL);
- ASSERT(StringDictionary::cast(dictionary)->NumberOfElements() == 0);
+ ASSERT(NameDictionary::cast(dictionary)->NumberOfElements() == 0);
for (int i = 0; i < kNumFunctions; ++i) {
Object* name_string;
{ MaybeObject* maybe_name_string =
heap->InternalizeUtf8String(kIntrinsicFunctions[i].name);
if (!maybe_name_string->ToObject(&name_string)) return maybe_name_string;
}
- StringDictionary* string_dictionary = StringDictionary::cast(dictionary);
- { MaybeObject* maybe_dictionary = string_dictionary->Add(
+ NameDictionary* name_dictionary = NameDictionary::cast(dictionary);
+ { MaybeObject* maybe_dictionary = name_dictionary->Add(
String::cast(name_string),
Smi::FromInt(i),
PropertyDetails(NONE, NORMAL));
« no previous file with comments | « src/proxy.js ('k') | src/runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698