mirror of
https://github.com/nodejs/node.git
synced 2024-11-27 22:16:50 +01:00
deps: V8: cherry-pick 9df5ef70ff18
Original commit message:
Add an `v8::ArrayBuffer::WasDetached` method to the C++ API
V8's C++ API does not give a way to tell whether an ArrayBuffer has
been detached from the `v8::ArrayBuffer` class. In fact, as far as can
be told from the C++ API without running JS code, detached
ArrayBuffers behave the same as zero-sized ArrayBuffers and there is
no way to observe the difference. However, this difference can be
observed in JS because constructing a TypedArray from a detached
ArrayBuffer will throw.
This change adds a `WasDetached` method to the `v8::ArrayBuffer` class
to give embedders access to this information without having to run JS
code.
Bug: v8:13159
Change-Id: I2bb1e380cee1cecd31f6d48ec3d9f28c03a8a673
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3810345
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83963}
Refs: 9df5ef70ff
PR-URL: https://github.com/nodejs/node/pull/45474
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
926c830995
commit
5b8b92176e
@ -36,7 +36,7 @@
|
||||
|
||||
# Reset this number to 0 on major V8 upgrades.
|
||||
# Increment by one for each non-official patch applied to deps/v8.
|
||||
'v8_embedder_string': '-node.19',
|
||||
'v8_embedder_string': '-node.20',
|
||||
|
||||
##### V8 defaults for Node.js #####
|
||||
|
||||
|
1
deps/v8/AUTHORS
vendored
1
deps/v8/AUTHORS
vendored
@ -60,6 +60,7 @@ Allan Sandfeld Jensen <allan.jensen@qt.io>
|
||||
Amos Lim <eui-sang.lim@samsung.com>
|
||||
Andreas Anyuru <andreas.anyuru@gmail.com>
|
||||
Andrei Kashcha <anvaka@gmail.com>
|
||||
Andreu Botella <andreu@andreubotella.com>
|
||||
Andrew Paprocki <andrew@ishiboo.com>
|
||||
Anna Henningsen <anna@addaleax.net>
|
||||
Antoine du Hamel <duhamelantoine1995@gmail.com>
|
||||
|
8
deps/v8/include/v8-array-buffer.h
vendored
8
deps/v8/include/v8-array-buffer.h
vendored
@ -240,6 +240,11 @@ class V8_EXPORT ArrayBuffer : public Object {
|
||||
*/
|
||||
bool IsDetachable() const;
|
||||
|
||||
/**
|
||||
* Returns true if this ArrayBuffer has been detached.
|
||||
*/
|
||||
bool WasDetached() const;
|
||||
|
||||
/**
|
||||
* Detaches this ArrayBuffer and all its views (typed arrays).
|
||||
* Detaching sets the byte length of the buffer and all typed arrays to zero,
|
||||
@ -253,6 +258,9 @@ class V8_EXPORT ArrayBuffer : public Object {
|
||||
* pointer coordinates the lifetime management of the internal storage
|
||||
* with any live ArrayBuffers on the heap, even across isolates. The embedder
|
||||
* should not attempt to manage lifetime of the storage through other means.
|
||||
*
|
||||
* The returned shared pointer will not be empty, even if the ArrayBuffer has
|
||||
* been detached. Use |WasDetached| to tell if it has been detached instead.
|
||||
*/
|
||||
std::shared_ptr<BackingStore> GetBackingStore();
|
||||
|
||||
|
4
deps/v8/src/api/api.cc
vendored
4
deps/v8/src/api/api.cc
vendored
@ -8064,6 +8064,10 @@ bool v8::ArrayBuffer::IsDetachable() const {
|
||||
return Utils::OpenHandle(this)->is_detachable();
|
||||
}
|
||||
|
||||
bool v8::ArrayBuffer::WasDetached() const {
|
||||
return Utils::OpenHandle(this)->was_detached();
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::shared_ptr<i::BackingStore> ToInternal(
|
||||
std::shared_ptr<i::BackingStoreBase> backing_store) {
|
||||
|
1
deps/v8/test/cctest/cctest.status
vendored
1
deps/v8/test/cctest/cctest.status
vendored
@ -516,6 +516,7 @@
|
||||
'test-api/WasmI32AtomicWaitCallback': [SKIP],
|
||||
'test-api/WasmI64AtomicWaitCallback': [SKIP],
|
||||
'test-api/WasmSetJitCodeEventHandler': [SKIP],
|
||||
'test-api-array-buffer/ArrayBuffer_NonDetachableWasDetached': [SKIP],
|
||||
'test-backing-store/Run_WasmModule_Buffer_Externalized_Regression_UseAfterFree': [SKIP],
|
||||
'test-c-wasm-entry/*': [SKIP],
|
||||
'test-compilation-cache/*': [SKIP],
|
||||
|
31
deps/v8/test/cctest/test-api-array-buffer.cc
vendored
31
deps/v8/test/cctest/test-api-array-buffer.cc
vendored
@ -245,6 +245,37 @@ THREADED_TEST(ArrayBuffer_DetachingScript) {
|
||||
CheckDataViewIsDetached(dv);
|
||||
}
|
||||
|
||||
THREADED_TEST(ArrayBuffer_WasDetached) {
|
||||
LocalContext env;
|
||||
v8::Isolate* isolate = env->GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 0);
|
||||
CHECK(!ab->WasDetached());
|
||||
|
||||
ab->Detach();
|
||||
CHECK(ab->WasDetached());
|
||||
}
|
||||
|
||||
THREADED_TEST(ArrayBuffer_NonDetachableWasDetached) {
|
||||
LocalContext env;
|
||||
v8::Isolate* isolate = env->GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
CompileRun(R"JS(
|
||||
var wasmMemory = new WebAssembly.Memory({initial: 1, maximum: 2});
|
||||
)JS");
|
||||
|
||||
Local<v8::ArrayBuffer> non_detachable =
|
||||
CompileRun("wasmMemory.buffer").As<v8::ArrayBuffer>();
|
||||
CHECK(!non_detachable->IsDetachable());
|
||||
CHECK(!non_detachable->WasDetached());
|
||||
|
||||
CompileRun("wasmMemory.grow(1)");
|
||||
CHECK(!non_detachable->IsDetachable());
|
||||
CHECK(non_detachable->WasDetached());
|
||||
}
|
||||
|
||||
THREADED_TEST(ArrayBuffer_ExternalizeEmpty) {
|
||||
LocalContext env;
|
||||
v8::Isolate* isolate = env->GetIsolate();
|
||||
|
Loading…
Reference in New Issue
Block a user