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

Unified Diff: src/accessors.cc

Issue 1404283002: Unify ToArrayLength conversions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comments Created 5 years, 2 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 | « no previous file | src/conversions-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/accessors.cc
diff --git a/src/accessors.cc b/src/accessors.cc
index 653fdc6a8c71741f0fe2cffa514b817b117be3e8..1871822d617663ee9a38fe6db1df6b5ff100f235 100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -198,18 +198,6 @@ void Accessors::ArrayLengthGetter(
}
-// Tries to non-observably convert |value| to a valid array length.
-// Returns false if it fails.
-static bool FastAsArrayLength(Isolate* isolate, Handle<Object> value,
- uint32_t* length) {
- if (value->ToArrayLength(length)) return true;
- // We don't support AsArrayLength, so use AsArrayIndex for now. This just
- // misses out on kMaxUInt32.
- if (value->IsString()) return String::cast(*value)->AsArrayIndex(length);
- return false;
-}
-
-
void Accessors::ArrayLengthSetter(
v8::Local<v8::Name> name,
v8::Local<v8::Value> val,
@@ -222,26 +210,9 @@ void Accessors::ArrayLengthSetter(
Handle<Object> length_obj = Utils::OpenHandle(*val);
uint32_t length = 0;
- if (!FastAsArrayLength(isolate, length_obj, &length)) {
- Handle<Object> uint32_v;
- if (!Object::ToUint32(isolate, length_obj).ToHandle(&uint32_v)) {
- isolate->OptionalRescheduleException(false);
- return;
- }
-
- Handle<Object> number_v;
- if (!Object::ToNumber(length_obj).ToHandle(&number_v)) {
- isolate->OptionalRescheduleException(false);
- return;
- }
-
- if (uint32_v->Number() != number_v->Number()) {
- Handle<Object> exception = isolate->factory()->NewRangeError(
- MessageTemplate::kInvalidArrayLength);
- return isolate->ScheduleThrow(*exception);
- }
-
- CHECK(uint32_v->ToArrayLength(&length));
+ if (!JSArray::AnythingToArrayLength(isolate, length_obj, &length)) {
+ isolate->OptionalRescheduleException(false);
+ return;
}
if (JSArray::ObservableSetLength(array, length).is_null()) {
@@ -260,7 +231,6 @@ Handle<AccessorInfo> Accessors::ArrayLengthInfo(
}
-
//
// Accessors::StringLength
//
« no previous file with comments | « no previous file | src/conversions-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698