Compare commits

...

5 Commits

Author SHA1 Message Date
Samuel Attard
d41ed8a118 chore: cherry-pick 521faebc8a7c from chromium (#45942) 2025-03-09 16:27:26 -07:00
Samuel Attard
daa37826f8 chore: cherry-pick 9dacf5694dfd from chromium (#45937) 2025-03-09 16:26:21 -07:00
trop[bot]
e74e1ab4c5 fix: resolve font list in default prefernce values (#45919)
* fix: resolve font list in default prefernce values

Co-authored-by: deepak1556 <hop2deep@gmail.com>

* chore: fix unsafe buffer usage

Co-authored-by: deepak1556 <hop2deep@gmail.com>

* docs: add code comment

Co-authored-by: deepak1556 <hop2deep@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2025-03-07 16:23:47 +01:00
trop[bot]
7d0f24420f fix: javascript heap OOM is not raised (#45912)
fix: javascript heap oom is not raised in node::OOMErrorHandler

node::OOMErrorHandler terminates the process directly without raising an
oom exception. To fix it, set an oom handler into node from electron.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Yang Liu <ouyangliu.leo@gmail.com>
2025-03-07 09:00:12 -06:00
trop[bot]
d1663a5ac6 chore: emphasize documentation style guide (#45910)
docs: emphasize documentation style guide

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Erick Zhao <ezhao@slack-corp.com>
2025-03-06 16:13:11 -05:00
11 changed files with 374 additions and 16 deletions

View File

@@ -13,7 +13,7 @@ Contributors guide: https://github.com/electron/electron/blob/main/CONTRIBUTING.
- [ ] PR description included and stakeholders cc'd
- [ ] `npm test` passes
- [ ] tests are [changed or added](https://github.com/electron/electron/blob/main/docs/development/testing.md)
- [ ] relevant documentation, tutorials, templates and examples are changed or added
- [ ] relevant API documentation, tutorials, and examples are updated and follow the [documentation style guide](https://github.com/electron/electron/blob/main/docs/development/style-guide.md)
- [ ] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).
#### Release Notes

View File

@@ -65,7 +65,7 @@ Verify that the Pull Request is correct and make a corresponding entry in the
API History:
> [!NOTE]
> Refer to the [API History section of `styleguide.md`](../styleguide.md#api-history)
> Refer to the [API History section of `style-guide.md`](./style-guide.md#api-history)
for information on how to create API History blocks.
`````markdown

View File

@@ -195,7 +195,7 @@ required[, optional]
More detailed information on each of the arguments is noted in an unordered list
below the method. The type of argument is notated by either JavaScript primitives
(e.g. `string`, `Promise`, or `Object`), a custom API structure like Electron's
[`Cookie`](api/structures/cookie.md), or the wildcard `any`.
[`Cookie`](../api/structures/cookie.md), or the wildcard `any`.
If the argument is of type `Array`, use `[]` shorthand with the type of value
inside the array (for example,`any[]` or `string[]`).
@@ -290,7 +290,7 @@ The purpose of the API History block is to describe when/where/how/why an API wa
Each API change listed in the block should include a link to the
PR where that change was made along with an optional short description of the
change. If applicable, include the [heading id](https://gist.github.com/asabaylus/3071099)
for that change from the [breaking changes documentation](./breaking-changes.md).
for that change from the [breaking changes documentation](../breaking-changes.md).
The [API History linting script][api-history-linting-script] (`lint:api-history`)
validates API History blocks in the Electron documentation against the schema and

View File

@@ -141,3 +141,5 @@ feat_add_signals_when_embedder_cleanup_callbacks_run_for.patch
feat_separate_content_settings_callback_for_sync_and_async_clipboard.patch
fix_win32_synchronous_spellcheck.patch
chore_remove_conflicting_allow_unsafe_libc_calls.patch
cherry-pick-521faebc8a7c.patch
cherry-pick-9dacf5694dfd.patch

View File

@@ -0,0 +1,33 @@
From 521faebc8a7cffe23177c6600bfcfb3c0b9ab1dc Mon Sep 17 00:00:00 2001
From: Geoff Lang <geofflang@chromium.org>
Date: Thu, 06 Mar 2025 19:39:37 -0800
Subject: [PATCH] Disable setting primtive restart for WebGL in the cmd decoder.
Until it's blocked in ANGLE for WebGL contexts, disable it in the
command decoder on the service side.
Bug: 401059730
Change-Id: Ia9c7d951cbd122454afec2f884968e0a709cee77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6334632
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Commit-Queue: Kenneth Russell <kbr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1429307}
---
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc b/gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc
index ad23480..733c553 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc
@@ -2170,6 +2170,11 @@
case GL_DEBUG_OUTPUT:
return true;
+ case GL_PRIMITIVE_RESTART_FIXED_INDEX:
+ // Disable setting primitive restart at the command decoder level until
+ // it's blocked in ANGLE for WebGL contexts.
+ return feature_info_->IsWebGLContext();
+
default:
return false;
}

View File

@@ -0,0 +1,95 @@
From 9dacf5694dfdb735c335805783840584a50bface Mon Sep 17 00:00:00 2001
From: Geoff Lang <geofflang@chromium.org>
Date: Thu, 06 Mar 2025 16:02:41 -0800
Subject: [PATCH] Move WebGL primitive restart state setting to the GPU process.
ANGLE will validate and initialize this state and errors are generated
when the WebGL client also initializes it on startup.
Initialize it even in the passthrough command decoder temporarily so
that ANGLE can roll without breaking WebGL tests.
Bug: 401059730
Change-Id: I0bfee710673bbcea6f915ffc4fc9be20438a2654
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6330188
Auto-Submit: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1429228}
---
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index d835b1f..0eedac0 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -3272,6 +3272,13 @@
}
}
+ if (feature_info_->context_type() == CONTEXT_TYPE_WEBGL2) {
+ // If WebGL 2, the PRIMITIVE_RESTART_FIXED_INDEX should be always enabled.
+ // See the section <Primitive Restart is Always Enabled> in WebGL 2 spec:
+ // https://www.khronos.org/registry/webgl/specs/latest/2.0/#4.1.4
+ DoEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
+ }
+
if (group_->gpu_preferences().enable_gpu_driver_debug_logging &&
feature_info_->feature_flags().khr_debug) {
InitializeGLDebugLogging(true, GLDebugMessageCallback, &logger_);
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc b/gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc
index 3ccdebc1..ad23480 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc
@@ -1064,6 +1064,17 @@
api()->glDisableFn(GL_TEXTURE_RECTANGLE_ANGLE);
#endif
+ // TEMPORARY: Set primitive restart to enabled by default for WebGL2. Clear
+ // errors afterwards so that when this state is initialized and validated in
+ // ANGLE, it will not generate errors during command buffer initialization.
+ if (feature_info_->context_type() == CONTEXT_TYPE_WEBGL2) {
+ // If WebGL 2, the PRIMITIVE_RESTART_FIXED_INDEX should be always enabled.
+ // See the section <Primitive Restart is Always Enabled> in WebGL 2 spec:
+ // https://www.khronos.org/registry/webgl/specs/latest/2.0/#4.1.4
+ api()->glEnableFn(GL_PRIMITIVE_RESTART_FIXED_INDEX);
+ CheckErrorCallbackState();
+ }
+
// Register this object as a GPU switching observer.
if (feature_info_->IsWebGLContext()) {
ui::GpuSwitchingManager::GetInstance()->AddObserver(this);
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
index 8e898bd..6030000 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
@@ -439,6 +439,13 @@
}
#endif
+ if (init.context_type == CONTEXT_TYPE_WEBGL2 &&
+ group_->feature_info()->gl_version_info().is_es3) {
+ EXPECT_CALL(*gl_, Enable(GL_PRIMITIVE_RESTART_FIXED_INDEX))
+ .Times(1)
+ .RetiresOnSaturation();
+ }
+
if (context_->HasRobustness()) {
EXPECT_CALL(*gl_, GetGraphicsResetStatusARB())
.WillOnce(Return(init.lose_context_on_init ? GL_GUILTY_CONTEXT_RESET_ARB
diff --git a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
index 79597c8..7c42b98 100644
--- a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
+++ b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
@@ -1433,12 +1433,6 @@
WTF::BindRepeating(&WebGLRenderingContextBase::OnErrorMessage,
WrapWeakPersistent(this)));
- // If WebGL 2, the PRIMITIVE_RESTART_FIXED_INDEX should be always enabled.
- // See the section <Primitive Restart is Always Enabled> in WebGL 2 spec:
- // https://www.khronos.org/registry/webgl/specs/latest/2.0/#4.1.4
- if (IsWebGL2())
- ContextGL()->Enable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
-
// This ensures that the context has a valid "lastFlushID" and won't be
// mistakenly identified as the "least recently used" context.
ContextGL()->Flush();

View File

@@ -44,3 +44,4 @@ test_make_eval_snapshot_tests_more_flexible.patch
build_option_to_use_custom_inspector_protocol_path.patch
fix_adjust_wpt_and_webidl_tests_for_enabled_float16array.patch
chore_add_createexternalizabletwobytestring_to_globals.patch
feat_add_oom_error_callback_in_node_isolatesettings.patch

View File

@@ -0,0 +1,42 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Yang Liu <ouyangliu.leo@gmail.com>
Date: Wed, 5 Mar 2025 17:22:39 +0800
Subject: feat: add oom_error_callback in node::IsolateSettings
Expose v8::OOMErrorCallback to allow setting OOM error handler outside Node.js
As described in this issue https://github.com/electron/electron/issues/45894,
Electron fails to capture js heap oom because node::OOMErrorHandler just
terminates the process without raising an exception.
To fix this issue, provide the interface oom_error_callback to enable a
custom oom error callback set from Electron.
diff --git a/src/api/environment.cc b/src/api/environment.cc
index 32fc075e97eebca6c47e796ac5308915746ffa2a..e72bee385865c7d34e9eea6b90c6d911d592f8af 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -241,7 +241,10 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
auto* fatal_error_cb = s.fatal_error_callback ?
s.fatal_error_callback : OnFatalError;
isolate->SetFatalErrorHandler(fatal_error_cb);
- isolate->SetOOMErrorHandler(OOMErrorHandler);
+
+ auto* oom_error_cb = s.oom_error_callback ?
+ s.oom_error_callback : OOMErrorHandler;
+ isolate->SetOOMErrorHandler(oom_error_cb);
if ((s.flags & SHOULD_NOT_SET_PREPARE_STACK_TRACE_CALLBACK) == 0) {
auto* prepare_stack_trace_cb = s.prepare_stack_trace_callback ?
diff --git a/src/node.h b/src/node.h
index afb26ec5690ccd65a3c36f8b8a1b2de416b9d843..98ad0ea649eaef43d1f5231f7bc4044e100e08d7 100644
--- a/src/node.h
+++ b/src/node.h
@@ -489,6 +489,7 @@ struct IsolateSettings {
v8::Isolate::AbortOnUncaughtExceptionCallback
should_abort_on_uncaught_exception_callback = nullptr;
v8::FatalErrorCallback fatal_error_callback = nullptr;
+ v8::OOMErrorCallback oom_error_callback = nullptr;
v8::PrepareStackTraceCallback prepare_stack_trace_callback = nullptr;
// Miscellaneous callbacks

View File

@@ -9,14 +9,101 @@
#include "base/containers/fixed_flat_map.h"
#include "base/containers/map_util.h"
#include "base/strings/cstring_view.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/platform_locale_settings.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/icu/source/common/unicode/uchar.h"
#include "third_party/icu/source/common/unicode/uscript.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#endif
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
// If a font name in prefs default values starts with a comma, consider it's a
// comma-separated font list and resolve it to the first available font.
#define PREFS_FONT_LIST 1
#include "ui/gfx/font_list.h"
#else
#define PREFS_FONT_LIST 0
#endif
namespace {
#if BUILDFLAG(IS_WIN)
// On Windows with antialiasing we want to use an alternate fixed font like
// Consolas, which looks much better than Courier New.
bool ShouldUseAlternateDefaultFixedFont(const std::string& script) {
if (!base::StartsWith(script, "courier",
base::CompareCase::INSENSITIVE_ASCII)) {
return false;
}
UINT smooth_type = 0;
SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smooth_type, 0);
return smooth_type == FE_FONTSMOOTHINGCLEARTYPE;
}
#endif
// Returns the script of the font pref |pref_name|. For example, suppose
// |pref_name| is "webkit.webprefs.fonts.serif.Hant". Since the script code for
// the script name "Hant" is USCRIPT_TRADITIONAL_HAN, the function returns
// USCRIPT_TRADITIONAL_HAN. |pref_name| must be a valid font pref name.
UScriptCode GetScriptOfFontPref(const base::cstring_view pref_name) {
// ICU script names are four letters.
static const size_t kScriptNameLength = 4;
size_t len = pref_name.size();
DCHECK_GT(len, kScriptNameLength);
const char* scriptName = pref_name.substr(len - kScriptNameLength).data();
int32_t code = u_getPropertyValueEnum(UCHAR_SCRIPT, scriptName);
DCHECK(code >= 0 && code < USCRIPT_CODE_LIMIT);
return static_cast<UScriptCode>(code);
}
// Returns the primary script used by the browser's UI locale. For example, if
// the locale is "ru", the function returns USCRIPT_CYRILLIC, and if the locale
// is "en", the function returns USCRIPT_LATIN.
UScriptCode GetScriptOfBrowserLocale(const std::string& locale) {
// For Chinese locales, uscript_getCode() just returns USCRIPT_HAN but our
// per-script fonts are for USCRIPT_SIMPLIFIED_HAN and
// USCRIPT_TRADITIONAL_HAN.
if (locale == "zh-CN") {
return USCRIPT_SIMPLIFIED_HAN;
}
if (locale == "zh-TW") {
return USCRIPT_TRADITIONAL_HAN;
}
// For Korean and Japanese, multiple scripts are returned by
// |uscript_getCode|, but we're passing a one entry buffer leading
// the buffer to be filled by USCRIPT_INVALID_CODE. We need to
// hard-code the results for them.
if (locale == "ko") {
return USCRIPT_HANGUL;
}
if (locale == "ja") {
return USCRIPT_JAPANESE;
}
UScriptCode code = USCRIPT_INVALID_CODE;
UErrorCode err = U_ZERO_ERROR;
uscript_getCode(locale.c_str(), &code, 1, &err);
if (U_FAILURE(err)) {
code = USCRIPT_INVALID_CODE;
}
return code;
}
struct FontDefault {
const char* pref_name;
int resource_id;
};
// The following list of font defaults was copied from
// https://chromium.googlesource.com/chromium/src/+/69.0.3497.106/chrome/browser/ui/prefs/prefs_tab_helper.cc#152
//
@@ -25,22 +112,18 @@ namespace {
//
// vvvvv DO NOT EDIT vvvvv
struct FontDefault {
const char* pref_name;
int resource_id;
};
// Font pref defaults. The prefs that have defaults vary by platform, since not
// all platforms have fonts for all scripts for all generic families.
// TODO(falken): add proper defaults when possible for all
// platforms/scripts/generic families.
const FontDefault kFontDefaults[] = {
constexpr auto kFontDefaults = std::to_array<FontDefault>({
{prefs::kWebKitStandardFontFamily, IDS_STANDARD_FONT_FAMILY},
{prefs::kWebKitFixedFontFamily, IDS_FIXED_FONT_FAMILY},
{prefs::kWebKitSerifFontFamily, IDS_SERIF_FONT_FAMILY},
{prefs::kWebKitSansSerifFontFamily, IDS_SANS_SERIF_FONT_FAMILY},
{prefs::kWebKitCursiveFontFamily, IDS_CURSIVE_FONT_FAMILY},
{prefs::kWebKitFantasyFontFamily, IDS_FANTASY_FONT_FAMILY},
{prefs::kWebKitMathFontFamily, IDS_MATH_FONT_FAMILY},
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
{prefs::kWebKitStandardFontFamilyJapanese,
IDS_STANDARD_FONT_FAMILY_JAPANESE},
@@ -102,7 +185,7 @@ const FontDefault kFontDefaults[] = {
{prefs::kWebKitFixedFontFamilyTraditionalHan,
IDS_FIXED_FONT_FAMILY_TRADITIONAL_HAN},
#endif
};
});
// ^^^^^ DO NOT EDIT ^^^^^
@@ -125,6 +208,9 @@ auto MakeDefaultFontCopier() {
WP defaults;
std::set<std::string> fonts_with_defaults;
UScriptCode browser_script =
GetScriptOfBrowserLocale(g_browser_process->GetApplicationLocale());
// Populate `defaults`'s ScriptFontFamilyMaps with the values from
// the kFontDefaults array in the "DO NOT EDIT" section of this file.
//
@@ -133,11 +219,75 @@ auto MakeDefaultFontCopier() {
// "webkit.webprefs.fonts.fixed.Zyyy" splits into family name
// "webkit.webprefs.fonts.fixed" and script "Zyyy". (Yes, "Zyyy" is real.
// See pref_font_script_names-inl.h for the full list :)
for (const auto& [pref_name, resource_id] : kFontDefaults) {
const auto [family, script] = *base::RSplitStringOnce(pref_name, '.');
if (auto* family_map_ptr = base::FindOrNull(FamilyMapByName, family)) {
FamilyMap& family_map = defaults.**family_map_ptr;
family_map[std::string{script}] = l10n_util::GetStringUTF16(resource_id);
for (auto [pref_name, resource_id] : kFontDefaults) {
#if BUILDFLAG(IS_WIN)
if (pref_name == prefs::kWebKitFixedFontFamily) {
if (ShouldUseAlternateDefaultFixedFont(
l10n_util::GetStringUTF8(resource_id))) {
resource_id = IDS_FIXED_FONT_FAMILY_ALT_WIN;
}
}
#endif
UScriptCode pref_script =
GetScriptOfFontPref(UNSAFE_BUFFERS(base::cstring_view(pref_name)));
// Suppress this default font pref value if it is for the primary script of
// the browser's UI locale. For example, if the pref is for the sans-serif
// font for the Cyrillic script, and the browser locale is "ru" (Russian),
// the default is suppressed. Otherwise, the default would override the
// user's font preferences when viewing pages in their native language.
// This is because users have no way yet of customizing their per-script
// font preferences. The font prefs accessible in the options UI are for
// the default, unknown script; these prefs have less priority than the
// per-script font prefs when the script of the content is known. This code
// can possibly be removed later if users can easily access per-script font
// prefs (e.g., via the extensions workflow), or the problem turns out to
// not be really critical after all.
if (browser_script != pref_script) {
std::string value = l10n_util::GetStringUTF8(resource_id);
#if PREFS_FONT_LIST
if (value.starts_with(',')) {
value = gfx::FontList::FirstAvailableOrFirst(value);
}
#else // !PREFS_FONT_LIST
DCHECK(!value.starts_with(','))
<< "This platform doesn't support default font lists. " << pref_name
<< "=" << value;
#endif // PREFS_FONT_LIST
const auto [family, script] = *base::RSplitStringOnce(pref_name, '.');
if (auto* family_map_ptr = base::FindOrNull(FamilyMapByName, family)) {
FamilyMap& family_map = defaults.**family_map_ptr;
family_map[std::string{script}] = base::UTF8ToUTF16(value);
}
fonts_with_defaults.insert(pref_name);
}
}
// Expand the font concatenated with script name so this stays at RO memory
// rather than allocated in heap.
// clang-format off
static const auto kFontFamilyMap = std::to_array<const char *>({
#define EXPAND_SCRIPT_FONT(map_name, script_name) map_name "." script_name,
#include "chrome/common/pref_font_script_names-inl.h"
ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_CURSIVE)
ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_FIXED)
ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_SANSERIF)
ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_SERIF)
ALL_FONT_SCRIPTS(WEBKIT_WEBPREFS_FONTS_STANDARD)
#undef EXPAND_SCRIPT_FONT
});
// clang-format on
for (const char* const pref_name : kFontFamilyMap) {
if (fonts_with_defaults.find(pref_name) == fonts_with_defaults.end()) {
// We haven't already set a default value for this font preference, so set
// an empty string as the default.
const auto [family, script] = *base::RSplitStringOnce(pref_name, '.');
if (auto* family_map_ptr = base::FindOrNull(FamilyMapByName, family)) {
FamilyMap& family_map = defaults.**family_map_ptr;
family_map[std::string{script}] = std::u16string();
}
}
}

View File

@@ -13,6 +13,12 @@ struct WebPreferences;
namespace electron {
// Set the default font preferences. The functionality is copied from
// chrome/browser/prefs_tab_helper.cc with modifications to work
// without a preference service and cache chrome/browser/font_family_cache.cc
// that persists across app sessions.
// Keep the core logic in sync to avoid performance regressions
// Refs https://issues.chromium.org/issues/400473071
void SetFontDefaults(blink::web_pref::WebPreferences* prefs);
} // namespace electron

View File

@@ -10,6 +10,7 @@
#include <utility>
#include <vector>
#include "base/allocator/partition_allocator/src/partition_alloc/oom.h"
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/containers/fixed_flat_set.h"
@@ -169,6 +170,33 @@ void V8FatalErrorCallback(const char* location, const char* message) {
*zero = 0;
}
void V8OOMErrorCallback(const char* location, const v8::OOMDetails& details) {
const char* message =
details.is_heap_oom ? "Allocation failed - JavaScript heap out of memory"
: "Allocation failed - process out of memory";
if (location) {
LOG(ERROR) << "OOM error in V8: " << location << " " << message;
} else {
LOG(ERROR) << "OOM error in V8: " << message;
}
if (details.detail) {
LOG(ERROR) << "OOM detail: " << details.detail;
}
#if !IS_MAS_BUILD()
electron::crash_keys::SetCrashKey("electron.v8-oom.is_heap_oom",
std::to_string(details.is_heap_oom));
if (location) {
electron::crash_keys::SetCrashKey("electron.v8-oom.location", location);
}
if (details.detail) {
electron::crash_keys::SetCrashKey("electron.v8-oom.detail", details.detail);
}
#endif
OOM_CRASH(0);
}
bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
v8::Local<v8::String> source) {
// If we're running with contextIsolation enabled in the renderer process,
@@ -688,6 +716,7 @@ std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
// Use a custom fatal error callback to allow us to add
// crash message and location to CrashReports.
is.fatal_error_callback = V8FatalErrorCallback;
is.oom_error_callback = V8OOMErrorCallback;
// We don't want to abort either in the renderer or browser processes.
// We already listen for uncaught exceptions and handle them there.