Commit 44c74847 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[API] Add LegacyOOMErrorCallback

This adds a typedef for LegacyOOMErrorCallback, which is identical to
OOMErrorCallback. Embedders will need to switch to
LegacyOOMErrorCallback so that we can change the definition of
OOMErrorCallback (see https://crbug.com/1323177).

R=mlippautz@chromium.org

Bug: chromium:1323177
Change-Id: I92312a577ca49e0174f2bb6b914cc11c3a0b0fc1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3632305Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80424}
parent 9e3f20b2
......@@ -216,7 +216,14 @@ using AddHistogramSampleCallback = void (*)(void* histogram, int sample);
using FatalErrorCallback = void (*)(const char* location, const char* message);
using OOMErrorCallback = void (*)(const char* location, bool is_heap_oom);
using LegacyOOMErrorCallback = void (*)(const char* location, bool is_heap_oom);
// TODO(chromium:1323177): Add a parameter for details, once this is deprecated
// for at least one branch.
using OOMErrorCallback V8_DEPRECATE_SOON(
"Use LegacyOOMErrorCallback; OOMErrorCallback will be changed "
"(https://crbug.com/1323177)") = void (*)(const char* location,
bool is_heap_oom);
using MessageCallback = void (*)(Local<Message> message, Local<Value> data);
......
......@@ -271,7 +271,7 @@ class V8_EXPORT V8 {
* exceptions in V8-generated code.
*/
static void SetUnhandledExceptionCallback(
UnhandledExceptionCallback unhandled_exception_callback);
UnhandledExceptionCallback callback);
#endif
/**
......@@ -279,8 +279,7 @@ class V8_EXPORT V8 {
* v8 has encountered a fatal failure to allocate memory and is about to
* terminate.
*/
static void SetFatalMemoryErrorCallback(OOMErrorCallback oom_error_callback);
static void SetFatalMemoryErrorCallback(LegacyOOMErrorCallback callback);
/**
* Get statistics about the shared memory usage.
......
......@@ -286,6 +286,10 @@ class V8_EXPORT Isolate {
* Callbacks to invoke in case of fatal or OOM errors.
*/
FatalErrorCallback fatal_error_callback = nullptr;
LegacyOOMErrorCallback legacy_oom_error_callback = nullptr;
V8_DEPRECATE_SOON(
"Use legacy_oom_error_callback; OOMErrorCallback will be changed soon "
"(https://crbug.com/1323177)")
OOMErrorCallback oom_error_callback = nullptr;
/**
......@@ -1475,7 +1479,7 @@ class V8_EXPORT Isolate {
void SetFatalErrorHandler(FatalErrorCallback that);
/** Set the callback to invoke in case of OOM errors. */
void SetOOMErrorHandler(OOMErrorCallback that);
void SetOOMErrorHandler(LegacyOOMErrorCallback that);
/**
* Add a callback to invoke in case the heap size is close to the heap limit.
......
......@@ -172,7 +172,9 @@
namespace v8 {
static OOMErrorCallback g_oom_error_callback = nullptr;
// TODO(chromium:1323177): Add a separate global for OOMErrorCallback once the
// types diverge.
static LegacyOOMErrorCallback g_oom_error_callback = nullptr;
static ScriptOrigin GetScriptOriginForScript(i::Isolate* i_isolate,
i::Handle<i::Script> script) {
......@@ -330,7 +332,7 @@ void Utils::ReportApiFailure(const char* location, const char* message) {
void Utils::ReportOOMFailure(i::Isolate* i_isolate, const char* location,
bool is_heap_oom) {
OOMErrorCallback oom_callback = i_isolate->oom_behavior();
LegacyOOMErrorCallback oom_callback = i_isolate->oom_behavior();
if (oom_callback == nullptr) {
// TODO(wfh): Remove this fallback once Blink is setting OOM handler. See
// crbug.com/614440.
......@@ -6118,7 +6120,7 @@ void V8::SetUnhandledExceptionCallback(
#endif // V8_OS_WIN
void v8::V8::SetFatalMemoryErrorCallback(
v8::OOMErrorCallback oom_error_callback) {
v8::LegacyOOMErrorCallback oom_error_callback) {
g_oom_error_callback = oom_error_callback;
}
......@@ -8629,9 +8631,18 @@ void Isolate::Initialize(Isolate* v8_isolate,
v8_isolate->SetFatalErrorHandler(params.fatal_error_callback);
}
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
if (params.oom_error_callback) {
v8_isolate->SetOOMErrorHandler(params.oom_error_callback);
} else if (params.legacy_oom_error_callback) {
v8_isolate->SetOOMErrorHandler(params.legacy_oom_error_callback);
}
#if __clang__
#pragma clang diagnostic pop
#endif
if (params.counter_lookup_callback) {
v8_isolate->SetCounterFunction(params.counter_lookup_callback);
......@@ -9373,7 +9384,7 @@ size_t Isolate::CopyCodePages(size_t capacity, MemoryRange* code_pages_out) {
}
CALLBACK_SETTER(FatalErrorHandler, FatalErrorCallback, exception_behavior)
CALLBACK_SETTER(OOMErrorHandler, OOMErrorCallback, oom_behavior)
CALLBACK_SETTER(OOMErrorHandler, LegacyOOMErrorCallback, oom_behavior)
CALLBACK_SETTER(ModifyCodeGenerationFromStringsCallback,
ModifyCodeGenerationFromStringsCallback2,
modify_code_gen_callback2)
......
......@@ -465,7 +465,7 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>;
#define ISOLATE_INIT_LIST(V) \
/* Assembler state. */ \
V(FatalErrorCallback, exception_behavior, nullptr) \
V(OOMErrorCallback, oom_behavior, nullptr) \
V(LegacyOOMErrorCallback, oom_behavior, nullptr) \
V(LogEventCallback, event_logger, nullptr) \
V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, nullptr) \
V(ModifyCodeGenerationFromStringsCallback, modify_code_gen_callback, \
......
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