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

Unified Diff: src/builtins.cc

Issue 1699733003: [left-trimming] Avoid creating duplicate handles in builtins.cc (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: using CloseAndEscape Created 4 years, 10 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/heap/heap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index 1c596503ef86e95bf3b6e3054ade3c484ae4a661..8bd5cb1490aedce82c44aa3f93d15c38185e4451 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -251,6 +251,9 @@ MUST_USE_RESULT
inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements(
Isolate* isolate, Handle<Object> receiver, Arguments* args,
int first_added_arg) {
+ // We explicitly add a HandleScope to avoid creating several copies of the
+ // same handle which would otherwise cause issue when left-trimming later-on.
+ HandleScope scope(isolate);
if (!receiver->IsJSArray()) return MaybeHandle<FixedArrayBase>();
Handle<JSArray> array = Handle<JSArray>::cast(receiver);
// If there may be elements accessors in the prototype chain, the fast path
@@ -264,12 +267,18 @@ inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements(
Handle<FixedArrayBase> elms(array->elements(), isolate);
Map* map = elms->map();
if (map == heap->fixed_array_map()) {
- if (args == NULL || array->HasFastObjectElements()) return elms;
+ if (args == NULL || array->HasFastObjectElements()) {
+ return scope.CloseAndEscape(elms);
+ }
} else if (map == heap->fixed_cow_array_map()) {
elms = JSObject::EnsureWritableFastElements(array);
- if (args == NULL || array->HasFastObjectElements()) return elms;
+ if (args == NULL || array->HasFastObjectElements()) {
+ return scope.CloseAndEscape(elms);
+ }
} else if (map == heap->fixed_double_array_map()) {
- if (args == NULL) return elms;
+ if (args == NULL) {
+ return scope.CloseAndEscape(elms);
+ }
} else {
return MaybeHandle<FixedArrayBase>();
}
@@ -283,7 +292,9 @@ inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements(
// Need to ensure that the arguments passed in args can be contained in
// the array.
int args_length = args->length();
- if (first_added_arg >= args_length) return handle(array->elements(), isolate);
+ if (first_added_arg >= args_length) {
+ return scope.CloseAndEscape(elms);
+ }
ElementsKind origin_kind = array->map()->elements_kind();
DCHECK(!IsFastObjectElementsKind(origin_kind));
@@ -306,9 +317,9 @@ inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements(
}
if (target_kind != origin_kind) {
JSObject::TransitionElementsKind(array, target_kind);
- return handle(array->elements(), isolate);
+ elms = handle(array->elements(), isolate);
}
- return elms;
+ return scope.CloseAndEscape(elms);
}
« no previous file with comments | « no previous file | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698