From 2a6f55f46c7c04b107ae6266fed17a52d4e1894e 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 | 3 ++- src/histogram.cc | 3 ++- src/node_file.cc | 9 +++------ src/node_wasi.cc | 16 ++++++++-------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/crypto/crypto_timing.cc b/src/crypto/crypto_timing.cc index 103a620d637..ebd5aecce25 100644 --- a/src/crypto/crypto_timing.cc +++ b/src/crypto/crypto_timing.cc @@ -57,7 +57,8 @@ bool FastTimingSafeEqual(Local receiver, uint8_t* data_b; if (a.length() != b.length() || !a.getStorageIfAligned(&data_a) || !b.getStorageIfAligned(&data_b)) { - options.fallback = true; + Environment* env = Environment::GetCurrent(options.isolate); + THROW_ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH(env); return false; } diff --git a/src/histogram.cc b/src/histogram.cc index 4dbdea9be57..4aacaa2a5d1 100644 --- a/src/histogram.cc +++ b/src/histogram.cc @@ -193,7 +193,8 @@ void HistogramBase::FastRecord(Local receiver, const int64_t value, FastApiCallbackOptions& options) { if (value < 1) { - options.fallback = true; + Environment* env = Environment::GetCurrent(options.isolate); + THROW_ERR_OUT_OF_RANGE(env, "value is out of range"); return; } HistogramBase* histogram; diff --git a/src/node_file.cc b/src/node_file.cc index a86482b194b..56545c85e67 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1057,14 +1057,11 @@ 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); 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..0a5e88b1a9c 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -248,17 +248,17 @@ 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; + v8::Isolate* isolate = receiver->GetIsolate(); + 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 {