Skip to content

Commit 2a6f55f

Browse files
gahaasnodejs-github-bot
authored andcommitted
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.
1 parent 74ce746 commit 2a6f55f

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

src/crypto/crypto_timing.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ bool FastTimingSafeEqual(Local<Value> receiver,
5757
uint8_t* data_b;
5858
if (a.length() != b.length() || !a.getStorageIfAligned(&data_a) ||
5959
!b.getStorageIfAligned(&data_b)) {
60-
options.fallback = true;
60+
Environment* env = Environment::GetCurrent(options.isolate);
61+
THROW_ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH(env);
6162
return false;
6263
}
6364

src/histogram.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ void HistogramBase::FastRecord(Local<Value> receiver,
193193
const int64_t value,
194194
FastApiCallbackOptions& options) {
195195
if (value < 1) {
196-
options.fallback = true;
196+
Environment* env = Environment::GetCurrent(options.isolate);
197+
THROW_ERR_OUT_OF_RANGE(env, "value is out of range");
197198
return;
198199
}
199200
HistogramBase* histogram;

src/node_file.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,14 +1057,11 @@ static int32_t FastInternalModuleStat(
10571057
const FastOneByteString& input,
10581058
// NOLINTNEXTLINE(runtime/references) This is V8 api.
10591059
FastApiCallbackOptions& options) {
1060-
Environment* env = Environment::GetCurrent(recv->GetCreationContextChecked());
1060+
Environment* env = Environment::GetCurrent(options.isolate);
10611061

10621062
auto path = std::filesystem::path(input.data, input.data + input.length);
1063-
if (UNLIKELY(!env->permission()->is_granted(
1064-
env, permission::PermissionScope::kFileSystemRead, path.string()))) {
1065-
options.fallback = true;
1066-
return -1;
1067-
}
1063+
THROW_IF_INSUFFICIENT_PERMISSIONS(
1064+
env, permission::PermissionScope::kFileSystemRead, path.string(), -1);
10681065

10691066
switch (std::filesystem::status(path).type()) {
10701067
case std::filesystem::file_type::directory:

src/node_wasi.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,17 @@ R WASI::WasiFunction<FT, F, R, Args...>::FastCallback(
248248
WASI* wasi = reinterpret_cast<WASI*>(BaseObject::FromJSObject(receiver));
249249
if (UNLIKELY(wasi == nullptr)) return EinvalError<R>();
250250

251-
if (UNLIKELY(options.wasm_memory == nullptr || wasi->memory_.IsEmpty())) {
252-
// fallback to slow path which to throw an error about missing memory.
253-
options.fallback = true;
251+
v8::Isolate* isolate = receiver->GetIsolate();
252+
if (wasi->memory_.IsEmpty()) {
253+
THROW_ERR_WASI_NOT_STARTED(isolate);
254254
return EinvalError<R>();
255255
}
256-
uint8_t* memory = nullptr;
257-
CHECK(LIKELY(options.wasm_memory->getStorageIfAligned(&memory)));
256+
Local<ArrayBuffer> ab = wasi->memory_.Get(isolate)->Buffer();
257+
size_t mem_size = ab->ByteLength();
258+
char* mem_data = static_cast<char*>(ab->Data());
259+
CHECK_NOT_NULL(mem_data);
258260

259-
return F(*wasi,
260-
{reinterpret_cast<char*>(memory), options.wasm_memory->length()},
261-
args...);
261+
return F(*wasi, {mem_data, mem_size}, args...);
262262
}
263263

264264
namespace {

0 commit comments

Comments
 (0)