Skip to content

Commit

Permalink
chore: update node version to v16.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Jul 8, 2024
1 parent 289b91b commit 8f3156d
Show file tree
Hide file tree
Showing 97 changed files with 2,338 additions and 1,972 deletions.
7 changes: 0 additions & 7 deletions deps/node/include/async_wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback(
return MakeCallback(cb_v.As<v8::Function>(), argc, argv);
}


// Defined here to avoid a circular dependency with env-inl.h.
inline AsyncHooks::DefaultTriggerAsyncIdScope ::DefaultTriggerAsyncIdScope(
AsyncWrap* async_wrap)
: DefaultTriggerAsyncIdScope(async_wrap->env(),
async_wrap->get_async_id()) {}

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
2 changes: 1 addition & 1 deletion deps/node/include/async_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class AsyncWrap : public BaseObject {
bool init_hook_ran_ = false;
// Because the values may be Reset(), cannot be made const.
double async_id_ = kInvalidAsyncId;
double trigger_async_id_;
double trigger_async_id_ = kInvalidAsyncId;
};

} // namespace node
Expand Down
18 changes: 11 additions & 7 deletions deps/node/include/base64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "base64.h"
#include "libbase64.h"
#include "util.h"

namespace node {

static constexpr char base64_table_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789-_";

extern const int8_t unbase64_table[256];


Expand Down Expand Up @@ -131,14 +136,19 @@ inline size_t base64_encode(const char* src,

dlen = base64_encoded_size(slen, mode);

if (mode == Base64Mode::NORMAL) {
::base64_encode(src, slen, dst, &dlen, 0);
return dlen;
}

unsigned a;
unsigned b;
unsigned c;
unsigned i;
unsigned k;
unsigned n;

const char* table = base64_select_table(mode);
const char* table = base64_table_url;

i = 0;
k = 0;
Expand All @@ -163,19 +173,13 @@ inline size_t base64_encode(const char* src,
a = src[i + 0] & 0xff;
dst[k + 0] = table[a >> 2];
dst[k + 1] = table[(a & 3) << 4];
if (mode == Base64Mode::NORMAL) {
dst[k + 2] = '=';
dst[k + 3] = '=';
}
break;
case 2:
a = src[i + 0] & 0xff;
b = src[i + 1] & 0xff;
dst[k + 0] = table[a >> 2];
dst[k + 1] = table[((a & 3) << 4) | (b >> 4)];
dst[k + 2] = table[(b & 0x0f) << 2];
if (mode == Base64Mode::NORMAL)
dst[k + 3] = '=';
break;
}

Expand Down
16 changes: 0 additions & 16 deletions deps/node/include/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ enum class Base64Mode {
URL
};

static constexpr char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";

static constexpr char base64_table_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789-_";

static inline const char* base64_select_table(Base64Mode mode) {
switch (mode) {
case Base64Mode::NORMAL: return base64_table;
case Base64Mode::URL: return base64_table_url;
default: UNREACHABLE();
}
}

static inline constexpr size_t base64_encoded_size(
size_t size,
Base64Mode mode = Base64Mode::NORMAL) {
Expand Down
104 changes: 0 additions & 104 deletions deps/node/include/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,6 @@

namespace node {

BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> object)
: persistent_handle_(env->isolate(), object), env_(env) {
CHECK_EQ(false, object.IsEmpty());
CHECK_GT(object->InternalFieldCount(), 0);
object->SetAlignedPointerInInternalField(
BaseObject::kSlot,
static_cast<void*>(this));
env->AddCleanupHook(DeleteMe, static_cast<void*>(this));
env->modify_base_object_count(1);
}

BaseObject::~BaseObject() {
env()->modify_base_object_count(-1);
env()->RemoveCleanupHook(DeleteMe, static_cast<void*>(this));

if (UNLIKELY(has_pointer_data())) {
PointerData* metadata = pointer_data();
CHECK_EQ(metadata->strong_ptr_count, 0);
metadata->self = nullptr;
if (metadata->weak_ptr_count == 0)
delete metadata;
}

if (persistent_handle_.IsEmpty()) {
// This most likely happened because the weak callback below cleared it.
return;
}

{
v8::HandleScope handle_scope(env()->isolate());
object()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr);
}
}

void BaseObject::Detach() {
CHECK_GT(pointer_data()->strong_ptr_count, 0);
pointer_data()->is_detached = true;
Expand Down Expand Up @@ -107,28 +73,6 @@ T* BaseObject::FromJSObject(v8::Local<v8::Value> object) {
return static_cast<T*>(FromJSObject(object));
}


void BaseObject::MakeWeak() {
if (has_pointer_data()) {
pointer_data()->wants_weak_jsobj = true;
if (pointer_data()->strong_ptr_count > 0) return;
}

persistent_handle_.SetWeak(
this,
[](const v8::WeakCallbackInfo<BaseObject>& data) {
BaseObject* obj = data.GetParameter();
// Clear the persistent handle so that ~BaseObject() doesn't attempt
// to mess with internal fields, since the JS object may have
// transitioned into an invalid state.
// Refs: https://github.com/nodejs/node/issues/18897
obj->persistent_handle_.Reset();
CHECK_IMPLIES(obj->has_pointer_data(),
obj->pointer_data()->strong_ptr_count == 0);
obj->OnGCCollect();
}, v8::WeakCallbackType::kParameter);
}

void BaseObject::OnGCCollect() {
delete this;
}
Expand All @@ -148,23 +92,6 @@ bool BaseObject::IsWeakOrDetached() const {
return pd->wants_weak_jsobj || pd->is_detached;
}

void BaseObject::LazilyInitializedJSTemplateConstructor(
const v8::FunctionCallbackInfo<v8::Value>& args) {
DCHECK(args.IsConstructCall());
DCHECK_GT(args.This()->InternalFieldCount(), 0);
args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr);
}

v8::Local<v8::FunctionTemplate>
BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) {
v8::Local<v8::FunctionTemplate> t =
env->NewFunctionTemplate(LazilyInitializedJSTemplateConstructor);
t->Inherit(BaseObject::GetConstructorTemplate(env));
t->InstanceTemplate()->SetInternalFieldCount(
BaseObject::kInternalFieldCount);
return t;
}

template <int Field>
void BaseObject::InternalFieldGet(
v8::Local<v8::String> property,
Expand All @@ -185,37 +112,6 @@ bool BaseObject::has_pointer_data() const {
return pointer_data_ != nullptr;
}

BaseObject::PointerData* BaseObject::pointer_data() {
if (!has_pointer_data()) {
PointerData* metadata = new PointerData();
metadata->wants_weak_jsobj = persistent_handle_.IsWeak();
metadata->self = this;
pointer_data_ = metadata;
}
CHECK(has_pointer_data());
return pointer_data_;
}

void BaseObject::decrease_refcount() {
CHECK(has_pointer_data());
PointerData* metadata = pointer_data();
CHECK_GT(metadata->strong_ptr_count, 0);
unsigned int new_refcount = --metadata->strong_ptr_count;
if (new_refcount == 0) {
if (metadata->is_detached) {
OnGCCollect();
} else if (metadata->wants_weak_jsobj && !persistent_handle_.IsEmpty()) {
MakeWeak();
}
}
}

void BaseObject::increase_refcount() {
unsigned int prev_refcount = pointer_data()->strong_ptr_count++;
if (prev_refcount == 0 && !persistent_handle_.IsEmpty())
persistent_handle_.ClearWeak();
}

template <typename T, bool kIsWeak>
BaseObject::PointerData*
BaseObjectPtrImpl<T, kIsWeak>::pointer_data() const {
Expand Down
24 changes: 13 additions & 11 deletions deps/node/include/base_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ namespace worker {
class TransferData;
}

extern uint16_t kNodeEmbedderId;

class BaseObject : public MemoryRetainer {
public:
enum InternalFields { kSlot, kInternalFieldCount };
enum InternalFields { kEmbedderType, kSlot, kInternalFieldCount };

// Associates this object with `object`. It uses the 0th internal field for
// Associates this object with `object`. It uses the 1st internal field for
// that, and in particular aborts if there is no such field.
inline BaseObject(Environment* env, v8::Local<v8::Object> object);
inline ~BaseObject() override;
BaseObject(Environment* env, v8::Local<v8::Object> object);
~BaseObject() override;

BaseObject() = delete;

Expand All @@ -65,7 +67,7 @@ class BaseObject : public MemoryRetainer {
// was also passed to the `BaseObject()` constructor initially.
// This may return `nullptr` if the C++ object has not been constructed yet,
// e.g. when the JS object used `MakeLazilyInitializedJSTemplate`.
static inline void LazilyInitializedJSTemplateConstructor(
static void LazilyInitializedJSTemplateConstructor(
const v8::FunctionCallbackInfo<v8::Value>& args);
static inline BaseObject* FromJSObject(v8::Local<v8::Value> object);
template <typename T>
Expand All @@ -74,7 +76,7 @@ class BaseObject : public MemoryRetainer {
// Make the `v8::Global` a weak reference and, `delete` this object once
// the JS object has been garbage collected and there are no (strong)
// BaseObjectPtr references to it.
inline void MakeWeak();
void MakeWeak();

// Undo `MakeWeak()`, i.e. turn this into a strong reference that is a GC
// root and will not be touched by the garbage collector.
Expand All @@ -88,7 +90,7 @@ class BaseObject : public MemoryRetainer {
// Utility to create a FunctionTemplate with one internal field (used for
// the `BaseObject*` pointer) and a constructor that initializes that field
// to `nullptr`.
static inline v8::Local<v8::FunctionTemplate> MakeLazilyInitializedJSTemplate(
static v8::Local<v8::FunctionTemplate> MakeLazilyInitializedJSTemplate(
Environment* env);

// Setter/Getter pair for internal fields that can be passed to SetAccessor.
Expand Down Expand Up @@ -171,7 +173,7 @@ class BaseObject : public MemoryRetainer {
// class because it is used by src/node_postmortem_metadata.cc to calculate
// offsets and generate debug symbols for BaseObject, which assumes that the
// position of members in memory are predictable. For more information please
// refer to `doc/guides/node-postmortem-support.md`
// refer to `doc/contributing/node-postmortem-support.md`
friend int GenDebugSymbols();
friend class CleanupHookCallback;
template <typename T, bool kIsWeak>
Expand Down Expand Up @@ -202,11 +204,11 @@ class BaseObject : public MemoryRetainer {
inline bool has_pointer_data() const;
// This creates a PointerData struct if none was associated with this
// BaseObject before.
inline PointerData* pointer_data();
PointerData* pointer_data();

// Functions that adjust the strong pointer count.
inline void decrease_refcount();
inline void increase_refcount();
void decrease_refcount();
void increase_refcount();

Environment* env_;
PointerData* pointer_data_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion deps/node/include/crypto/crypto_aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "crypto/crypto_cipher.h"
#include "crypto/crypto_keys.h"
#include "crypto/crypto_util.h"
#include "allocated_buffer.h"
#include "env.h"
#include "v8.h"

Expand Down Expand Up @@ -81,6 +80,7 @@ using AESCryptoJob = CipherJob<AESCipherTraits>;

namespace AES {
void Initialize(Environment* env, v8::Local<v8::Object> target);
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
} // namespace AES
} // namespace crypto
} // namespace node
Expand Down
13 changes: 9 additions & 4 deletions deps/node/include/crypto/crypto_cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "crypto/crypto_keys.h"
#include "crypto/crypto_util.h"
#include "allocated_buffer-inl.h"
#include "base_object.h"
#include "env.h"
#include "memory_tracker.h"
Expand All @@ -21,6 +20,7 @@ class CipherBase : public BaseObject {
static void GetCiphers(const v8::FunctionCallbackInfo<v8::Value>& args);

static void Initialize(Environment* env, v8::Local<v8::Object> target);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);

void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(CipherBase)
Expand Down Expand Up @@ -60,8 +60,9 @@ class CipherBase : public BaseObject {
bool InitAuthenticated(const char* cipher_type, int iv_len,
unsigned int auth_tag_len);
bool CheckCCMMessageLength(int message_len);
UpdateResult Update(const char* data, size_t len, AllocatedBuffer* out);
bool Final(AllocatedBuffer* out);
UpdateResult Update(const char* data, size_t len,
std::unique_ptr<v8::BackingStore>* out);
bool Final(std::unique_ptr<v8::BackingStore>* out);
bool SetAutoPadding(bool auto_padding);

bool IsAuthenticatedMode() const;
Expand Down Expand Up @@ -114,7 +115,7 @@ class PublicKeyCipher {
const EVP_MD* digest,
const ArrayBufferOrViewContents<unsigned char>& oaep_label,
const ArrayBufferOrViewContents<unsigned char>& data,
AllocatedBuffer* out);
std::unique_ptr<v8::BackingStore>* out);

template <Operation operation,
EVP_PKEY_cipher_init_t EVP_PKEY_cipher_init,
Expand Down Expand Up @@ -190,6 +191,10 @@ class CipherJob final : public CryptoJob<CipherTraits> {
CryptoJob<CipherTraits>::Initialize(New, env, target);
}

static void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
CryptoJob<CipherTraits>::RegisterExternalReferences(New, registry);
}

CipherJob(
Environment* env,
v8::Local<v8::Object> object,
Expand Down
4 changes: 2 additions & 2 deletions deps/node/include/crypto/crypto_clienthello-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ inline void ClientHelloParser::Reset() {

inline void ClientHelloParser::Start(ClientHelloParser::OnHelloCb onhello_cb,
ClientHelloParser::OnEndCb onend_cb,
void* onend_arg) {
void* cb_arg) {
if (!IsEnded())
return;
Reset();
Expand All @@ -61,7 +61,7 @@ inline void ClientHelloParser::Start(ClientHelloParser::OnHelloCb onhello_cb,
state_ = kWaiting;
onhello_cb_ = onhello_cb;
onend_cb_ = onend_cb;
cb_arg_ = onend_arg;
cb_arg_ = cb_arg;
}

inline void ClientHelloParser::End() {
Expand Down
2 changes: 1 addition & 1 deletion deps/node/include/crypto/crypto_clienthello.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ClientHelloParser {
void Parse(const uint8_t* data, size_t avail);

inline void Reset();
inline void Start(OnHelloCb onhello_cb, OnEndCb onend_cb, void* onend_arg);
inline void Start(OnHelloCb onhello_cb, OnEndCb onend_cb, void* cb_arg);
inline void End();
inline bool IsPaused() const;
inline bool IsEnded() const;
Expand Down
Loading

0 comments on commit 8f3156d

Please sign in to comment.