Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 0059a6a64801c462be7b301e0f609d750f1a71af..ca941ce4e21a0c6c0a6b6eb9cc54e8ffd3441054 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -133,6 +133,27 @@ MaybeHandle<Object> Object::ToNumber(Handle<Object> input) { |
// static |
+MaybeHandle<Object> Object::ToInteger(Isolate* isolate, Handle<Object> input) { |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
+ return isolate->factory()->NewNumber(DoubleToInteger(input->Number())); |
+} |
+ |
+ |
+// static |
+MaybeHandle<Object> Object::ToInt32(Isolate* isolate, Handle<Object> input) { |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
+ return isolate->factory()->NewNumberFromInt(DoubleToInt32(input->Number())); |
+} |
+ |
+ |
+// static |
+MaybeHandle<Object> Object::ToUint32(Isolate* isolate, Handle<Object> input) { |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
+ return isolate->factory()->NewNumberFromUint(DoubleToUint32(input->Number())); |
+} |
+ |
+ |
+// static |
MaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) { |
while (true) { |
if (input->IsString()) { |
@@ -159,6 +180,19 @@ MaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) { |
} |
+// static |
+MaybeHandle<Object> Object::ToLength(Isolate* isolate, Handle<Object> input) { |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
+ double len = DoubleToInteger(input->Number()); |
+ if (len <= 0.0) { |
+ len = 0.0; |
+ } else if (len >= kMaxSafeInteger) { |
+ len = kMaxSafeInteger; |
+ } |
+ return isolate->factory()->NewNumber(len); |
+} |
+ |
+ |
bool Object::BooleanValue() { |
if (IsBoolean()) return IsTrue(); |
if (IsSmi()) return Smi::cast(this)->value() != 0; |