Skip to content

Commit f0134fa

Browse files
gahaastargos
authored andcommittedAug 16, 2024
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. PR-URL: #54077 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent 64e8646 commit f0134fa

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed
 

Diff for: ‎src/crypto/crypto_timing.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace node {
1313
using v8::FastApiCallbackOptions;
1414
using v8::FastApiTypedArray;
1515
using v8::FunctionCallbackInfo;
16+
using v8::HandleScope;
1617
using v8::Local;
1718
using v8::Object;
1819
using v8::Value;
@@ -59,7 +60,8 @@ bool FastTimingSafeEqual(Local<Value> receiver,
5960
if (a.length() != b.length() || !a.getStorageIfAligned(&data_a) ||
6061
!b.getStorageIfAligned(&data_b)) {
6162
TRACK_V8_FAST_API_CALL("crypto.timingSafeEqual.error");
62-
options.fallback = true;
63+
HandleScope scope(options.isolate);
64+
THROW_ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH(options.isolate);
6365
return false;
6466
}
6567

Diff for: ‎src/histogram.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using v8::Context;
1414
using v8::FastApiCallbackOptions;
1515
using v8::FunctionCallbackInfo;
1616
using v8::FunctionTemplate;
17+
using v8::HandleScope;
1718
using v8::Integer;
1819
using v8::Isolate;
1920
using v8::Local;
@@ -193,7 +194,8 @@ void HistogramBase::FastRecord(Local<Value> receiver,
193194
const int64_t value,
194195
FastApiCallbackOptions& options) {
195196
if (value < 1) {
196-
options.fallback = true;
197+
HandleScope scope(options.isolate);
198+
THROW_ERR_OUT_OF_RANGE(options.isolate, "value is out of range");
197199
return;
198200
}
199201
HistogramBase* histogram;

Diff for: ‎src/node_file.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -1057,14 +1057,12 @@ 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);
1061+
HandleScope scope(env->isolate());
10611062

10621063
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-
}
1064+
THROW_IF_INSUFFICIENT_PERMISSIONS(
1065+
env, permission::PermissionScope::kFileSystemRead, path.string(), -1);
10681066

10691067
switch (std::filesystem::status(path).type()) {
10701068
case std::filesystem::file_type::directory:

Diff for: ‎src/node_wasi.cc

+10-8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using v8::Exception;
3535
using v8::FastApiCallbackOptions;
3636
using v8::FunctionCallbackInfo;
3737
using v8::FunctionTemplate;
38+
using v8::HandleScope;
3839
using v8::Integer;
3940
using v8::Isolate;
4041
using v8::Local;
@@ -248,17 +249,18 @@ R WASI::WasiFunction<FT, F, R, Args...>::FastCallback(
248249
WASI* wasi = reinterpret_cast<WASI*>(BaseObject::FromJSObject(receiver));
249250
if (UNLIKELY(wasi == nullptr)) return EinvalError<R>();
250251

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;
252+
Isolate* isolate = receiver->GetIsolate();
253+
HandleScope scope(isolate);
254+
if (wasi->memory_.IsEmpty()) {
255+
THROW_ERR_WASI_NOT_STARTED(isolate);
254256
return EinvalError<R>();
255257
}
256-
uint8_t* memory = nullptr;
257-
CHECK(LIKELY(options.wasm_memory->getStorageIfAligned(&memory)));
258+
Local<ArrayBuffer> ab = wasi->memory_.Get(isolate)->Buffer();
259+
size_t mem_size = ab->ByteLength();
260+
char* mem_data = static_cast<char*>(ab->Data());
261+
CHECK_NOT_NULL(mem_data);
258262

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

264266
namespace {

0 commit comments

Comments
 (0)