Commit 3935d6f6 authored by Adam Klein's avatar Adam Klein Committed by V8 LUCI CQ

Add MAYBE_RETURN_ON_EXCEPTION_VALUE macro and use it in Temporal

This is useful for cases where we're calling a Maybe-returning
function only for its side effects and possible exception-throwing.

Change-Id: I64e73598d40b3565d83cb17166c762d8affd7a84
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3708022Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81201}
parent 2506d6ca
...@@ -406,6 +406,14 @@ class StackMemory; ...@@ -406,6 +406,14 @@ class StackMemory;
#define MAYBE_RETURN_NULL(call) MAYBE_RETURN(call, MaybeHandle<Object>()) #define MAYBE_RETURN_NULL(call) MAYBE_RETURN(call, MaybeHandle<Object>())
#define MAYBE_RETURN_ON_EXCEPTION_VALUE(isolate, call, value) \
do { \
if ((call).IsNothing()) { \
DCHECK((isolate)->has_pending_exception()); \
return value; \
} \
} while (false)
#define MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \ #define MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \
do { \ do { \
if (!(call).To(&dst)) { \ if (!(call).To(&dst)) { \
......
...@@ -1985,14 +1985,14 @@ Maybe<ShowOverflow> ToTemporalOverflow(Isolate* isolate, Handle<Object> options, ...@@ -1985,14 +1985,14 @@ Maybe<ShowOverflow> ToTemporalOverflow(Isolate* isolate, Handle<Object> options,
ShowOverflow::kConstrain); ShowOverflow::kConstrain);
} }
// TODO(adamk): Remove this and replace with direct usage of
// MAYBE_RETURN_ON_EXCEPTION_VALUE().
Maybe<bool> ToTemporalOverflowForSideEffects(Isolate* isolate, Maybe<bool> ToTemporalOverflowForSideEffects(Isolate* isolate,
Handle<Object> options, Handle<Object> options,
const char* method_name) { const char* method_name) {
ShowOverflow overflow; MAYBE_RETURN_ON_EXCEPTION_VALUE(
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, ToTemporalOverflow(isolate, options, method_name),
isolate, overflow, ToTemporalOverflow(isolate, options, method_name),
Nothing<bool>()); Nothing<bool>());
USE(overflow);
return Just(true); return Just(true);
} }
...@@ -9916,11 +9916,9 @@ MaybeHandle<JSTemporalPlainMonthDay> ToTemporalMonthDay( ...@@ -9916,11 +9916,9 @@ MaybeHandle<JSTemporalPlainMonthDay> ToTemporalMonthDay(
return MonthDayFromFields(isolate, calendar, fields, options); return MonthDayFromFields(isolate, calendar, fields, options);
} }
// 4. Perform ? ToTemporalOverflow(options). // 4. Perform ? ToTemporalOverflow(options).
ShowOverflow overflow; MAYBE_RETURN_ON_EXCEPTION_VALUE(
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, ToTemporalOverflow(isolate, options, method_name),
isolate, overflow, ToTemporalOverflow(isolate, options, method_name),
Handle<JSTemporalPlainMonthDay>()); Handle<JSTemporalPlainMonthDay>());
USE(overflow);
// 5. Let string be ? ToString(item). // 5. Let string be ? ToString(item).
Handle<String> string; Handle<String> string;
...@@ -9996,11 +9994,9 @@ MaybeHandle<JSTemporalPlainMonthDay> JSTemporalPlainMonthDay::From( ...@@ -9996,11 +9994,9 @@ MaybeHandle<JSTemporalPlainMonthDay> JSTemporalPlainMonthDay::From(
// internal slot, then // internal slot, then
if (item->IsJSTemporalPlainMonthDay()) { if (item->IsJSTemporalPlainMonthDay()) {
// a. Perform ? ToTemporalOverflow(options). // a. Perform ? ToTemporalOverflow(options).
ShowOverflow overflow; MAYBE_RETURN_ON_EXCEPTION_VALUE(
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, ToTemporalOverflow(isolate, options, method_name),
isolate, overflow, ToTemporalOverflow(isolate, options, method_name),
Handle<JSTemporalPlainMonthDay>()); Handle<JSTemporalPlainMonthDay>());
USE(overflow);
// b. Return ? CreateTemporalMonthDay(item.[[ISOMonth]], item.[[ISODay]], // b. Return ? CreateTemporalMonthDay(item.[[ISOMonth]], item.[[ISODay]],
// item.[[Calendar]], item.[[ISOYear]]). // item.[[Calendar]], item.[[ISOYear]]).
Handle<JSTemporalPlainMonthDay> month_day = Handle<JSTemporalPlainMonthDay> month_day =
......
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