Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e04b976
deps: update V8 to 13.6.233.8
targos Apr 29, 2025
038c3f2
build: reset embedder string to "-node.0"
targos Apr 29, 2025
045507c
src: update NODE_MODULE_VERSION to 137
targos Apr 29, 2025
2b27576
deps: patch V8 to avoid duplicated zlib symbol
targos Sep 16, 2023
d6837f1
deps: fix FP16 bitcasts.h
StefanStojanovic May 28, 2024
8a9baf6
deps: define V8_PRESERVE_MOST as no-op on Windows
StefanStojanovic Dec 16, 2024
1f9cf1d
deps: remove problematic comment from v8-internal
targos Mar 19, 2025
3deb96e
deps: patch V8 for illumos
danmcd Apr 18, 2025
ee7ad80
deps: use std::map in MSVC STL for EphemeronRememberedSet
joyeecheung Apr 28, 2025
567d78c
deps: disable V8 concurrent sparkplug compilation
targos Apr 6, 2023
ca3fffb
deps: always define V8_EXPORT_PRIVATE as no-op
targos Sep 21, 2022
eabc4fb
deps: patch V8 to support compilation with MSVC
StefanStojanovic Apr 21, 2024
36ee451
deps: V8: backport 954187bb1b87
joyeecheung Apr 24, 2025
840fbbb
build: remove support for s390 32-bit
richardlau Sep 18, 2024
eb26ca3
build: enable shared RO heap with ptr compression
targos Sep 21, 2024
c08834a
tools: update V8 gypfiles for 13.1
targos Sep 25, 2024
0c4f35c
tools: update V8 gypfiles for 13.2
targos Oct 28, 2024
d7d2b59
build,src,tools: adapt build config for V8 13.3
targos Dec 19, 2024
9afc83f
tools: update V8 gypfiles for 13.4
targos Jan 20, 2025
f552e07
build: add `/bigobj` to compile V8 on Windows
targos Feb 5, 2025
b247c98
src: replace uses of FastApiTypedArray
targos Feb 8, 2025
38be4b8
Revert "test: disable fast API call count checks"
targos Jan 31, 2025
3e314b4
test: update test-linux-perf-logger
targos Feb 4, 2025
34b439a
test: adapt assert tests to stack trace changes
targos Dec 20, 2024
9297f92
test: handle explicit resource management globals
targos Dec 21, 2024
50db68a
deps: remove deps/simdutf
targos Jan 29, 2025
e7504c7
tools: update license-builder and LICENSE for V8 deps
targos Jan 29, 2025
6b6add6
src: use `v8::ExternalMemoryAccounter`
targos Feb 15, 2025
9c9f865
src,test: add V8 API to test the hash seed
targos Feb 20, 2025
07cdd3b
build: pass `-fPIC` to linker as well for shared builds
targos Apr 2, 2025
adc9675
build: fix V8 TLS config for shared lib builds
targos Apr 3, 2025
773a8c6
tools: update V8 gypfiles for 13.5
targos Feb 25, 2025
2e71fb7
tools: update V8 gypfiles for 13.6
targos Apr 5, 2025
8a3e8f3
build: update list of installed cppgc headers
targos Apr 6, 2025
6f16029
test: fix test-fs-write for V8 13.6
targos Apr 9, 2025
1780962
src: use V8-owned CppHeap
joyeecheung May 29, 2024
05054d2
src: use non-deprecated Utf8LengthV2() method
anonrig Apr 17, 2025
c21b0e7
src: use non-deprecated WriteUtf8V2() method
anonrig Apr 17, 2025
fb09a88
src,test: unregister the isolate after disposal and before freeing
joyeecheung Apr 21, 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 May 1, 2025
commit b247c98df9288ea37bca1d0800565ab2d732b676
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
168 changes: 87 additions & 81 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 @@ -511,9 +513,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 @@ -549,45 +551,47 @@ void StringSlice(const FunctionCallbackInfo<Value>& args) {
}
}

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);
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();

ArrayBufferViewContents<char> source(args[0]);
SPREAD_BUFFER_ARG(args[1].As<Object>(), target);

uint32_t target_start;
uint32_t source_start;
uint32_t to_copy;
if (!args[2]->Uint32Value(env->context()).To(&target_start) ||
!args[3]->Uint32Value(env->context()).To(&source_start) ||
!args[4]->Uint32Value(env->context()).To(&to_copy)) {
return;
}
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 +735,7 @@ void SlowByteLengthUtf8(const FunctionCallbackInfo<Value>& args) {
uint32_t FastByteLengthUtf8(
Local<Value> receiver,
Local<Value> sourceValue,
v8::FastApiCallbackOptions& options) { // NOLINT(runtime/references)
FastApiCallbackOptions& options) { // NOLINT(runtime/references)
TRACK_V8_FAST_API_CALL("Buffer::FastByteLengthUtf8");
auto isolate = options.isolate;
HandleScope handleScope(isolate);
Expand Down Expand Up @@ -783,8 +787,7 @@ uint32_t FastByteLengthUtf8(
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 @@ -847,39 +850,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 @@ -1109,11 +1112,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 @@ -1137,29 +1142,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 @@ -1503,29 +1507,31 @@ 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 const v8::CFunction fast_write_string_ascii(
v8::CFunction::Make(FastWriteString<ASCII>));
static const v8::CFunction fast_write_string_latin1(
v8::CFunction::Make(FastWriteString<LATIN1>));
static const v8::CFunction fast_write_string_utf8(
v8::CFunction::Make(FastWriteString<UTF8>));
static const CFunction fast_write_string_ascii(
CFunction::Make(FastWriteString<ASCII>));
static const CFunction fast_write_string_latin1(
CFunction::Make(FastWriteString<LATIN1>));
static const CFunction fast_write_string_utf8(
CFunction::Make(FastWriteString<UTF8>));

void Initialize(Local<Object> target,
Local<Value> unused,
Expand Down
42 changes: 19 additions & 23 deletions src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,16 @@ using CFunctionCallbackWithStrings =
const v8::FastOneByteString& base);
using CFunctionCallbackWithTwoUint8Arrays =
int32_t (*)(v8::Local<v8::Value>,
const v8::FastApiTypedArray<uint8_t>&,
const v8::FastApiTypedArray<uint8_t>&);
using CFunctionCallbackWithTwoUint8ArraysFallback =
bool (*)(v8::Local<v8::Value>,
const v8::FastApiTypedArray<uint8_t>&,
const v8::FastApiTypedArray<uint8_t>&,
v8::FastApiCallbackOptions&);
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 @@ -80,20 +77,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 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> 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 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 All @@ -117,7 +114,6 @@ class ExternalReferenceRegistry {
V(CFunctionCallbackWithString) \
V(CFunctionCallbackWithStrings) \
V(CFunctionCallbackWithTwoUint8Arrays) \
V(CFunctionCallbackWithTwoUint8ArraysFallback) \
V(CFunctionCallbackWithUint8ArrayUint32Int64Bool) \
V(CFunctionWithUint32) \
V(CFunctionWithDoubleReturnDouble) \
Expand Down