Enable V8 sandbox by default (fixes #3332)

When the V8 sandbox is enabled, ArrayBuffer backing stores must be
allocated inside the sandbox address space. This change introduces a new
CefV8Value::CreateArrayBufferWithCopy method that copies the memory
contents into the sandbox address space.

Enabling the V8 sandbox can have a performance impact, especially when
passing large ArrayBuffers from C++ code to the JS side. We have therefore
retained the old CefV8Value::CreateArrayBuffer method that references
external memory. However, this method can only be used if the V8 sandbox is
disabled at CEF/Chromium build time.

To disable the V8 sandbox add `v8_enable_sandbox=false` to
`GN_DEFINES` when building CEF/Chromium.
This commit is contained in:
Nik Pavlov
2024-08-05 16:00:58 +00:00
committed by Marshall Greenblatt
parent 08ae3a44a6
commit 295ea1f715
15 changed files with 264 additions and 72 deletions

View File

@@ -322,6 +322,7 @@ PERF_TEST_FUNC(V8ObjectGetValueWithAccessor) {
PERF_ITERATIONS_END()
}
#ifndef CEF_V8_ENABLE_SANDBOX
PERF_TEST_FUNC(V8ArrayBufferCreate) {
class ReleaseCallback : public CefV8ArrayBufferReleaseCallback {
public:
@@ -339,6 +340,17 @@ PERF_TEST_FUNC(V8ArrayBufferCreate) {
CefV8Value::CreateArrayBuffer(buffer, byte_len, callback);
PERF_ITERATIONS_END()
}
#endif // CEF_V8_ENABLE_SANDBOX
PERF_TEST_FUNC(V8ArrayBufferCopy) {
constexpr size_t len = 1;
constexpr size_t byte_len = len * sizeof(float);
std::array<float, len> buffer = {0};
PERF_ITERATIONS_START()
CefRefPtr<CefV8Value> ret =
CefV8Value::CreateArrayBufferWithCopy(buffer.data(), byte_len);
PERF_ITERATIONS_END()
}
PERF_TEST_FUNC(V8ContextEnterExit) {
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
@@ -385,7 +397,10 @@ const PerfTestEntry kPerfTests[] = {
PERF_TEST_ENTRY(V8ObjectGetValue),
PERF_TEST_ENTRY(V8ObjectSetValueWithAccessor),
PERF_TEST_ENTRY(V8ObjectGetValueWithAccessor),
#ifndef CEF_V8_ENABLE_SANDBOX
PERF_TEST_ENTRY(V8ArrayBufferCreate),
#endif // CEF_V8_ENABLE_SANDBOX
PERF_TEST_ENTRY(V8ArrayBufferCopy),
PERF_TEST_ENTRY(V8ContextEnterExit),
PERF_TEST_ENTRY(V8ContextEval),
};