Skip to content

Commit

Permalink
src: stop using deprecated fields of v8::FastApiCallbackOptions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gahaas authored and nodejs-github-bot committed Aug 10, 2024
1 parent 96c802b commit c4c3e7c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/crypto/crypto_timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace node {
using v8::FastApiCallbackOptions;
using v8::FastApiTypedArray;
using v8::FunctionCallbackInfo;
using v8::HandleScope;
using v8::Local;
using v8::Object;
using v8::Value;
Expand Down Expand Up @@ -57,7 +58,8 @@ bool FastTimingSafeEqual(Local<Value> receiver,
uint8_t* data_b;
if (a.length() != b.length() || !a.getStorageIfAligned(&data_a) ||
!b.getStorageIfAligned(&data_b)) {
options.fallback = true;
HandleScope scope(options.isolate);
THROW_ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH(options.isolate);
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion src/histogram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,7 +194,8 @@ void HistogramBase::FastRecord(Local<Value> 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;
Expand Down
10 changes: 4 additions & 6 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 10 additions & 8 deletions src/node_wasi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -248,17 +249,18 @@ R WASI::WasiFunction<FT, F, R, Args...>::FastCallback(
WASI* wasi = reinterpret_cast<WASI*>(BaseObject::FromJSObject(receiver));
if (UNLIKELY(wasi == nullptr)) return EinvalError<R>();

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<R>();
}
uint8_t* memory = nullptr;
CHECK(LIKELY(options.wasm_memory->getStorageIfAligned(&memory)));
Local<ArrayBuffer> ab = wasi->memory_.Get(isolate)->Buffer();
size_t mem_size = ab->ByteLength();
char* mem_data = static_cast<char*>(ab->Data());
CHECK_NOT_NULL(mem_data);

return F(*wasi,
{reinterpret_cast<char*>(memory), options.wasm_memory->length()},
args...);
return F(*wasi, {mem_data, mem_size}, args...);
}

namespace {
Expand Down

0 comments on commit c4c3e7c

Please sign in to comment.