Introduce ErrorUtils::StackTraceCollection
Introduce the enum class to expand a boolean parameter in ErrorUtils::Construct. This is a preliminary change for error serialization: we want to create an error with the given stack string. Bug: chromium:970079 Change-Id: Ic55993d39d5d7b92197e2062a2be7cd8e87e552a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1689674 Reviewed-by: Simon Zünd <szuend@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Yutaka Hirano <yhirano@chromium.org> Cr-Commit-Position: refs/heads/master@{#62550}
This commit is contained in:
parent
c14f209fe6
commit
46c3ea3154
@ -31,10 +31,11 @@ BUILTIN(ErrorConstructor) {
|
||||
}
|
||||
|
||||
RETURN_RESULT_OR_FAILURE(
|
||||
isolate, ErrorUtils::Construct(isolate, args.target(),
|
||||
Handle<Object>::cast(args.new_target()),
|
||||
args.atOrUndefined(isolate, 1), mode,
|
||||
caller, false));
|
||||
isolate,
|
||||
ErrorUtils::Construct(isolate, args.target(),
|
||||
Handle<Object>::cast(args.new_target()),
|
||||
args.atOrUndefined(isolate, 1), mode, caller,
|
||||
ErrorUtils::StackTraceCollection::kDetailed));
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -1378,7 +1378,8 @@ Object Isolate::StackOverflow() {
|
||||
Handle<Object> exception;
|
||||
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
||||
this, exception,
|
||||
ErrorUtils::Construct(this, fun, fun, msg, SKIP_NONE, no_caller, true));
|
||||
ErrorUtils::Construct(this, fun, fun, msg, SKIP_NONE, no_caller,
|
||||
ErrorUtils::StackTraceCollection::kSimple));
|
||||
|
||||
Throw(*exception, nullptr);
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "src/api/api-inl.h"
|
||||
#include "src/base/v8-fallthrough.h"
|
||||
#include "src/execution/execution.h"
|
||||
#include "src/execution/isolate-inl.h"
|
||||
#include "src/logging/counters.h"
|
||||
@ -975,7 +976,7 @@ MaybeHandle<String> MessageFormatter::Format(Isolate* isolate,
|
||||
MaybeHandle<Object> ErrorUtils::Construct(
|
||||
Isolate* isolate, Handle<JSFunction> target, Handle<Object> new_target,
|
||||
Handle<Object> message, FrameSkipMode mode, Handle<Object> caller,
|
||||
bool suppress_detailed_trace) {
|
||||
StackTraceCollection stack_trace_collection) {
|
||||
// 1. If NewTarget is undefined, let newTarget be the active function object,
|
||||
// else let newTarget be NewTarget.
|
||||
|
||||
@ -1009,17 +1010,19 @@ MaybeHandle<Object> ErrorUtils::Construct(
|
||||
Object);
|
||||
}
|
||||
|
||||
// Optionally capture a more detailed stack trace for the message.
|
||||
if (!suppress_detailed_trace) {
|
||||
RETURN_ON_EXCEPTION(isolate, isolate->CaptureAndSetDetailedStackTrace(err),
|
||||
Object);
|
||||
switch (stack_trace_collection) {
|
||||
case StackTraceCollection::kDetailed:
|
||||
RETURN_ON_EXCEPTION(
|
||||
isolate, isolate->CaptureAndSetDetailedStackTrace(err), Object);
|
||||
V8_FALLTHROUGH;
|
||||
case StackTraceCollection::kSimple:
|
||||
RETURN_ON_EXCEPTION(
|
||||
isolate, isolate->CaptureAndSetSimpleStackTrace(err, mode, caller),
|
||||
Object);
|
||||
break;
|
||||
case StackTraceCollection::kNone:
|
||||
break;
|
||||
}
|
||||
|
||||
// Capture a simple stack trace for the stack property.
|
||||
RETURN_ON_EXCEPTION(isolate,
|
||||
isolate->CaptureAndSetSimpleStackTrace(err, mode, caller),
|
||||
Object);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -1148,7 +1151,7 @@ MaybeHandle<Object> ErrorUtils::MakeGenericError(
|
||||
|
||||
Handle<Object> no_caller;
|
||||
return ErrorUtils::Construct(isolate, constructor, constructor, msg, mode,
|
||||
no_caller, false);
|
||||
no_caller, StackTraceCollection::kDetailed);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@ -259,10 +259,13 @@ enum FrameSkipMode {
|
||||
|
||||
class ErrorUtils : public AllStatic {
|
||||
public:
|
||||
// |kNone| is useful when you don't need the stack information at all, for
|
||||
// example when creating a deserialized error.
|
||||
enum class StackTraceCollection { kDetailed, kSimple, kNone };
|
||||
static MaybeHandle<Object> Construct(
|
||||
Isolate* isolate, Handle<JSFunction> target, Handle<Object> new_target,
|
||||
Handle<Object> message, FrameSkipMode mode, Handle<Object> caller,
|
||||
bool suppress_detailed_trace);
|
||||
StackTraceCollection stack_trace_collection);
|
||||
|
||||
static MaybeHandle<String> ToString(Isolate* isolate, Handle<Object> recv);
|
||||
|
||||
|
@ -2290,9 +2290,9 @@ Handle<Object> Factory::NewError(Handle<JSFunction> constructor,
|
||||
// as the result.
|
||||
|
||||
Handle<Object> no_caller;
|
||||
MaybeHandle<Object> maybe_error =
|
||||
ErrorUtils::Construct(isolate(), constructor, constructor, message,
|
||||
SKIP_NONE, no_caller, false);
|
||||
MaybeHandle<Object> maybe_error = ErrorUtils::Construct(
|
||||
isolate(), constructor, constructor, message, SKIP_NONE, no_caller,
|
||||
ErrorUtils::StackTraceCollection::kDetailed);
|
||||
if (maybe_error.is_null()) {
|
||||
DCHECK(isolate()->has_pending_exception());
|
||||
maybe_error = handle(isolate()->pending_exception(), isolate());
|
||||
|
Loading…
Reference in New Issue
Block a user