Commit 1dc711f2 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

Move runtime helper for ToName conversion onto Object.

R=bmeurer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#30409}
parent 8d54fc2e
......@@ -3531,7 +3531,7 @@ static i::MaybeHandle<i::Object> DefineObjectProperty(
i::Handle<i::Name> name;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, name,
i::Runtime::ToName(isolate, key),
i::Object::ToName(isolate, key),
i::MaybeHandle<i::Object>());
return i::JSObject::DefinePropertyOrElementIgnoreAttributes(js_object, name,
......@@ -3855,7 +3855,7 @@ Maybe<bool> v8::Object::Has(Local<Context> context, Local<Value> key) {
} else {
// Convert the key to a name - possibly by calling back into JavaScript.
i::Handle<i::Name> name;
if (i::Runtime::ToName(isolate, key_obj).ToHandle(&name)) {
if (i::Object::ToName(isolate, key_obj).ToHandle(&name)) {
maybe = i::JSReceiver::HasProperty(self, name);
}
}
......
......@@ -90,6 +90,18 @@ MaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate,
}
MaybeHandle<Name> Object::ToName(Isolate* isolate, Handle<Object> object) {
if (object->IsName()) {
return Handle<Name>::cast(object);
} else {
Handle<Object> converted;
ASSIGN_RETURN_ON_EXCEPTION(isolate, converted,
Execution::ToString(isolate, object), Name);
return Handle<Name>::cast(converted);
}
}
bool Object::BooleanValue() {
if (IsBoolean()) return IsTrue();
if (IsSmi()) return Smi::cast(this)->value() != 0;
......
......@@ -1074,9 +1074,12 @@ class Object {
// native_context is used when creating wrapper object.
static inline MaybeHandle<JSReceiver> ToObject(Isolate* isolate,
Handle<Object> object);
static MaybeHandle<JSReceiver> ToObject(Isolate* isolate,
Handle<Object> object,
Handle<Context> context);
MUST_USE_RESULT static MaybeHandle<JSReceiver> ToObject(
Isolate* isolate, Handle<Object> object, Handle<Context> context);
// Convert to a Name if needed.
MUST_USE_RESULT static MaybeHandle<Name> ToName(Isolate* isolate,
Handle<Object> object);
MUST_USE_RESULT static MaybeHandle<Object> GetProperty(
LookupIterator* it, LanguageMode language_mode = SLOPPY);
......
......@@ -380,7 +380,7 @@ RUNTIME_FUNCTION(Runtime_LoadKeyedFromSuper) {
Handle<Name> name;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name,
Runtime::ToName(isolate, key));
Object::ToName(isolate, key));
// TODO(verwaest): Unify using LookupIterator.
if (name->AsArrayIndex(&index)) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
......@@ -477,7 +477,7 @@ static Object* StoreKeyedToSuper(Isolate* isolate, Handle<JSObject> home_object,
}
Handle<Name> name;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name,
Runtime::ToName(isolate, key));
Object::ToName(isolate, key));
// TODO(verwaest): Unify using LookupIterator.
if (name->AsArrayIndex(&index)) {
return StoreElementToSuper(isolate, home_object, receiver, index, value,
......
......@@ -28,7 +28,7 @@ RUNTIME_FUNCTION(Runtime_ForInFilter) {
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
// TODO(turbofan): Fast case for array indices.
Handle<Name> name;
if (!Runtime::ToName(isolate, key).ToHandle(&name)) {
if (!Object::ToName(isolate, key).ToHandle(&name)) {
return isolate->heap()->exception();
}
Maybe<bool> result = JSReceiver::HasProperty(receiver, name);
......@@ -53,7 +53,7 @@ RUNTIME_FUNCTION(Runtime_ForInNext) {
}
// TODO(turbofan): Fast case for array indices.
Handle<Name> name;
if (!Runtime::ToName(isolate, key).ToHandle(&name)) {
if (!Object::ToName(isolate, key).ToHandle(&name)) {
return isolate->heap()->exception();
}
Maybe<bool> result = JSReceiver::HasProperty(receiver, name);
......
......@@ -14,18 +14,6 @@ namespace v8 {
namespace internal {
MaybeHandle<Name> Runtime::ToName(Isolate* isolate, Handle<Object> key) {
if (key->IsName()) {
return Handle<Name>::cast(key);
} else {
Handle<Object> converted;
ASSIGN_RETURN_ON_EXCEPTION(isolate, converted,
Execution::ToString(isolate, key), Name);
return Handle<Name>::cast(converted);
}
}
MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate,
Handle<Object> object,
Handle<Object> key,
......@@ -45,7 +33,8 @@ MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate,
// Convert the key to a name - possibly by calling back into JavaScript.
Handle<Name> name;
ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object);
ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key),
Object);
// Check if the name is trivially convertible to an index and get
// the element if so.
......@@ -150,7 +139,8 @@ MaybeHandle<Object> Runtime::DeleteObjectProperty(Isolate* isolate,
}
Handle<Name> name;
ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object);
ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key),
Object);
return JSReceiver::DeletePropertyOrElement(receiver, name, language_mode);
}
......@@ -175,7 +165,8 @@ MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
}
Handle<Name> name;
ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object);
ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key),
Object);
LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name);
return Object::SetProperty(&it, value, language_mode,
......
......@@ -1149,9 +1149,6 @@ class Runtime : public AllStatic {
MUST_USE_RESULT static MaybeHandle<Object> GetPrototype(
Isolate* isolate, Handle<Object> object);
MUST_USE_RESULT static MaybeHandle<Name> ToName(Isolate* isolate,
Handle<Object> key);
enum TypedArrayId {
// arrayIds below should be synchronized with typedarray.js natives.
ARRAY_ID_UINT8 = 1,
......
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