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

Unified Diff: src/runtime/runtime-object.cc

Issue 1221303019: Fix keyed access of primitive objects in the runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix Created 5 years, 5 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/runtime/runtime-debug.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-object.cc
diff --git a/src/runtime/runtime-object.cc b/src/runtime/runtime-object.cc
index da1ec4977be36f1965f86e60cbfd5e08c8e02fdd..d27b2b14207910fb33309cdb9d907656573ec5bc 100644
--- a/src/runtime/runtime-object.cc
+++ b/src/runtime/runtime-object.cc
@@ -14,30 +14,6 @@
namespace v8 {
namespace internal {
-// Returns a single character string where first character equals
-// string->Get(index).
-static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
- DCHECK_LT(index, static_cast<uint32_t>(string->length()));
- Factory* factory = string->GetIsolate()->factory();
- return factory->LookupSingleCharacterStringFromCode(
- String::Flatten(string)->Get(index));
-}
-
-
-MaybeHandle<Object> Runtime::GetElementOrCharAt(Isolate* isolate,
- Handle<Object> object,
- uint32_t index,
- LanguageMode language_mode) {
- // Handle [] indexing on Strings
- if (object->IsString() &&
- index < static_cast<uint32_t>(String::cast(*object)->length())) {
- Handle<Object> result = GetCharAt(Handle<String>::cast(object), index);
- if (!result->IsUndefined()) return result;
- }
-
- return Object::GetElement(isolate, object, index, language_mode);
-}
-
MaybeHandle<Name> Runtime::ToName(Isolate* isolate, Handle<Object> key) {
if (key->IsName()) {
@@ -65,7 +41,7 @@ MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate,
// Check if the given key is an array index.
uint32_t index = 0;
if (key->ToArrayIndex(&index)) {
- return GetElementOrCharAt(isolate, object, index, language_mode);
+ return Object::GetElement(isolate, object, index, language_mode);
}
// Convert the key to a name - possibly by calling back into JavaScript.
@@ -77,7 +53,7 @@ MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate,
// TODO(verwaest): Make sure GetProperty(LookupIterator*) can handle this, and
// remove the special casing here.
if (name->AsArrayIndex(&index)) {
- return GetElementOrCharAt(isolate, object, index);
+ return Object::GetElement(isolate, object, index);
} else {
return Object::GetProperty(object, name, language_mode);
}
@@ -153,7 +129,9 @@ MaybeHandle<Object> Runtime::KeyedGetObjectProperty(
Handle<String> str = Handle<String>::cast(receiver_obj);
int index = Handle<Smi>::cast(key_obj)->value();
if (index >= 0 && index < str->length()) {
- return GetCharAt(str, index);
+ Factory* factory = isolate->factory();
+ return factory->LookupSingleCharacterStringFromCode(
+ String::Flatten(str)->Get(index));
}
}
@@ -194,18 +172,13 @@ MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
// Check if the given key is an array index.
uint32_t index = 0;
if (key->ToArrayIndex(&index)) {
- // TODO(verwaest): Support other objects as well.
- if (!object->IsJSReceiver()) return value;
- return JSReceiver::SetElement(Handle<JSReceiver>::cast(object), index,
- value, language_mode);
+ return Object::SetElement(isolate, object, index, value, language_mode);
}
Handle<Name> name;
ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object);
LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name);
- // TODO(verwaest): Support other objects as well.
- if (it.IsElement() && !object->IsJSReceiver()) return value;
return Object::SetProperty(&it, value, language_mode,
Object::MAY_BE_STORE_FROM_KEYED);
}
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698