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

Unified Diff: src/objects.cc

Issue 2247073004: Reland of Amend DataView, ArrayBuffer, and TypedArray methods to use ToIndex. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Correct messages Created 4 years, 4 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/objects.h ('k') | test/mjsunit/harmony/dataview-accessors.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index b133ee3f75c6d71e04370b8b61617f34fb90af6c..93928e80eaf3c833ea80cd44e4d25a40d1b893c4 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -383,6 +383,18 @@ MaybeHandle<Object> Object::ToLength(Isolate* isolate, Handle<Object> input) {
return isolate->factory()->NewNumber(len);
}
+// static
+MaybeHandle<Object> Object::ToIndex(Isolate* isolate, Handle<Object> input,
+ MessageTemplate::Template error_index) {
+ if (input->IsUndefined(isolate)) return isolate->factory()->NewNumber(0.0);
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object);
+ double len = DoubleToInteger(input->Number()) + 0.0;
+ auto js_len = isolate->factory()->NewNumber(len);
+ if (len < 0.0 || len > kMaxSafeInteger) {
+ THROW_NEW_ERROR(isolate, NewRangeError(error_index, js_len), Object);
+ }
+ return js_len;
+}
bool Object::BooleanValue() {
if (IsSmi()) return Smi::cast(this)->value() != 0;
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/harmony/dataview-accessors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698