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

Unified Diff: src/objects.cc

Issue 1191313003: More cleanup related to setting array.length (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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') | src/objects-inl.h » ('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 5e03e8abde4910923800e099cd6e921881ae921f..6dda62f1acb9f3957682cca2195f4187b4da4329 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -11930,18 +11930,19 @@ static bool GetOldValue(Isolate* isolate,
return true;
}
-MaybeHandle<Object> JSArray::SetElementsLength(
- Handle<JSArray> array,
- Handle<Object> new_length_handle) {
- if (array->HasFastElements() &&
- SetElementsLengthWouldNormalize(array->GetHeap(), new_length_handle)) {
- NormalizeElements(array);
- }
+void JSArray::SetLength(Handle<JSArray> array, uint32_t new_length) {
// We should never end in here with a pixel or external array.
- DCHECK(array->AllowsSetElementsLength());
+ DCHECK(array->AllowsSetLength());
+ array->GetElementsAccessor()->SetLength(array, new_length);
+}
+
+
+MaybeHandle<Object> JSArray::ObservableSetLength(Handle<JSArray> array,
+ uint32_t new_length) {
if (!array->map()->is_observed()) {
- return array->GetElementsAccessor()->SetLength(array, new_length_handle);
+ SetLength(array, new_length);
+ return array;
}
Isolate* isolate = array->GetIsolate();
@@ -11950,8 +11951,6 @@ MaybeHandle<Object> JSArray::SetElementsLength(
Handle<Object> old_length_handle(array->length(), isolate);
uint32_t old_length = 0;
CHECK(old_length_handle->ToArrayLength(&old_length));
- uint32_t new_length = 0;
- CHECK(new_length_handle->ToArrayLength(&new_length));
static const PropertyAttributes kNoAttrFilter = NONE;
int num_elements = array->NumberOfOwnElements(kNoAttrFilter);
@@ -11975,14 +11974,10 @@ MaybeHandle<Object> JSArray::SetElementsLength(
}
}
- Handle<Object> hresult;
- ASSIGN_RETURN_ON_EXCEPTION(
- isolate, hresult,
- array->GetElementsAccessor()->SetLength(array, new_length_handle),
- Object);
+ SetLength(array, new_length);
CHECK(array->length()->ToArrayLength(&new_length));
- if (old_length == new_length) return hresult;
+ if (old_length == new_length) return array;
RETURN_ON_EXCEPTION(isolate, BeginPerformSplice(array), Object);
@@ -11997,6 +11992,7 @@ MaybeHandle<Object> JSArray::SetElementsLength(
old_values[i]),
Object);
}
+
RETURN_ON_EXCEPTION(isolate,
JSObject::EnqueueChangeRecord(
array, "update", isolate->factory()->length_string(),
@@ -12018,15 +12014,13 @@ MaybeHandle<Object> JSArray::SetElementsLength(
.Assert();
}
- ElementsAccessor* accessor = deleted->GetElementsAccessor();
- accessor->SetLength(deleted, isolate->factory()->NewNumberFromUint(
- delete_count)).Check();
+ JSArray::SetLength(deleted, delete_count);
}
RETURN_ON_EXCEPTION(
isolate, EnqueueSpliceRecord(array, index, deleted, add_count), Object);
- return hresult;
+ return array;
}
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698