Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c7f674d
deps: update V8 to 13.3.415.20
targos Feb 7, 2025
f5987ab
build: reset embedder string to "-node.0"
targos Feb 7, 2025
cf32db3
src: update NODE_MODULE_VERSION to 135
targos Feb 7, 2025
5bb479d
deps: always define V8_EXPORT_PRIVATE as no-op
targos Sep 21, 2022
2aef73a
deps: disable V8 concurrent sparkplug compilation
targos Apr 6, 2023
33d5f38
deps: patch V8 to avoid duplicated zlib symbol
targos Sep 16, 2023
491a5b2
deps: patch V8 to support compilation with MSVC
StefanStojanovic Apr 21, 2024
d2774c2
deps: fix FP16 bitcasts.h
StefanStojanovic May 28, 2024
ee32ce1
deps: always define V8_NODISCARD as no-op
targos Aug 8, 2024
1e48040
deps: define V8_PRESERVE_MOST as no-op on Windows
StefanStojanovic Dec 16, 2024
b3eaf29
build: remove support for s390 32-bit
richardlau Sep 18, 2024
7fc4386
build: enable shared RO heap with ptr compression
targos Sep 21, 2024
81883b0
tools: update V8 gypfiles for 13.1
targos Sep 25, 2024
2ef20c6
tools: update V8 gypfiles for 13.2
targos Oct 28, 2024
2df68dd
build,src,tools: adapt build config for V8 13.3
targos Dec 19, 2024
b3ca191
build: add `/bigobj` to compile V8 on Windows
targos Feb 5, 2025
1c85fc7
src: replace uses of FastApiTypedArray
targos Feb 8, 2025
c68131c
Revert "test: disable fast API call count checks"
targos Jan 31, 2025
dec5890
test: update test-linux-perf-logger
targos Feb 4, 2025
a4064bf
test: adapt assert tests to stack trace changes
targos Dec 20, 2024
fa3d23b
src: lock the isolate properly in IsolateData destructor
joyeecheung Feb 13, 2025
a1ecc28
test: use v8::Locker to lock isolates properly in cctest
joyeecheung Feb 13, 2025
ebe4dca
deps: fix v8::String namespace
joyeecheung Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src: replace uses of FastApiTypedArray
The API was removed from V8.
  • Loading branch information
targos committed Feb 8, 2025
commit 1c85fc70a84055fcb824373fe95858cd18e1deef
19 changes: 9 additions & 10 deletions src/crypto/crypto_timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace node {

using v8::CFunction;
using v8::FastApiCallbackOptions;
using v8::FastApiTypedArray;
using v8::FunctionCallbackInfo;
using v8::HandleScope;
using v8::Local;
Expand Down Expand Up @@ -51,25 +51,24 @@ void TimingSafeEqual(const FunctionCallbackInfo<Value>& args) {
}

bool FastTimingSafeEqual(Local<Value> receiver,
const FastApiTypedArray<uint8_t>& a,
const FastApiTypedArray<uint8_t>& b,
Local<Value> a_obj,
Local<Value> b_obj,
// NOLINTNEXTLINE(runtime/references)
FastApiCallbackOptions& options) {
uint8_t* data_a;
uint8_t* data_b;
if (a.length() != b.length() || !a.getStorageIfAligned(&data_a) ||
!b.getStorageIfAligned(&data_b)) {
HandleScope scope(options.isolate);
ArrayBufferViewContents<uint8_t> a(a_obj);
ArrayBufferViewContents<uint8_t> b(b_obj);
if (a.length() != b.length()) {
TRACK_V8_FAST_API_CALL("crypto.timingSafeEqual.error");
HandleScope scope(options.isolate);
THROW_ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH(options.isolate);
return false;
}

TRACK_V8_FAST_API_CALL("crypto.timingSafeEqual.ok");
return CRYPTO_memcmp(data_a, data_b, a.length()) == 0;
return CRYPTO_memcmp(a.data(), b.data(), a.length()) == 0;
}

static v8::CFunction fast_equal(v8::CFunction::Make(FastTimingSafeEqual));
static CFunction fast_equal(CFunction::Make(FastTimingSafeEqual));

void Initialize(Environment* env, Local<Object> target) {
SetFastMethodNoSideEffect(
Expand Down
162 changes: 86 additions & 76 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
using v8::BackingStoreInitializationMode;
using v8::CFunction;
using v8::Context;
using v8::EscapableHandleScope;
using v8::FastApiTypedArray;
using v8::FastApiCallbackOptions;
using v8::FastOneByteString;
using v8::FunctionCallbackInfo;
using v8::Global;
using v8::HandleScope;
Expand Down Expand Up @@ -514,9 +516,9 @@ MaybeLocal<Object> New(Environment* env,
free(data);
};
std::unique_ptr<BackingStore> bs =
v8::ArrayBuffer::NewBackingStore(data, length, free_callback, nullptr);
ArrayBuffer::NewBackingStore(data, length, free_callback, nullptr);

Local<ArrayBuffer> ab = v8::ArrayBuffer::New(env->isolate(), std::move(bs));
Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(), std::move(bs));

Local<Object> obj;
if (Buffer::New(env, ab, 0, length).ToLocal(&obj))
Expand Down Expand Up @@ -561,40 +563,47 @@ void StringSlice(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(ret);
}

void CopyImpl(Local<Value> source_obj,
Local<Value> target_obj,
const uint32_t target_start,
const uint32_t source_start,
const uint32_t to_copy) {
ArrayBufferViewContents<char> source(source_obj);
SPREAD_BUFFER_ARG(target_obj, target);

memmove(target_data + target_start, source.data() + source_start, to_copy);
}

// Assume caller has properly validated args.
void SlowCopy(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

ArrayBufferViewContents<char> source(args[0]);
SPREAD_BUFFER_ARG(args[1].As<Object>(), target);
Local<Value> source_obj = args[0];
Local<Value> target_obj = args[1];
const uint32_t target_start = args[2].As<Uint32>()->Value();
const uint32_t source_start = args[3].As<Uint32>()->Value();
const uint32_t to_copy = args[4].As<Uint32>()->Value();

const auto target_start = args[2]->Uint32Value(env->context()).ToChecked();
const auto source_start = args[3]->Uint32Value(env->context()).ToChecked();
const auto to_copy = args[4]->Uint32Value(env->context()).ToChecked();
CopyImpl(source_obj, target_obj, target_start, source_start, to_copy);

memmove(target_data + target_start, source.data() + source_start, to_copy);
args.GetReturnValue().Set(to_copy);
}

// Assume caller has properly validated args.
uint32_t FastCopy(Local<Value> receiver,
const v8::FastApiTypedArray<uint8_t>& source,
const v8::FastApiTypedArray<uint8_t>& target,
Local<Value> source_obj,
Local<Value> target_obj,
uint32_t target_start,
uint32_t source_start,
uint32_t to_copy) {
uint8_t* source_data;
CHECK(source.getStorageIfAligned(&source_data));
uint32_t to_copy,
// NOLINTNEXTLINE(runtime/references)
FastApiCallbackOptions& options) {
HandleScope scope(options.isolate);

uint8_t* target_data;
CHECK(target.getStorageIfAligned(&target_data));

memmove(target_data + target_start, source_data + source_start, to_copy);
CopyImpl(source_obj, target_obj, target_start, source_start, to_copy);

return to_copy;
}

static v8::CFunction fast_copy(v8::CFunction::Make(FastCopy));
static CFunction fast_copy(CFunction::Make(FastCopy));

void Fill(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Expand Down Expand Up @@ -731,7 +740,7 @@ void SlowByteLengthUtf8(const FunctionCallbackInfo<Value>& args) {
}

uint32_t FastByteLengthUtf8(Local<Value> receiver,
const v8::FastOneByteString& source) {
const FastOneByteString& source) {
// For short inputs, the function call overhead to simdutf is maybe
// not worth it, reserve simdutf for long strings.
if (source.length > 128) {
Expand Down Expand Up @@ -773,8 +782,7 @@ uint32_t FastByteLengthUtf8(Local<Value> receiver,
return answer;
}

static v8::CFunction fast_byte_length_utf8(
v8::CFunction::Make(FastByteLengthUtf8));
static CFunction fast_byte_length_utf8(CFunction::Make(FastByteLengthUtf8));

// Normalize val to be an integer in the range of [1, -1] since
// implementations of memcmp() can vary by platform.
Expand Down Expand Up @@ -837,39 +845,39 @@ void CompareOffset(const FunctionCallbackInfo<Value> &args) {
args.GetReturnValue().Set(val);
}

int32_t CompareImpl(Local<Value> a_obj, Local<Value> b_obj) {
ArrayBufferViewContents<char> a(a_obj);
ArrayBufferViewContents<char> b(b_obj);

size_t cmp_length = std::min(a.length(), b.length());

return normalizeCompareVal(
cmp_length > 0 ? memcmp(a.data(), b.data(), cmp_length) : 0,
a.length(),
b.length());
}

void Compare(const FunctionCallbackInfo<Value> &args) {
Environment* env = Environment::GetCurrent(args);

THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]);
THROW_AND_RETURN_UNLESS_BUFFER(env, args[1]);
ArrayBufferViewContents<char> a(args[0]);
ArrayBufferViewContents<char> b(args[1]);

size_t cmp_length = std::min(a.length(), b.length());
int val = CompareImpl(args[0], args[1]);

int val = normalizeCompareVal(cmp_length > 0 ?
memcmp(a.data(), b.data(), cmp_length) : 0,
a.length(), b.length());
args.GetReturnValue().Set(val);
}

int32_t FastCompare(v8::Local<v8::Value>,
const FastApiTypedArray<uint8_t>& a,
const FastApiTypedArray<uint8_t>& b) {
uint8_t* data_a;
uint8_t* data_b;
CHECK(a.getStorageIfAligned(&data_a));
CHECK(b.getStorageIfAligned(&data_b));

size_t cmp_length = std::min(a.length(), b.length());
int32_t FastCompare(Local<Value>,
Local<Value> a_obj,
Local<Value> b_obj,
// NOLINTNEXTLINE(runtime/references)
FastApiCallbackOptions& options) {
HandleScope scope(options.isolate);

return normalizeCompareVal(
cmp_length > 0 ? memcmp(data_a, data_b, cmp_length) : 0,
a.length(),
b.length());
return CompareImpl(a_obj, b_obj);
}

static v8::CFunction fast_compare(v8::CFunction::Make(FastCompare));
static CFunction fast_compare(CFunction::Make(FastCompare));

// Computes the offset for starting an indexOf or lastIndexOf search.
// Returns either a valid offset in [0...<length - 1>], ie inside the Buffer,
Expand Down Expand Up @@ -1099,11 +1107,13 @@ void IndexOfBuffer(const FunctionCallbackInfo<Value>& args) {
result == haystack_length ? -1 : static_cast<int>(result));
}

int32_t IndexOfNumber(const uint8_t* buffer_data,
size_t buffer_length,
uint32_t needle,
int64_t offset_i64,
bool is_forward) {
int32_t IndexOfNumberImpl(Local<Value> buffer_obj,
const uint32_t needle,
const int64_t offset_i64,
const bool is_forward) {
ArrayBufferViewContents<uint8_t> buffer(buffer_obj);
const uint8_t* buffer_data = buffer.data();
const size_t buffer_length = buffer.length();
int64_t opt_offset = IndexOfOffset(buffer_length, offset_i64, 1, is_forward);
if (opt_offset <= -1 || buffer_length == 0) {
return -1;
Expand All @@ -1127,29 +1137,28 @@ void SlowIndexOfNumber(const FunctionCallbackInfo<Value>& args) {
CHECK(args[3]->IsBoolean());

THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]);
ArrayBufferViewContents<uint8_t> buffer(args[0]);

Local<Value> buffer_obj = args[0];
uint32_t needle = args[1].As<Uint32>()->Value();
int64_t offset_i64 = args[2].As<Integer>()->Value();
bool is_forward = args[3]->IsTrue();

args.GetReturnValue().Set(IndexOfNumber(
buffer.data(), buffer.length(), needle, offset_i64, is_forward));
args.GetReturnValue().Set(
IndexOfNumberImpl(buffer_obj, needle, offset_i64, is_forward));
}

int32_t FastIndexOfNumber(v8::Local<v8::Value>,
const FastApiTypedArray<uint8_t>& buffer,
int32_t FastIndexOfNumber(Local<Value>,
Local<Value> buffer_obj,
uint32_t needle,
int64_t offset_i64,
bool is_forward) {
uint8_t* buffer_data;
CHECK(buffer.getStorageIfAligned(&buffer_data));
return IndexOfNumber(
buffer_data, buffer.length(), needle, offset_i64, is_forward);
bool is_forward,
// NOLINTNEXTLINE(runtime/references)
FastApiCallbackOptions& options) {
HandleScope scope(options.isolate);
return IndexOfNumberImpl(buffer_obj, needle, offset_i64, is_forward);
}

static v8::CFunction fast_index_of_number(
v8::CFunction::Make(FastIndexOfNumber));
static CFunction fast_index_of_number(CFunction::Make(FastIndexOfNumber));

void Swap16(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Expand Down Expand Up @@ -1498,29 +1507,30 @@ void SlowWriteString(const FunctionCallbackInfo<Value>& args) {

template <encoding encoding>
uint32_t FastWriteString(Local<Value> receiver,
const v8::FastApiTypedArray<uint8_t>& dst,
const v8::FastOneByteString& src,
Local<Value> dst_obj,
const FastOneByteString& src,
uint32_t offset,
uint32_t max_length) {
uint8_t* dst_data;
CHECK(dst.getStorageIfAligned(&dst_data));
CHECK(offset <= dst.length());
CHECK(dst.length() - offset <= std::numeric_limits<uint32_t>::max());
uint32_t max_length,
// NOLINTNEXTLINE(runtime/references)
FastApiCallbackOptions& options) {
HandleScope handle_scope(options.isolate);
SPREAD_BUFFER_ARG(dst_obj, dst);
CHECK(offset <= dst_length);
CHECK(dst_length - offset <= std::numeric_limits<uint32_t>::max());
TRACK_V8_FAST_API_CALL("buffer.writeString");

return WriteOneByteString<encoding>(
src.data,
src.length,
reinterpret_cast<char*>(dst_data + offset),
std::min<uint32_t>(dst.length() - offset, max_length));
std::min<uint32_t>(dst_length - offset, max_length));
}

static v8::CFunction fast_write_string_ascii(
v8::CFunction::Make(FastWriteString<ASCII>));
static v8::CFunction fast_write_string_latin1(
v8::CFunction::Make(FastWriteString<LATIN1>));
static v8::CFunction fast_write_string_utf8(
v8::CFunction::Make(FastWriteString<UTF8>));
static CFunction fast_write_string_ascii(
CFunction::Make(FastWriteString<ASCII>));
static CFunction fast_write_string_latin1(
CFunction::Make(FastWriteString<LATIN1>));
static CFunction fast_write_string_utf8(CFunction::Make(FastWriteString<UTF8>));

void Initialize(Local<Object> target,
Local<Value> unused,
Expand Down
42 changes: 22 additions & 20 deletions src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ using CFunctionCallbackWithStrings =
const v8::FastOneByteString& base);
using CFunctionCallbackWithTwoUint8Arrays =
int32_t (*)(v8::Local<v8::Value>,
const v8::FastApiTypedArray<uint8_t>&,
const v8::FastApiTypedArray<uint8_t>&);
v8::Local<v8::Value>,
v8::Local<v8::Value>,
v8::FastApiCallbackOptions&);
using CFunctionCallbackWithTwoUint8ArraysFallback =
bool (*)(v8::Local<v8::Value>,
const v8::FastApiTypedArray<uint8_t>&,
const v8::FastApiTypedArray<uint8_t>&,
v8::Local<v8::Value>,
v8::Local<v8::Value>,
v8::FastApiCallbackOptions&);
using CFunctionCallbackWithUint8ArrayUint32Int64Bool =
int32_t (*)(v8::Local<v8::Value>,
const v8::FastApiTypedArray<uint8_t>&,
v8::Local<v8::Value>,
uint32_t,
int64_t,
bool);
bool,
v8::FastApiCallbackOptions&);
using CFunctionWithUint32 = uint32_t (*)(v8::Local<v8::Value>,
const uint32_t input);
using CFunctionWithDoubleReturnDouble = double (*)(v8::Local<v8::Value>,
Expand All @@ -66,20 +68,20 @@ using CFunctionWithBool = void (*)(v8::Local<v8::Value>,
v8::Local<v8::Value>,
bool);

using CFunctionWriteString =
uint32_t (*)(v8::Local<v8::Value> receiver,
const v8::FastApiTypedArray<uint8_t>& dst,
const v8::FastOneByteString& src,
uint32_t offset,
uint32_t max_length);

using CFunctionBufferCopy =
uint32_t (*)(v8::Local<v8::Value> receiver,
const v8::FastApiTypedArray<uint8_t>& source,
const v8::FastApiTypedArray<uint8_t>& target,
uint32_t target_start,
uint32_t source_start,
uint32_t to_copy);
using CFunctionWriteString = uint32_t (*)(v8::Local<v8::Value>,
v8::Local<v8::Value>,
const v8::FastOneByteString&,
uint32_t,
uint32_t,
v8::FastApiCallbackOptions&);

using CFunctionBufferCopy = uint32_t (*)(v8::Local<v8::Value>,
v8::Local<v8::Value>,
v8::Local<v8::Value>,
uint32_t,
uint32_t,
uint32_t,
v8::FastApiCallbackOptions&);

// This class manages the external references from the V8 heap
// to the C++ addresses in Node.js.
Expand Down