Commit 22afaacd authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[keys] Handle RangeError in GetKeysWithPrototypeInfoCache

Drive-by-fix: Add V8_WARN_UNUSED_RESULT to MaybeHandle::ToHandle

Bug: chromium:1057653
Change-Id: I2834806ca498a2fa43a64f5391606cdbfb4af4fa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2084814Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66582}
parent 3a86dca1
...@@ -50,7 +50,7 @@ class MaybeHandle final { ...@@ -50,7 +50,7 @@ class MaybeHandle final {
// Convert to a Handle with a type that can be upcasted to. // Convert to a Handle with a type that can be upcasted to.
template <typename S> template <typename S>
V8_INLINE bool ToHandle(Handle<S>* out) const { V8_WARN_UNUSED_RESULT V8_INLINE bool ToHandle(Handle<S>* out) const {
if (location_ == nullptr) { if (location_ == nullptr) {
*out = Handle<T>::null(); *out = Handle<T>::null();
return false; return false;
......
...@@ -572,15 +572,17 @@ MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysWithPrototypeInfoCache( ...@@ -572,15 +572,17 @@ MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysWithPrototypeInfoCache(
GetKeysConversion keys_conversion) { GetKeysConversion keys_conversion) {
Handle<FixedArray> own_keys; Handle<FixedArray> own_keys;
if (may_have_elements_) { if (may_have_elements_) {
MaybeHandle<FixedArray> maybe_own_keys;
if (receiver_->map().is_dictionary_map()) { if (receiver_->map().is_dictionary_map()) {
GetOwnKeysWithElements<false>(isolate_, Handle<JSObject>::cast(receiver_), maybe_own_keys = GetOwnKeysWithElements<false>(
keys_conversion, skip_indices_) isolate_, Handle<JSObject>::cast(receiver_), keys_conversion,
.ToHandle(&own_keys); skip_indices_);
} else { } else {
GetOwnKeysWithElements<true>(isolate_, Handle<JSObject>::cast(receiver_), maybe_own_keys = GetOwnKeysWithElements<true>(
keys_conversion, skip_indices_) isolate_, Handle<JSObject>::cast(receiver_), keys_conversion,
.ToHandle(&own_keys); skip_indices_);
} }
ASSIGN_RETURN_ON_EXCEPTION(isolate_, own_keys, maybe_own_keys, FixedArray);
} else { } else {
own_keys = KeyAccumulator::GetOwnEnumPropertyKeys( own_keys = KeyAccumulator::GetOwnEnumPropertyKeys(
isolate_, Handle<JSObject>::cast(receiver_)); isolate_, Handle<JSObject>::cast(receiver_));
......
...@@ -6092,17 +6092,18 @@ Handle<Object> JSPromise::TriggerPromiseReactions(Isolate* isolate, ...@@ -6092,17 +6092,18 @@ Handle<Object> JSPromise::TriggerPromiseReactions(Isolate* isolate,
secondary_handler = handle(reaction->fulfill_handler(), isolate); secondary_handler = handle(reaction->fulfill_handler(), isolate);
} }
bool has_handler_context = false;
if (primary_handler->IsJSReceiver()) { if (primary_handler->IsJSReceiver()) {
JSReceiver::GetContextForMicrotask( has_handler_context = JSReceiver::GetContextForMicrotask(
Handle<JSReceiver>::cast(primary_handler)) Handle<JSReceiver>::cast(primary_handler))
.ToHandle(&handler_context); .ToHandle(&handler_context);
} }
if (handler_context.is_null() && secondary_handler->IsJSReceiver()) { if (!has_handler_context && secondary_handler->IsJSReceiver()) {
JSReceiver::GetContextForMicrotask( has_handler_context = JSReceiver::GetContextForMicrotask(
Handle<JSReceiver>::cast(secondary_handler)) Handle<JSReceiver>::cast(secondary_handler))
.ToHandle(&handler_context); .ToHandle(&handler_context);
} }
if (handler_context.is_null()) handler_context = isolate->native_context(); if (!has_handler_context) handler_context = isolate->native_context();
STATIC_ASSERT( STATIC_ASSERT(
static_cast<int>(PromiseReaction::kSize) == static_cast<int>(PromiseReaction::kSize) ==
......
...@@ -14,8 +14,8 @@ namespace compiler { ...@@ -14,8 +14,8 @@ namespace compiler {
TEST(ArgumentsMapped) { TEST(ArgumentsMapped) {
FunctionTester T("(function(a) { return arguments; })"); FunctionTester T("(function(a) { return arguments; })");
Handle<Object> arguments; Handle<Object> arguments =
T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandle(&arguments); T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandleChecked();
CHECK(arguments->IsJSObject() && !arguments->IsJSArray()); CHECK(arguments->IsJSObject() && !arguments->IsJSArray());
CHECK(JSObject::cast(*arguments).HasSloppyArgumentsElements()); CHECK(JSObject::cast(*arguments).HasSloppyArgumentsElements());
Handle<String> l = T.isolate->factory()->length_string(); Handle<String> l = T.isolate->factory()->length_string();
...@@ -28,8 +28,8 @@ TEST(ArgumentsMapped) { ...@@ -28,8 +28,8 @@ TEST(ArgumentsMapped) {
TEST(ArgumentsUnmapped) { TEST(ArgumentsUnmapped) {
FunctionTester T("(function(a) { 'use strict'; return arguments; })"); FunctionTester T("(function(a) { 'use strict'; return arguments; })");
Handle<Object> arguments; Handle<Object> arguments =
T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandle(&arguments); T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandleChecked();
CHECK(arguments->IsJSObject() && !arguments->IsJSArray()); CHECK(arguments->IsJSObject() && !arguments->IsJSArray());
CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements()); CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements());
Handle<String> l = T.isolate->factory()->length_string(); Handle<String> l = T.isolate->factory()->length_string();
...@@ -42,8 +42,8 @@ TEST(ArgumentsUnmapped) { ...@@ -42,8 +42,8 @@ TEST(ArgumentsUnmapped) {
TEST(ArgumentsRest) { TEST(ArgumentsRest) {
FunctionTester T("(function(a, ...args) { return args; })"); FunctionTester T("(function(a, ...args) { return args; })");
Handle<Object> arguments; Handle<Object> arguments =
T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandle(&arguments); T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandleChecked();
CHECK(arguments->IsJSObject() && arguments->IsJSArray()); CHECK(arguments->IsJSObject() && arguments->IsJSArray());
CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements()); CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements());
Handle<String> l = T.isolate->factory()->length_string(); Handle<String> l = T.isolate->factory()->length_string();
......
...@@ -5709,8 +5709,7 @@ TEST(Regress631969) { ...@@ -5709,8 +5709,7 @@ TEST(Regress631969) {
// Allocate a cons string and promote it to a fresh page in the old space. // Allocate a cons string and promote it to a fresh page in the old space.
heap::SimulateFullSpace(heap->old_space()); heap::SimulateFullSpace(heap->old_space());
Handle<String> s3; Handle<String> s3 = factory->NewConsString(s1, s2).ToHandleChecked();
factory->NewConsString(s1, s2).ToHandle(&s3);
CcTest::CollectGarbage(NEW_SPACE); CcTest::CollectGarbage(NEW_SPACE);
CcTest::CollectGarbage(NEW_SPACE); CcTest::CollectGarbage(NEW_SPACE);
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Object.prototype.length = 3642395160;
const array = new Float32Array(2**28);
assertThrows(() => {for (const key in array) {}}, RangeError);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment