From 63063bdddaf0cc9d16748f2888273d6b3ca2f930 Mon Sep 17 00:00:00 2001 From: Andreas Haas Date: Sun, 28 Jul 2024 09:20:12 +0200 Subject: [PATCH] src: stop using deprecated fields of `v8::FastApiCallbackOptions` Two fields on the `v8::FastApiCallbackOptions` struct were deprecated recently: `fallback` and `wasm_memory`. This PR removes uses of these two fields in node.js. --- src/crypto/crypto_timing.cc | 4 +++- src/histogram.cc | 4 +++- src/node_file.cc | 10 ++++------ src/node_wasi.cc | 18 ++++++++++-------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/crypto/crypto_timing.cc b/src/crypto/crypto_timing.cc index 3d8ccc77b59..5c23e830d1e 100644 --- a/src/crypto/crypto_timing.cc +++ b/src/crypto/crypto_timing.cc @@ -13,6 +13,7 @@ namespace node { using v8::FastApiCallbackOptions; using v8::FastApiTypedArray; using v8::FunctionCallbackInfo; +using v8::HandleScope; using v8::Local; using v8::Object; using v8::Value; @@ -59,7 +60,8 @@ bool FastTimingSafeEqual(Local receiver, if (a.length() != b.length() || !a.getStorageIfAligned(&data_a) || !b.getStorageIfAligned(&data_b)) { TRACK_V8_FAST_API_CALL("crypto.timingSafeEqual.error"); - options.fallback = true; + HandleScope scope(options.isolate); + THROW_ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH(options.isolate); return false; } diff --git a/src/histogram.cc b/src/histogram.cc index 4dbdea9be57..20d93c77613 100644 --- a/src/histogram.cc +++ b/src/histogram.cc @@ -14,6 +14,7 @@ using v8::Context; using v8::FastApiCallbackOptions; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; +using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; @@ -193,7 +194,8 @@ void HistogramBase::FastRecord(Local receiver, const int64_t value, FastApiCallbackOptions& options) { if (value < 1) { - options.fallback = true; + HandleScope scope(options.isolate); + THROW_ERR_OUT_OF_RANGE(options.isolate, "value is out of range"); return; } HistogramBase* histogram; diff --git a/src/node_file.cc b/src/node_file.cc index 8d2733a2f79..8ab92f4e55d 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1057,14 +1057,12 @@ static int32_t FastInternalModuleStat( const FastOneByteString& input, // NOLINTNEXTLINE(runtime/references) This is V8 api. FastApiCallbackOptions& options) { - Environment* env = Environment::GetCurrent(recv->GetCreationContextChecked()); + Environment* env = Environment::GetCurrent(options.isolate); + HandleScope scope(env->isolate()); auto path = std::filesystem::path(input.data, input.data + input.length); - if (UNLIKELY(!env->permission()->is_granted( - env, permission::PermissionScope::kFileSystemRead, path.string()))) { - options.fallback = true; - return -1; - } + THROW_IF_INSUFFICIENT_PERMISSIONS( + env, permission::PermissionScope::kFileSystemRead, path.string(), -1); switch (std::filesystem::status(path).type()) { case std::filesystem::file_type::directory: diff --git a/src/node_wasi.cc b/src/node_wasi.cc index ad1da44a01f..01440caee96 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -35,6 +35,7 @@ using v8::Exception; using v8::FastApiCallbackOptions; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; +using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; @@ -248,17 +249,18 @@ R WASI::WasiFunction::FastCallback( WASI* wasi = reinterpret_cast(BaseObject::FromJSObject(receiver)); if (UNLIKELY(wasi == nullptr)) return EinvalError(); - if (UNLIKELY(options.wasm_memory == nullptr || wasi->memory_.IsEmpty())) { - // fallback to slow path which to throw an error about missing memory. - options.fallback = true; + Isolate* isolate = receiver->GetIsolate(); + HandleScope scope(isolate); + if (wasi->memory_.IsEmpty()) { + THROW_ERR_WASI_NOT_STARTED(isolate); return EinvalError(); } - uint8_t* memory = nullptr; - CHECK(LIKELY(options.wasm_memory->getStorageIfAligned(&memory))); + Local ab = wasi->memory_.Get(isolate)->Buffer(); + size_t mem_size = ab->ByteLength(); + char* mem_data = static_cast(ab->Data()); + CHECK_NOT_NULL(mem_data); - return F(*wasi, - {reinterpret_cast(memory), options.wasm_memory->length()}, - args...); + return F(*wasi, {mem_data, mem_size}, args...); } namespace {