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

Unified Diff: src/objects-inl.h

Issue 2579023002: [runtime] Improve Object::ToNumber, ToInteger, ToInt32, ToUint32, ToString (Closed)
Patch Set: fix Uint32 conversion Created 4 years 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/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index b1165b3ae7ea74daef4df6ec236d76fdc3b2eaf7..6a338b2f7c05dee67d13eb3ef1e0252fa0c332c1 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -651,7 +651,7 @@ class Utf8StringKey : public HashTableKey {
bool Object::IsNumber() const {
- return IsSmi() || IsHeapNumber();
+ return IsSmi() || HeapObject::cast(this)->IsHeapNumber();
}
@@ -1081,6 +1081,35 @@ MaybeHandle<Object> Object::ToPrimitive(Handle<Object> input,
return JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(input), hint);
}
+// static
+MaybeHandle<Object> Object::ToNumber(Handle<Object> input) {
+ if (input->IsNumber()) return input;
+ return ConvertToNumber(HeapObject::cast(*input)->GetIsolate(), input);
+}
+
+// static
+MaybeHandle<Object> Object::ToInteger(Isolate* isolate, Handle<Object> input) {
+ if (input->IsSmi()) return input;
+ return ConvertToInteger(isolate, input);
+}
+
+// static
+MaybeHandle<Object> Object::ToInt32(Isolate* isolate, Handle<Object> input) {
+ if (input->IsSmi()) return input;
+ return ConvertToInt32(isolate, input);
+}
+
+// static
+MaybeHandle<Object> Object::ToUint32(Isolate* isolate, Handle<Object> input) {
+ if (input->IsSmi()) return handle(Smi::cast(*input)->ToUint32Smi(), isolate);
+ return ConvertToUint32(isolate, input);
+}
+
+// static
+MaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) {
+ if (input->IsString()) return Handle<String>::cast(input);
+ return ConvertToString(isolate, input);
+}
bool Object::HasSpecificClassOf(String* name) {
return this->IsJSObject() && (JSObject::cast(this)->class_name() == name);
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698