Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/api/callback.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,

Local<Context> context = env->context();
if (use_async_hooks_trampoline) {
MaybeStackBuffer<Local<Value>, 16> args(3 + argc);
MaybeStackBuffer<Value, 16> args(env->isolate(), 3 + argc);
args[0] = Number::New(env->isolate(), asyncContext.async_id);
args[1] = resource;
args[2] = callback;
Expand Down
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,12 +187,12 @@ Local<Array> AddrTTLToArray(
Environment* env,
const T* addrttls,
size_t naddrttls) {
MaybeStackBuffer<Local<Value>, 8> ttls(naddrttls);
MaybeStackBuffer<Value, 8> ttls(env->isolate(), naddrttls);
for (size_t i = 0; i < naddrttls; i++) {
ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl);
}

return Array::New(env->isolate(), ttls.out(), naddrttls);
return ttls.ToArray();
}

// Parse the CSV produced by ares_get_servers_csv() back into (ip, port)
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/crypto_tls.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,6 @@ using ncrypto::MarkPopErrorOnReturn;
using ncrypto::SSLPointer;
using ncrypto::SSLSessionPointer;
using ncrypto::X509Pointer;
using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
Expand DownExpand Up@@ -1956,7 +1955,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
SSL* ssl = w->ssl_.get();
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
nullptr);
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
MaybeStackBuffer<Value, 16> ret_arr(env->isolate(), nsig);

for (int i = 0; i < nsig; i++) {
int hash_nid;
Expand DownExpand Up@@ -2023,8 +2022,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
ret_arr[i] = OneByteString(env->isolate(), sig_with_md);
}

args.GetReturnValue().Set(
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
args.GetReturnValue().Set(ret_arr.ToArray());
}

void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
Expand Down
8 changes: 2 additions & 6 deletions src/js_stream.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ namespace node {

using errors::TryCatchScope;

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -119,17 +118,14 @@ int JSStream::DoWrite(WriteWrap* w,

int value_int = UV_EPROTO;

MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
MaybeStackBuffer<Value, 16> bufs_arr(env()->isolate(), count);
for (size_t i = 0; i < count; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
return value_int;
}
}

Local<Value> argv[] = {
w->object(),
Array::New(env()->isolate(), bufs_arr.out(), count)
};
Local<Value> argv[] = {w->object(), bufs_arr.ToArray()};

TryCatchScope try_catch(env());
Local<Value> value;
Expand Down
9 changes: 4 additions & 5 deletions src/js_udp_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@
namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -98,7 +97,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
int64_t value_int = JS_EXCEPTION_PENDING;
size_t total_len = 0;

MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
MaybeStackBuffer<Value, 16> buffers(env()->isolate(), nbufs);
for (size_t i = 0; i < nbufs; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
return value_int;
Expand All@@ -110,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int;

Local<Value> args[] = {
listener()->CreateSendWrap(total_len)->object(),
Array::New(env()->isolate(), buffers.out(), nbufs),
address,
listener()->CreateSendWrap(total_len)->object(),
buffers.ToArray(),
address,
};

if (!MakeCallback(env()->onwrite_string(), arraysize(args), args)
Expand Down
7 changes: 7 additions & 0 deletions src/node_concepts.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <v8.h>
#include <concepts>
#include <limits>
#include <type_traits>
Expand DownExpand Up@@ -32,6 +33,12 @@ concept StandardCharType =
template <typename T>
concept IsCallable = std::is_function<T>::value || requires { &T::operator(); };

// Types that can reside on V8's managed heap (v8::Value, v8::Object, etc.).
// Used to select the MaybeStackBuffer specialization that holds handles in a
// v8::LocalVector instead of malloc'd memory.
template <typename T>
concept V8Type = std::is_base_of_v<v8::Data, T>;

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
uv_dirent_t* ents,
int num,
enum encoding encoding) {
MaybeStackBuffer<Local<Value>, 64> entries(num * 2);
MaybeStackBuffer<Value, 64> entries(env->isolate(), num * 2);

// Return an array of all read filenames.
int j = 0;
Expand All@@ -222,7 +222,8 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
entries[j++] = Integer::New(env->isolate(), ents[i].type);
}

return Array::New(env->isolate(), entries.out(), j);
CHECK_EQ(j, num * 2);
return entries.ToArray();
}

static void AfterDirRead(uv_fs_t* req) {
Expand Down
7 changes: 5 additions & 2 deletions src/node_env_var.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); });
CHECK_EQ(uv_os_environ(&items, &count), 0);

MaybeStackBuffer<Local<Value>, 256> env_v(count);
MaybeStackBuffer<Value, 256> env_v(isolate, count);
int env_v_index = 0;
for (int i = 0; i < count; i++) {
#ifdef _WIN32
Expand All@@ -216,7 +216,10 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
env_v[env_v_index++] = str;
}

return Array::New(isolate, env_v.out(), env_v_index);
// We're possibly not filling the entire buffer.
CHECK_LE(env_v_index, count);
env_v.SetLength(env_v_index);
return env_v.ToArray();
}

std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const {
Expand Down
17 changes: 9 additions & 8 deletions src/node_http2.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1609,8 +1609,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
// this way for performance reasons (it's faster to generate and pass an
// array than it is to generate and pass the object).

MaybeStackBuffer<Local<Value>, 64> headers_v(stream->headers_count() * 2);
MaybeStackBuffer<Local<Value>, 32> sensitive_v(stream->headers_count());
MaybeStackBuffer<Value, 64> headers_v(isolate, stream->headers_count() * 2);
MaybeStackBuffer<Value, 32> sensitive_v(isolate, stream->headers_count());
size_t sensitive_count = 0;

stream->TransferHeaders([&](const Http2Header& header, size_t i) {
Expand All@@ -1627,13 +1627,14 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
stream->retained_headers_length_ += stream->current_headers_length_;
stream->current_headers_length_ = 0;

sensitive_v.SetLength(sensitive_count);
Local<Value> args[] = {
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
Array::New(isolate, headers_v.out(), headers_v.length()),
Array::New(isolate, sensitive_v.out(), sensitive_count),
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
headers_v.ToArray(),
sensitive_v.ToArray(),
};
MakeCallback(env()->http2session_on_headers_function(),
arraysize(args), args);
Expand Down
4 changes: 2 additions & 2 deletions src/node_messaging.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1093,7 +1093,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
"MessagePort.postMessage");
}

TransferList transfer_list;
TransferList transfer_list(env->isolate());
if (!GetTransferList(env, context, args[1], &transfer_list)) {
return;
}
Expand DownExpand Up@@ -1607,7 +1607,7 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) {

Local<Value> value = args[0];

TransferList transfer_list;
TransferList transfer_list(isolate);
Local<Object> options = args[1].As<Object>();
Local<Value> transfer_list_v;
if (!options->Get(context, env->transfer_string())
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ namespace worker {
class MessagePortData;
class MessagePort;

typedef MaybeStackBuffer<v8::Local<v8::Value>, 8> TransferList;
typedef MaybeStackBuffer<v8::Value, 8> TransferList;

// Used to represent the in-flight structure of an object that is being
// transferred or cloned using postMessage().
Expand Down
10 changes: 5 additions & 5 deletions src/node_v8.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -745,17 +745,17 @@ void Initialize(Local<Object> target,
// Heap space names are extracted once and exposed to JavaScript to
// avoid excessive creation of heap space name Strings.
HeapSpaceStatistics s;
MaybeStackBuffer<Local<Value>, 16> heap_spaces(number_of_heap_spaces);
MaybeStackBuffer<Value, 16> heap_spaces(env->isolate(),
number_of_heap_spaces);
for (size_t i = 0; i < number_of_heap_spaces; i++) {
env->isolate()->GetHeapSpaceStatistics(&s, i);
heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name())
.ToLocalChecked();
}
target
->Set(
context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
Array::New(env->isolate(), heap_spaces.out(), number_of_heap_spaces))
->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces.ToArray())
.Check();

SetMethod(context,
Expand Down
5 changes: 2 additions & 3 deletions src/spawn_sync.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -767,7 +767,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
CHECK(!stdio_pipes_.empty());

EscapableHandleScope scope(env()->isolate());
MaybeStackBuffer<Local<Value>, 8> js_output(stdio_pipes_.size());
MaybeStackBuffer<Value, 8> js_output(env()->isolate(), stdio_pipes_.size());

for (uint32_t i = 0; i < stdio_pipes_.size(); i++) {
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
Expand All@@ -781,8 +781,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
}
}

return scope.Escape(
Array::New(env()->isolate(), js_output.out(), js_output.length()));
return scope.Escape(js_output.ToArray());
}

Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Expand Down
40 changes: 33 additions & 7 deletions src/util-inl.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,14 +394,13 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T>
Expand DownExpand Up@@ -430,16 +429,15 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
auto it = vec.begin();
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, *it, isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
std::advance(it, 1);
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T, typename U>
Expand DownExpand Up@@ -519,7 +517,14 @@ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
}

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: SlicedArguments(args.GetIsolate(), args, start) {}

SlicedArguments::SlicedArguments(
v8::Isolate* isolate,
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start)
: MaybeStackBuffer<v8::Value>(isolate) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
Expand All@@ -545,6 +550,27 @@ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
length_ = storage;
}

template <V8Type T, size_t kStackStorageSize>
void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
if (!local_vector_.has_value()) {
local_vector_.emplace(isolate_, storage);
// Copy existing stack data into the LocalVector.
for (size_t i = 0; i < length_; i++) {
(*local_vector_)[i] = buf_st_[i];
}
} else {
local_vector_->resize(storage);
}
buf_ = local_vector_->data();
capacity_ = storage;
}

length_ = storage;
}

template <typename T, size_t S>
requires(sizeof(T) == 1)
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/api/callback.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,

Local<Context> context = env->context();
if (use_async_hooks_trampoline) {
MaybeStackBuffer<Local<Value>, 16> args(3 + argc);
MaybeStackBuffer<Value, 16> args(env->isolate(), 3 + argc);
args[0] = Number::New(env->isolate(), asyncContext.async_id);
args[1] = resource;
args[2] = callback;
Expand Down
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,12 +187,12 @@ Local<Array> AddrTTLToArray(
Environment* env,
const T* addrttls,
size_t naddrttls) {
MaybeStackBuffer<Local<Value>, 8> ttls(naddrttls);
MaybeStackBuffer<Value, 8> ttls(env->isolate(), naddrttls);
for (size_t i = 0; i < naddrttls; i++) {
ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl);
}

return Array::New(env->isolate(), ttls.out(), naddrttls);
return ttls.ToArray();
}

// Parse the CSV produced by ares_get_servers_csv() back into (ip, port)
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/crypto_tls.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,6 @@ using ncrypto::MarkPopErrorOnReturn;
using ncrypto::SSLPointer;
using ncrypto::SSLSessionPointer;
using ncrypto::X509Pointer;
using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
Expand DownExpand Up@@ -1956,7 +1955,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
SSL* ssl = w->ssl_.get();
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
nullptr);
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
MaybeStackBuffer<Value, 16> ret_arr(env->isolate(), nsig);

for (int i = 0; i < nsig; i++) {
int hash_nid;
Expand DownExpand Up@@ -2023,8 +2022,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
ret_arr[i] = OneByteString(env->isolate(), sig_with_md);
}

args.GetReturnValue().Set(
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
args.GetReturnValue().Set(ret_arr.ToArray());
}

void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
Expand Down
8 changes: 2 additions & 6 deletions src/js_stream.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ namespace node {

using errors::TryCatchScope;

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -119,17 +118,14 @@ int JSStream::DoWrite(WriteWrap* w,

int value_int = UV_EPROTO;

MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
MaybeStackBuffer<Value, 16> bufs_arr(env()->isolate(), count);
for (size_t i = 0; i < count; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
return value_int;
}
}

Local<Value> argv[] = {
w->object(),
Array::New(env()->isolate(), bufs_arr.out(), count)
};
Local<Value> argv[] = {w->object(), bufs_arr.ToArray()};

TryCatchScope try_catch(env());
Local<Value> value;
Expand Down
9 changes: 4 additions & 5 deletions src/js_udp_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@
namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -98,7 +97,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
int64_t value_int = JS_EXCEPTION_PENDING;
size_t total_len = 0;

MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
MaybeStackBuffer<Value, 16> buffers(env()->isolate(), nbufs);
for (size_t i = 0; i < nbufs; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
return value_int;
Expand All@@ -110,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int;

Local<Value> args[] = {
listener()->CreateSendWrap(total_len)->object(),
Array::New(env()->isolate(), buffers.out(), nbufs),
address,
listener()->CreateSendWrap(total_len)->object(),
buffers.ToArray(),
address,
};

if (!MakeCallback(env()->onwrite_string(), arraysize(args), args)
Expand Down
7 changes: 7 additions & 0 deletions src/node_concepts.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <v8.h>
#include <concepts>
#include <limits>
#include <type_traits>
Expand DownExpand Up@@ -32,6 +33,12 @@ concept StandardCharType =
template <typename T>
concept IsCallable = std::is_function<T>::value || requires { &T::operator(); };

// Types that can reside on V8's managed heap (v8::Value, v8::Object, etc.).
// Used to select the MaybeStackBuffer specialization that holds handles in a
// v8::LocalVector instead of malloc'd memory.
template <typename T>
concept V8Type = std::is_base_of_v<v8::Data, T>;

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
uv_dirent_t* ents,
int num,
enum encoding encoding) {
MaybeStackBuffer<Local<Value>, 64> entries(num * 2);
MaybeStackBuffer<Value, 64> entries(env->isolate(), num * 2);

// Return an array of all read filenames.
int j = 0;
Expand All@@ -222,7 +222,8 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
entries[j++] = Integer::New(env->isolate(), ents[i].type);
}

return Array::New(env->isolate(), entries.out(), j);
CHECK_EQ(j, num * 2);
return entries.ToArray();
}

static void AfterDirRead(uv_fs_t* req) {
Expand Down
7 changes: 5 additions & 2 deletions src/node_env_var.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); });
CHECK_EQ(uv_os_environ(&items, &count), 0);

MaybeStackBuffer<Local<Value>, 256> env_v(count);
MaybeStackBuffer<Value, 256> env_v(isolate, count);
int env_v_index = 0;
for (int i = 0; i < count; i++) {
#ifdef _WIN32
Expand All@@ -216,7 +216,10 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
env_v[env_v_index++] = str;
}

return Array::New(isolate, env_v.out(), env_v_index);
// We're possibly not filling the entire buffer.
CHECK_LE(env_v_index, count);
env_v.SetLength(env_v_index);
return env_v.ToArray();
}

std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const {
Expand Down
17 changes: 9 additions & 8 deletions src/node_http2.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1609,8 +1609,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
// this way for performance reasons (it's faster to generate and pass an
// array than it is to generate and pass the object).

MaybeStackBuffer<Local<Value>, 64> headers_v(stream->headers_count() * 2);
MaybeStackBuffer<Local<Value>, 32> sensitive_v(stream->headers_count());
MaybeStackBuffer<Value, 64> headers_v(isolate, stream->headers_count() * 2);
MaybeStackBuffer<Value, 32> sensitive_v(isolate, stream->headers_count());
size_t sensitive_count = 0;

stream->TransferHeaders([&](const Http2Header& header, size_t i) {
Expand All@@ -1627,13 +1627,14 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
stream->retained_headers_length_ += stream->current_headers_length_;
stream->current_headers_length_ = 0;

sensitive_v.SetLength(sensitive_count);
Local<Value> args[] = {
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
Array::New(isolate, headers_v.out(), headers_v.length()),
Array::New(isolate, sensitive_v.out(), sensitive_count),
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
headers_v.ToArray(),
sensitive_v.ToArray(),
};
MakeCallback(env()->http2session_on_headers_function(),
arraysize(args), args);
Expand Down
4 changes: 2 additions & 2 deletions src/node_messaging.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1093,7 +1093,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
"MessagePort.postMessage");
}

TransferList transfer_list;
TransferList transfer_list(env->isolate());
if (!GetTransferList(env, context, args[1], &transfer_list)) {
return;
}
Expand DownExpand Up@@ -1607,7 +1607,7 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) {

Local<Value> value = args[0];

TransferList transfer_list;
TransferList transfer_list(isolate);
Local<Object> options = args[1].As<Object>();
Local<Value> transfer_list_v;
if (!options->Get(context, env->transfer_string())
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ namespace worker {
class MessagePortData;
class MessagePort;

typedef MaybeStackBuffer<v8::Local<v8::Value>, 8> TransferList;
typedef MaybeStackBuffer<v8::Value, 8> TransferList;

// Used to represent the in-flight structure of an object that is being
// transferred or cloned using postMessage().
Expand Down
10 changes: 5 additions & 5 deletions src/node_v8.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -745,17 +745,17 @@ void Initialize(Local<Object> target,
// Heap space names are extracted once and exposed to JavaScript to
// avoid excessive creation of heap space name Strings.
HeapSpaceStatistics s;
MaybeStackBuffer<Local<Value>, 16> heap_spaces(number_of_heap_spaces);
MaybeStackBuffer<Value, 16> heap_spaces(env->isolate(),
number_of_heap_spaces);
for (size_t i = 0; i < number_of_heap_spaces; i++) {
env->isolate()->GetHeapSpaceStatistics(&s, i);
heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name())
.ToLocalChecked();
}
target
->Set(
context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
Array::New(env->isolate(), heap_spaces.out(), number_of_heap_spaces))
->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces.ToArray())
.Check();

SetMethod(context,
Expand Down
5 changes: 2 additions & 3 deletions src/spawn_sync.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -767,7 +767,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
CHECK(!stdio_pipes_.empty());

EscapableHandleScope scope(env()->isolate());
MaybeStackBuffer<Local<Value>, 8> js_output(stdio_pipes_.size());
MaybeStackBuffer<Value, 8> js_output(env()->isolate(), stdio_pipes_.size());

for (uint32_t i = 0; i < stdio_pipes_.size(); i++) {
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
Expand All@@ -781,8 +781,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
}
}

return scope.Escape(
Array::New(env()->isolate(), js_output.out(), js_output.length()));
return scope.Escape(js_output.ToArray());
}

Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Expand Down
40 changes: 33 additions & 7 deletions src/util-inl.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,14 +394,13 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T>
Expand DownExpand Up@@ -430,16 +429,15 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
auto it = vec.begin();
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, *it, isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
std::advance(it, 1);
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T, typename U>
Expand DownExpand Up@@ -519,7 +517,14 @@ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
}

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: SlicedArguments(args.GetIsolate(), args, start) {}

SlicedArguments::SlicedArguments(
v8::Isolate* isolate,
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start)
: MaybeStackBuffer<v8::Value>(isolate) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
Expand All@@ -545,6 +550,27 @@ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
length_ = storage;
}

template <V8Type T, size_t kStackStorageSize>
void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
if (!local_vector_.has_value()) {
local_vector_.emplace(isolate_, storage);
// Copy existing stack data into the LocalVector.
for (size_t i = 0; i < length_; i++) {
(*local_vector_)[i] = buf_st_[i];
}
} else {
local_vector_->resize(storage);
}
buf_ = local_vector_->data();
capacity_ = storage;
}

length_ = storage;
}

template <typename T, size_t S>
requires(sizeof(T) == 1)
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/api/callback.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,

Local<Context> context = env->context();
if (use_async_hooks_trampoline) {
MaybeStackBuffer<Local<Value>, 16> args(3 + argc);
MaybeStackBuffer<Value, 16> args(env->isolate(), 3 + argc);
args[0] = Number::New(env->isolate(), asyncContext.async_id);
args[1] = resource;
args[2] = callback;
Expand Down
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,12 +187,12 @@ Local<Array> AddrTTLToArray(
Environment* env,
const T* addrttls,
size_t naddrttls) {
MaybeStackBuffer<Local<Value>, 8> ttls(naddrttls);
MaybeStackBuffer<Value, 8> ttls(env->isolate(), naddrttls);
for (size_t i = 0; i < naddrttls; i++) {
ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl);
}

return Array::New(env->isolate(), ttls.out(), naddrttls);
return ttls.ToArray();
}

// Parse the CSV produced by ares_get_servers_csv() back into (ip, port)
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/crypto_tls.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,6 @@ using ncrypto::MarkPopErrorOnReturn;
using ncrypto::SSLPointer;
using ncrypto::SSLSessionPointer;
using ncrypto::X509Pointer;
using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
Expand DownExpand Up@@ -1956,7 +1955,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
SSL* ssl = w->ssl_.get();
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
nullptr);
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
MaybeStackBuffer<Value, 16> ret_arr(env->isolate(), nsig);

for (int i = 0; i < nsig; i++) {
int hash_nid;
Expand DownExpand Up@@ -2023,8 +2022,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
ret_arr[i] = OneByteString(env->isolate(), sig_with_md);
}

args.GetReturnValue().Set(
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
args.GetReturnValue().Set(ret_arr.ToArray());
}

void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
Expand Down
8 changes: 2 additions & 6 deletions src/js_stream.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ namespace node {

using errors::TryCatchScope;

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -119,17 +118,14 @@ int JSStream::DoWrite(WriteWrap* w,

int value_int = UV_EPROTO;

MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
MaybeStackBuffer<Value, 16> bufs_arr(env()->isolate(), count);
for (size_t i = 0; i < count; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
return value_int;
}
}

Local<Value> argv[] = {
w->object(),
Array::New(env()->isolate(), bufs_arr.out(), count)
};
Local<Value> argv[] = {w->object(), bufs_arr.ToArray()};

TryCatchScope try_catch(env());
Local<Value> value;
Expand Down
9 changes: 4 additions & 5 deletions src/js_udp_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@
namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -98,7 +97,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
int64_t value_int = JS_EXCEPTION_PENDING;
size_t total_len = 0;

MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
MaybeStackBuffer<Value, 16> buffers(env()->isolate(), nbufs);
for (size_t i = 0; i < nbufs; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
return value_int;
Expand All@@ -110,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int;

Local<Value> args[] = {
listener()->CreateSendWrap(total_len)->object(),
Array::New(env()->isolate(), buffers.out(), nbufs),
address,
listener()->CreateSendWrap(total_len)->object(),
buffers.ToArray(),
address,
};

if (!MakeCallback(env()->onwrite_string(), arraysize(args), args)
Expand Down
7 changes: 7 additions & 0 deletions src/node_concepts.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <v8.h>
#include <concepts>
#include <limits>
#include <type_traits>
Expand DownExpand Up@@ -32,6 +33,12 @@ concept StandardCharType =
template <typename T>
concept IsCallable = std::is_function<T>::value || requires { &T::operator(); };

// Types that can reside on V8's managed heap (v8::Value, v8::Object, etc.).
// Used to select the MaybeStackBuffer specialization that holds handles in a
// v8::LocalVector instead of malloc'd memory.
template <typename T>
concept V8Type = std::is_base_of_v<v8::Data, T>;

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
uv_dirent_t* ents,
int num,
enum encoding encoding) {
MaybeStackBuffer<Local<Value>, 64> entries(num * 2);
MaybeStackBuffer<Value, 64> entries(env->isolate(), num * 2);

// Return an array of all read filenames.
int j = 0;
Expand All@@ -222,7 +222,8 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
entries[j++] = Integer::New(env->isolate(), ents[i].type);
}

return Array::New(env->isolate(), entries.out(), j);
CHECK_EQ(j, num * 2);
return entries.ToArray();
}

static void AfterDirRead(uv_fs_t* req) {
Expand Down
7 changes: 5 additions & 2 deletions src/node_env_var.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); });
CHECK_EQ(uv_os_environ(&items, &count), 0);

MaybeStackBuffer<Local<Value>, 256> env_v(count);
MaybeStackBuffer<Value, 256> env_v(isolate, count);
int env_v_index = 0;
for (int i = 0; i < count; i++) {
#ifdef _WIN32
Expand All@@ -216,7 +216,10 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
env_v[env_v_index++] = str;
}

return Array::New(isolate, env_v.out(), env_v_index);
// We're possibly not filling the entire buffer.
CHECK_LE(env_v_index, count);
env_v.SetLength(env_v_index);
return env_v.ToArray();
}

std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const {
Expand Down
17 changes: 9 additions & 8 deletions src/node_http2.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1609,8 +1609,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
// this way for performance reasons (it's faster to generate and pass an
// array than it is to generate and pass the object).

MaybeStackBuffer<Local<Value>, 64> headers_v(stream->headers_count() * 2);
MaybeStackBuffer<Local<Value>, 32> sensitive_v(stream->headers_count());
MaybeStackBuffer<Value, 64> headers_v(isolate, stream->headers_count() * 2);
MaybeStackBuffer<Value, 32> sensitive_v(isolate, stream->headers_count());
size_t sensitive_count = 0;

stream->TransferHeaders([&](const Http2Header& header, size_t i) {
Expand All@@ -1627,13 +1627,14 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
stream->retained_headers_length_ += stream->current_headers_length_;
stream->current_headers_length_ = 0;

sensitive_v.SetLength(sensitive_count);
Local<Value> args[] = {
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
Array::New(isolate, headers_v.out(), headers_v.length()),
Array::New(isolate, sensitive_v.out(), sensitive_count),
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
headers_v.ToArray(),
sensitive_v.ToArray(),
};
MakeCallback(env()->http2session_on_headers_function(),
arraysize(args), args);
Expand Down
4 changes: 2 additions & 2 deletions src/node_messaging.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1093,7 +1093,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
"MessagePort.postMessage");
}

TransferList transfer_list;
TransferList transfer_list(env->isolate());
if (!GetTransferList(env, context, args[1], &transfer_list)) {
return;
}
Expand DownExpand Up@@ -1607,7 +1607,7 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) {

Local<Value> value = args[0];

TransferList transfer_list;
TransferList transfer_list(isolate);
Local<Object> options = args[1].As<Object>();
Local<Value> transfer_list_v;
if (!options->Get(context, env->transfer_string())
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ namespace worker {
class MessagePortData;
class MessagePort;

typedef MaybeStackBuffer<v8::Local<v8::Value>, 8> TransferList;
typedef MaybeStackBuffer<v8::Value, 8> TransferList;

// Used to represent the in-flight structure of an object that is being
// transferred or cloned using postMessage().
Expand Down
10 changes: 5 additions & 5 deletions src/node_v8.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -745,17 +745,17 @@ void Initialize(Local<Object> target,
// Heap space names are extracted once and exposed to JavaScript to
// avoid excessive creation of heap space name Strings.
HeapSpaceStatistics s;
MaybeStackBuffer<Local<Value>, 16> heap_spaces(number_of_heap_spaces);
MaybeStackBuffer<Value, 16> heap_spaces(env->isolate(),
number_of_heap_spaces);
for (size_t i = 0; i < number_of_heap_spaces; i++) {
env->isolate()->GetHeapSpaceStatistics(&s, i);
heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name())
.ToLocalChecked();
}
target
->Set(
context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
Array::New(env->isolate(), heap_spaces.out(), number_of_heap_spaces))
->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces.ToArray())
.Check();

SetMethod(context,
Expand Down
5 changes: 2 additions & 3 deletions src/spawn_sync.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -767,7 +767,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
CHECK(!stdio_pipes_.empty());

EscapableHandleScope scope(env()->isolate());
MaybeStackBuffer<Local<Value>, 8> js_output(stdio_pipes_.size());
MaybeStackBuffer<Value, 8> js_output(env()->isolate(), stdio_pipes_.size());

for (uint32_t i = 0; i < stdio_pipes_.size(); i++) {
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
Expand All@@ -781,8 +781,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
}
}

return scope.Escape(
Array::New(env()->isolate(), js_output.out(), js_output.length()));
return scope.Escape(js_output.ToArray());
}

Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Expand Down
40 changes: 33 additions & 7 deletions src/util-inl.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,14 +394,13 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T>
Expand DownExpand Up@@ -430,16 +429,15 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
auto it = vec.begin();
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, *it, isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
std::advance(it, 1);
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T, typename U>
Expand DownExpand Up@@ -519,7 +517,14 @@ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
}

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: SlicedArguments(args.GetIsolate(), args, start) {}

SlicedArguments::SlicedArguments(
v8::Isolate* isolate,
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start)
: MaybeStackBuffer<v8::Value>(isolate) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
Expand All@@ -545,6 +550,27 @@ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
length_ = storage;
}

template <V8Type T, size_t kStackStorageSize>
void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
if (!local_vector_.has_value()) {
local_vector_.emplace(isolate_, storage);
// Copy existing stack data into the LocalVector.
for (size_t i = 0; i < length_; i++) {
(*local_vector_)[i] = buf_st_[i];
}
} else {
local_vector_->resize(storage);
}
buf_ = local_vector_->data();
capacity_ = storage;
}

length_ = storage;
}

template <typename T, size_t S>
requires(sizeof(T) == 1)
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/api/callback.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,

Local<Context> context = env->context();
if (use_async_hooks_trampoline) {
MaybeStackBuffer<Local<Value>, 16> args(3 + argc);
MaybeStackBuffer<Value, 16> args(env->isolate(), 3 + argc);
args[0] = Number::New(env->isolate(), asyncContext.async_id);
args[1] = resource;
args[2] = callback;
Expand Down
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,12 +187,12 @@ Local<Array> AddrTTLToArray(
Environment* env,
const T* addrttls,
size_t naddrttls) {
MaybeStackBuffer<Local<Value>, 8> ttls(naddrttls);
MaybeStackBuffer<Value, 8> ttls(env->isolate(), naddrttls);
for (size_t i = 0; i < naddrttls; i++) {
ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl);
}

return Array::New(env->isolate(), ttls.out(), naddrttls);
return ttls.ToArray();
}

// Parse the CSV produced by ares_get_servers_csv() back into (ip, port)
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/crypto_tls.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,6 @@ using ncrypto::MarkPopErrorOnReturn;
using ncrypto::SSLPointer;
using ncrypto::SSLSessionPointer;
using ncrypto::X509Pointer;
using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
Expand DownExpand Up@@ -1956,7 +1955,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
SSL* ssl = w->ssl_.get();
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
nullptr);
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
MaybeStackBuffer<Value, 16> ret_arr(env->isolate(), nsig);

for (int i = 0; i < nsig; i++) {
int hash_nid;
Expand DownExpand Up@@ -2023,8 +2022,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
ret_arr[i] = OneByteString(env->isolate(), sig_with_md);
}

args.GetReturnValue().Set(
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
args.GetReturnValue().Set(ret_arr.ToArray());
}

void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
Expand Down
8 changes: 2 additions & 6 deletions src/js_stream.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ namespace node {

using errors::TryCatchScope;

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -119,17 +118,14 @@ int JSStream::DoWrite(WriteWrap* w,

int value_int = UV_EPROTO;

MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
MaybeStackBuffer<Value, 16> bufs_arr(env()->isolate(), count);
for (size_t i = 0; i < count; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
return value_int;
}
}

Local<Value> argv[] = {
w->object(),
Array::New(env()->isolate(), bufs_arr.out(), count)
};
Local<Value> argv[] = {w->object(), bufs_arr.ToArray()};

TryCatchScope try_catch(env());
Local<Value> value;
Expand Down
9 changes: 4 additions & 5 deletions src/js_udp_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@
namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -98,7 +97,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
int64_t value_int = JS_EXCEPTION_PENDING;
size_t total_len = 0;

MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
MaybeStackBuffer<Value, 16> buffers(env()->isolate(), nbufs);
for (size_t i = 0; i < nbufs; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
return value_int;
Expand All@@ -110,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int;

Local<Value> args[] = {
listener()->CreateSendWrap(total_len)->object(),
Array::New(env()->isolate(), buffers.out(), nbufs),
address,
listener()->CreateSendWrap(total_len)->object(),
buffers.ToArray(),
address,
};

if (!MakeCallback(env()->onwrite_string(), arraysize(args), args)
Expand Down
7 changes: 7 additions & 0 deletions src/node_concepts.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <v8.h>
#include <concepts>
#include <limits>
#include <type_traits>
Expand DownExpand Up@@ -32,6 +33,12 @@ concept StandardCharType =
template <typename T>
concept IsCallable = std::is_function<T>::value || requires { &T::operator(); };

// Types that can reside on V8's managed heap (v8::Value, v8::Object, etc.).
// Used to select the MaybeStackBuffer specialization that holds handles in a
// v8::LocalVector instead of malloc'd memory.
template <typename T>
concept V8Type = std::is_base_of_v<v8::Data, T>;

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
uv_dirent_t* ents,
int num,
enum encoding encoding) {
MaybeStackBuffer<Local<Value>, 64> entries(num * 2);
MaybeStackBuffer<Value, 64> entries(env->isolate(), num * 2);

// Return an array of all read filenames.
int j = 0;
Expand All@@ -222,7 +222,8 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
entries[j++] = Integer::New(env->isolate(), ents[i].type);
}

return Array::New(env->isolate(), entries.out(), j);
CHECK_EQ(j, num * 2);
return entries.ToArray();
}

static void AfterDirRead(uv_fs_t* req) {
Expand Down
7 changes: 5 additions & 2 deletions src/node_env_var.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); });
CHECK_EQ(uv_os_environ(&items, &count), 0);

MaybeStackBuffer<Local<Value>, 256> env_v(count);
MaybeStackBuffer<Value, 256> env_v(isolate, count);
int env_v_index = 0;
for (int i = 0; i < count; i++) {
#ifdef _WIN32
Expand All@@ -216,7 +216,10 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
env_v[env_v_index++] = str;
}

return Array::New(isolate, env_v.out(), env_v_index);
// We're possibly not filling the entire buffer.
CHECK_LE(env_v_index, count);
env_v.SetLength(env_v_index);
return env_v.ToArray();
}

std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const {
Expand Down
17 changes: 9 additions & 8 deletions src/node_http2.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1609,8 +1609,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
// this way for performance reasons (it's faster to generate and pass an
// array than it is to generate and pass the object).

MaybeStackBuffer<Local<Value>, 64> headers_v(stream->headers_count() * 2);
MaybeStackBuffer<Local<Value>, 32> sensitive_v(stream->headers_count());
MaybeStackBuffer<Value, 64> headers_v(isolate, stream->headers_count() * 2);
MaybeStackBuffer<Value, 32> sensitive_v(isolate, stream->headers_count());
size_t sensitive_count = 0;

stream->TransferHeaders([&](const Http2Header& header, size_t i) {
Expand All@@ -1627,13 +1627,14 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
stream->retained_headers_length_ += stream->current_headers_length_;
stream->current_headers_length_ = 0;

sensitive_v.SetLength(sensitive_count);
Local<Value> args[] = {
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
Array::New(isolate, headers_v.out(), headers_v.length()),
Array::New(isolate, sensitive_v.out(), sensitive_count),
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
headers_v.ToArray(),
sensitive_v.ToArray(),
};
MakeCallback(env()->http2session_on_headers_function(),
arraysize(args), args);
Expand Down
4 changes: 2 additions & 2 deletions src/node_messaging.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1093,7 +1093,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
"MessagePort.postMessage");
}

TransferList transfer_list;
TransferList transfer_list(env->isolate());
if (!GetTransferList(env, context, args[1], &transfer_list)) {
return;
}
Expand DownExpand Up@@ -1607,7 +1607,7 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) {

Local<Value> value = args[0];

TransferList transfer_list;
TransferList transfer_list(isolate);
Local<Object> options = args[1].As<Object>();
Local<Value> transfer_list_v;
if (!options->Get(context, env->transfer_string())
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ namespace worker {
class MessagePortData;
class MessagePort;

typedef MaybeStackBuffer<v8::Local<v8::Value>, 8> TransferList;
typedef MaybeStackBuffer<v8::Value, 8> TransferList;

// Used to represent the in-flight structure of an object that is being
// transferred or cloned using postMessage().
Expand Down
10 changes: 5 additions & 5 deletions src/node_v8.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -745,17 +745,17 @@ void Initialize(Local<Object> target,
// Heap space names are extracted once and exposed to JavaScript to
// avoid excessive creation of heap space name Strings.
HeapSpaceStatistics s;
MaybeStackBuffer<Local<Value>, 16> heap_spaces(number_of_heap_spaces);
MaybeStackBuffer<Value, 16> heap_spaces(env->isolate(),
number_of_heap_spaces);
for (size_t i = 0; i < number_of_heap_spaces; i++) {
env->isolate()->GetHeapSpaceStatistics(&s, i);
heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name())
.ToLocalChecked();
}
target
->Set(
context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
Array::New(env->isolate(), heap_spaces.out(), number_of_heap_spaces))
->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces.ToArray())
.Check();

SetMethod(context,
Expand Down
5 changes: 2 additions & 3 deletions src/spawn_sync.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -767,7 +767,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
CHECK(!stdio_pipes_.empty());

EscapableHandleScope scope(env()->isolate());
MaybeStackBuffer<Local<Value>, 8> js_output(stdio_pipes_.size());
MaybeStackBuffer<Value, 8> js_output(env()->isolate(), stdio_pipes_.size());

for (uint32_t i = 0; i < stdio_pipes_.size(); i++) {
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
Expand All@@ -781,8 +781,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
}
}

return scope.Escape(
Array::New(env()->isolate(), js_output.out(), js_output.length()));
return scope.Escape(js_output.ToArray());
}

Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Expand Down
40 changes: 33 additions & 7 deletions src/util-inl.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,14 +394,13 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T>
Expand DownExpand Up@@ -430,16 +429,15 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
auto it = vec.begin();
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, *it, isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
std::advance(it, 1);
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T, typename U>
Expand DownExpand Up@@ -519,7 +517,14 @@ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
}

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: SlicedArguments(args.GetIsolate(), args, start) {}

SlicedArguments::SlicedArguments(
v8::Isolate* isolate,
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start)
: MaybeStackBuffer<v8::Value>(isolate) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
Expand All@@ -545,6 +550,27 @@ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
length_ = storage;
}

template <V8Type T, size_t kStackStorageSize>
void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
if (!local_vector_.has_value()) {
local_vector_.emplace(isolate_, storage);
// Copy existing stack data into the LocalVector.
for (size_t i = 0; i < length_; i++) {
(*local_vector_)[i] = buf_st_[i];
}
} else {
local_vector_->resize(storage);
}
buf_ = local_vector_->data();
capacity_ = storage;
}

length_ = storage;
}

template <typename T, size_t S>
requires(sizeof(T) == 1)
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/api/callback.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,

Local<Context> context = env->context();
if (use_async_hooks_trampoline) {
MaybeStackBuffer<Local<Value>, 16> args(3 + argc);
MaybeStackBuffer<Value, 16> args(env->isolate(), 3 + argc);
args[0] = Number::New(env->isolate(), asyncContext.async_id);
args[1] = resource;
args[2] = callback;
Expand Down
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,12 +187,12 @@ Local<Array> AddrTTLToArray(
Environment* env,
const T* addrttls,
size_t naddrttls) {
MaybeStackBuffer<Local<Value>, 8> ttls(naddrttls);
MaybeStackBuffer<Value, 8> ttls(env->isolate(), naddrttls);
for (size_t i = 0; i < naddrttls; i++) {
ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl);
}

return Array::New(env->isolate(), ttls.out(), naddrttls);
return ttls.ToArray();
}

// Parse the CSV produced by ares_get_servers_csv() back into (ip, port)
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/crypto_tls.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,6 @@ using ncrypto::MarkPopErrorOnReturn;
using ncrypto::SSLPointer;
using ncrypto::SSLSessionPointer;
using ncrypto::X509Pointer;
using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
Expand DownExpand Up@@ -1956,7 +1955,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
SSL* ssl = w->ssl_.get();
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
nullptr);
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
MaybeStackBuffer<Value, 16> ret_arr(env->isolate(), nsig);

for (int i = 0; i < nsig; i++) {
int hash_nid;
Expand DownExpand Up@@ -2023,8 +2022,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
ret_arr[i] = OneByteString(env->isolate(), sig_with_md);
}

args.GetReturnValue().Set(
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
args.GetReturnValue().Set(ret_arr.ToArray());
}

void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
Expand Down
8 changes: 2 additions & 6 deletions src/js_stream.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ namespace node {

using errors::TryCatchScope;

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -119,17 +118,14 @@ int JSStream::DoWrite(WriteWrap* w,

int value_int = UV_EPROTO;

MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
MaybeStackBuffer<Value, 16> bufs_arr(env()->isolate(), count);
for (size_t i = 0; i < count; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
return value_int;
}
}

Local<Value> argv[] = {
w->object(),
Array::New(env()->isolate(), bufs_arr.out(), count)
};
Local<Value> argv[] = {w->object(), bufs_arr.ToArray()};

TryCatchScope try_catch(env());
Local<Value> value;
Expand Down
9 changes: 4 additions & 5 deletions src/js_udp_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@
namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -98,7 +97,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
int64_t value_int = JS_EXCEPTION_PENDING;
size_t total_len = 0;

MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
MaybeStackBuffer<Value, 16> buffers(env()->isolate(), nbufs);
for (size_t i = 0; i < nbufs; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
return value_int;
Expand All@@ -110,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int;

Local<Value> args[] = {
listener()->CreateSendWrap(total_len)->object(),
Array::New(env()->isolate(), buffers.out(), nbufs),
address,
listener()->CreateSendWrap(total_len)->object(),
buffers.ToArray(),
address,
};

if (!MakeCallback(env()->onwrite_string(), arraysize(args), args)
Expand Down
7 changes: 7 additions & 0 deletions src/node_concepts.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <v8.h>
#include <concepts>
#include <limits>
#include <type_traits>
Expand DownExpand Up@@ -32,6 +33,12 @@ concept StandardCharType =
template <typename T>
concept IsCallable = std::is_function<T>::value || requires { &T::operator(); };

// Types that can reside on V8's managed heap (v8::Value, v8::Object, etc.).
// Used to select the MaybeStackBuffer specialization that holds handles in a
// v8::LocalVector instead of malloc'd memory.
template <typename T>
concept V8Type = std::is_base_of_v<v8::Data, T>;

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
uv_dirent_t* ents,
int num,
enum encoding encoding) {
MaybeStackBuffer<Local<Value>, 64> entries(num * 2);
MaybeStackBuffer<Value, 64> entries(env->isolate(), num * 2);

// Return an array of all read filenames.
int j = 0;
Expand All@@ -222,7 +222,8 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
entries[j++] = Integer::New(env->isolate(), ents[i].type);
}

return Array::New(env->isolate(), entries.out(), j);
CHECK_EQ(j, num * 2);
return entries.ToArray();
}

static void AfterDirRead(uv_fs_t* req) {
Expand Down
7 changes: 5 additions & 2 deletions src/node_env_var.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); });
CHECK_EQ(uv_os_environ(&items, &count), 0);

MaybeStackBuffer<Local<Value>, 256> env_v(count);
MaybeStackBuffer<Value, 256> env_v(isolate, count);
int env_v_index = 0;
for (int i = 0; i < count; i++) {
#ifdef _WIN32
Expand All@@ -216,7 +216,10 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
env_v[env_v_index++] = str;
}

return Array::New(isolate, env_v.out(), env_v_index);
// We're possibly not filling the entire buffer.
CHECK_LE(env_v_index, count);
env_v.SetLength(env_v_index);
return env_v.ToArray();
}

std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const {
Expand Down
17 changes: 9 additions & 8 deletions src/node_http2.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1609,8 +1609,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
// this way for performance reasons (it's faster to generate and pass an
// array than it is to generate and pass the object).

MaybeStackBuffer<Local<Value>, 64> headers_v(stream->headers_count() * 2);
MaybeStackBuffer<Local<Value>, 32> sensitive_v(stream->headers_count());
MaybeStackBuffer<Value, 64> headers_v(isolate, stream->headers_count() * 2);
MaybeStackBuffer<Value, 32> sensitive_v(isolate, stream->headers_count());
size_t sensitive_count = 0;

stream->TransferHeaders([&](const Http2Header& header, size_t i) {
Expand All@@ -1627,13 +1627,14 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
stream->retained_headers_length_ += stream->current_headers_length_;
stream->current_headers_length_ = 0;

sensitive_v.SetLength(sensitive_count);
Local<Value> args[] = {
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
Array::New(isolate, headers_v.out(), headers_v.length()),
Array::New(isolate, sensitive_v.out(), sensitive_count),
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
headers_v.ToArray(),
sensitive_v.ToArray(),
};
MakeCallback(env()->http2session_on_headers_function(),
arraysize(args), args);
Expand Down
4 changes: 2 additions & 2 deletions src/node_messaging.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1093,7 +1093,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
"MessagePort.postMessage");
}

TransferList transfer_list;
TransferList transfer_list(env->isolate());
if (!GetTransferList(env, context, args[1], &transfer_list)) {
return;
}
Expand DownExpand Up@@ -1607,7 +1607,7 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) {

Local<Value> value = args[0];

TransferList transfer_list;
TransferList transfer_list(isolate);
Local<Object> options = args[1].As<Object>();
Local<Value> transfer_list_v;
if (!options->Get(context, env->transfer_string())
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ namespace worker {
class MessagePortData;
class MessagePort;

typedef MaybeStackBuffer<v8::Local<v8::Value>, 8> TransferList;
typedef MaybeStackBuffer<v8::Value, 8> TransferList;

// Used to represent the in-flight structure of an object that is being
// transferred or cloned using postMessage().
Expand Down
10 changes: 5 additions & 5 deletions src/node_v8.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -745,17 +745,17 @@ void Initialize(Local<Object> target,
// Heap space names are extracted once and exposed to JavaScript to
// avoid excessive creation of heap space name Strings.
HeapSpaceStatistics s;
MaybeStackBuffer<Local<Value>, 16> heap_spaces(number_of_heap_spaces);
MaybeStackBuffer<Value, 16> heap_spaces(env->isolate(),
number_of_heap_spaces);
for (size_t i = 0; i < number_of_heap_spaces; i++) {
env->isolate()->GetHeapSpaceStatistics(&s, i);
heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name())
.ToLocalChecked();
}
target
->Set(
context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
Array::New(env->isolate(), heap_spaces.out(), number_of_heap_spaces))
->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces.ToArray())
.Check();

SetMethod(context,
Expand Down
5 changes: 2 additions & 3 deletions src/spawn_sync.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -767,7 +767,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
CHECK(!stdio_pipes_.empty());

EscapableHandleScope scope(env()->isolate());
MaybeStackBuffer<Local<Value>, 8> js_output(stdio_pipes_.size());
MaybeStackBuffer<Value, 8> js_output(env()->isolate(), stdio_pipes_.size());

for (uint32_t i = 0; i < stdio_pipes_.size(); i++) {
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
Expand All@@ -781,8 +781,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
}
}

return scope.Escape(
Array::New(env()->isolate(), js_output.out(), js_output.length()));
return scope.Escape(js_output.ToArray());
}

Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Expand Down
40 changes: 33 additions & 7 deletions src/util-inl.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,14 +394,13 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T>
Expand DownExpand Up@@ -430,16 +429,15 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
auto it = vec.begin();
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, *it, isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
std::advance(it, 1);
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T, typename U>
Expand DownExpand Up@@ -519,7 +517,14 @@ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
}

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: SlicedArguments(args.GetIsolate(), args, start) {}

SlicedArguments::SlicedArguments(
v8::Isolate* isolate,
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start)
: MaybeStackBuffer<v8::Value>(isolate) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
Expand All@@ -545,6 +550,27 @@ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
length_ = storage;
}

template <V8Type T, size_t kStackStorageSize>
void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
if (!local_vector_.has_value()) {
local_vector_.emplace(isolate_, storage);
// Copy existing stack data into the LocalVector.
for (size_t i = 0; i < length_; i++) {
(*local_vector_)[i] = buf_st_[i];
}
} else {
local_vector_->resize(storage);
}
buf_ = local_vector_->data();
capacity_ = storage;
}

length_ = storage;
}

template <typename T, size_t S>
requires(sizeof(T) == 1)
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/api/callback.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,

Local<Context> context = env->context();
if (use_async_hooks_trampoline) {
MaybeStackBuffer<Local<Value>, 16> args(3 + argc);
MaybeStackBuffer<Value, 16> args(env->isolate(), 3 + argc);
args[0] = Number::New(env->isolate(), asyncContext.async_id);
args[1] = resource;
args[2] = callback;
Expand Down
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,12 +187,12 @@ Local<Array> AddrTTLToArray(
Environment* env,
const T* addrttls,
size_t naddrttls) {
MaybeStackBuffer<Local<Value>, 8> ttls(naddrttls);
MaybeStackBuffer<Value, 8> ttls(env->isolate(), naddrttls);
for (size_t i = 0; i < naddrttls; i++) {
ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl);
}

return Array::New(env->isolate(), ttls.out(), naddrttls);
return ttls.ToArray();
}

// Parse the CSV produced by ares_get_servers_csv() back into (ip, port)
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/crypto_tls.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,6 @@ using ncrypto::MarkPopErrorOnReturn;
using ncrypto::SSLPointer;
using ncrypto::SSLSessionPointer;
using ncrypto::X509Pointer;
using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
Expand DownExpand Up@@ -1956,7 +1955,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
SSL* ssl = w->ssl_.get();
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
nullptr);
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
MaybeStackBuffer<Value, 16> ret_arr(env->isolate(), nsig);

for (int i = 0; i < nsig; i++) {
int hash_nid;
Expand DownExpand Up@@ -2023,8 +2022,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
ret_arr[i] = OneByteString(env->isolate(), sig_with_md);
}

args.GetReturnValue().Set(
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
args.GetReturnValue().Set(ret_arr.ToArray());
}

void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
Expand Down
8 changes: 2 additions & 6 deletions src/js_stream.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ namespace node {

using errors::TryCatchScope;

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -119,17 +118,14 @@ int JSStream::DoWrite(WriteWrap* w,

int value_int = UV_EPROTO;

MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
MaybeStackBuffer<Value, 16> bufs_arr(env()->isolate(), count);
for (size_t i = 0; i < count; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
return value_int;
}
}

Local<Value> argv[] = {
w->object(),
Array::New(env()->isolate(), bufs_arr.out(), count)
};
Local<Value> argv[] = {w->object(), bufs_arr.ToArray()};

TryCatchScope try_catch(env());
Local<Value> value;
Expand Down
9 changes: 4 additions & 5 deletions src/js_udp_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@
namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -98,7 +97,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
int64_t value_int = JS_EXCEPTION_PENDING;
size_t total_len = 0;

MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
MaybeStackBuffer<Value, 16> buffers(env()->isolate(), nbufs);
for (size_t i = 0; i < nbufs; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
return value_int;
Expand All@@ -110,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int;

Local<Value> args[] = {
listener()->CreateSendWrap(total_len)->object(),
Array::New(env()->isolate(), buffers.out(), nbufs),
address,
listener()->CreateSendWrap(total_len)->object(),
buffers.ToArray(),
address,
};

if (!MakeCallback(env()->onwrite_string(), arraysize(args), args)
Expand Down
7 changes: 7 additions & 0 deletions src/node_concepts.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <v8.h>
#include <concepts>
#include <limits>
#include <type_traits>
Expand DownExpand Up@@ -32,6 +33,12 @@ concept StandardCharType =
template <typename T>
concept IsCallable = std::is_function<T>::value || requires { &T::operator(); };

// Types that can reside on V8's managed heap (v8::Value, v8::Object, etc.).
// Used to select the MaybeStackBuffer specialization that holds handles in a
// v8::LocalVector instead of malloc'd memory.
template <typename T>
concept V8Type = std::is_base_of_v<v8::Data, T>;

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
uv_dirent_t* ents,
int num,
enum encoding encoding) {
MaybeStackBuffer<Local<Value>, 64> entries(num * 2);
MaybeStackBuffer<Value, 64> entries(env->isolate(), num * 2);

// Return an array of all read filenames.
int j = 0;
Expand All@@ -222,7 +222,8 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
entries[j++] = Integer::New(env->isolate(), ents[i].type);
}

return Array::New(env->isolate(), entries.out(), j);
CHECK_EQ(j, num * 2);
return entries.ToArray();
}

static void AfterDirRead(uv_fs_t* req) {
Expand Down
7 changes: 5 additions & 2 deletions src/node_env_var.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); });
CHECK_EQ(uv_os_environ(&items, &count), 0);

MaybeStackBuffer<Local<Value>, 256> env_v(count);
MaybeStackBuffer<Value, 256> env_v(isolate, count);
int env_v_index = 0;
for (int i = 0; i < count; i++) {
#ifdef _WIN32
Expand All@@ -216,7 +216,10 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
env_v[env_v_index++] = str;
}

return Array::New(isolate, env_v.out(), env_v_index);
// We're possibly not filling the entire buffer.
CHECK_LE(env_v_index, count);
env_v.SetLength(env_v_index);
return env_v.ToArray();
}

std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const {
Expand Down
17 changes: 9 additions & 8 deletions src/node_http2.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1609,8 +1609,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
// this way for performance reasons (it's faster to generate and pass an
// array than it is to generate and pass the object).

MaybeStackBuffer<Local<Value>, 64> headers_v(stream->headers_count() * 2);
MaybeStackBuffer<Local<Value>, 32> sensitive_v(stream->headers_count());
MaybeStackBuffer<Value, 64> headers_v(isolate, stream->headers_count() * 2);
MaybeStackBuffer<Value, 32> sensitive_v(isolate, stream->headers_count());
size_t sensitive_count = 0;

stream->TransferHeaders([&](const Http2Header& header, size_t i) {
Expand All@@ -1627,13 +1627,14 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
stream->retained_headers_length_ += stream->current_headers_length_;
stream->current_headers_length_ = 0;

sensitive_v.SetLength(sensitive_count);
Local<Value> args[] = {
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
Array::New(isolate, headers_v.out(), headers_v.length()),
Array::New(isolate, sensitive_v.out(), sensitive_count),
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
headers_v.ToArray(),
sensitive_v.ToArray(),
};
MakeCallback(env()->http2session_on_headers_function(),
arraysize(args), args);
Expand Down
4 changes: 2 additions & 2 deletions src/node_messaging.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1093,7 +1093,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
"MessagePort.postMessage");
}

TransferList transfer_list;
TransferList transfer_list(env->isolate());
if (!GetTransferList(env, context, args[1], &transfer_list)) {
return;
}
Expand DownExpand Up@@ -1607,7 +1607,7 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) {

Local<Value> value = args[0];

TransferList transfer_list;
TransferList transfer_list(isolate);
Local<Object> options = args[1].As<Object>();
Local<Value> transfer_list_v;
if (!options->Get(context, env->transfer_string())
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ namespace worker {
class MessagePortData;
class MessagePort;

typedef MaybeStackBuffer<v8::Local<v8::Value>, 8> TransferList;
typedef MaybeStackBuffer<v8::Value, 8> TransferList;

// Used to represent the in-flight structure of an object that is being
// transferred or cloned using postMessage().
Expand Down
10 changes: 5 additions & 5 deletions src/node_v8.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -745,17 +745,17 @@ void Initialize(Local<Object> target,
// Heap space names are extracted once and exposed to JavaScript to
// avoid excessive creation of heap space name Strings.
HeapSpaceStatistics s;
MaybeStackBuffer<Local<Value>, 16> heap_spaces(number_of_heap_spaces);
MaybeStackBuffer<Value, 16> heap_spaces(env->isolate(),
number_of_heap_spaces);
for (size_t i = 0; i < number_of_heap_spaces; i++) {
env->isolate()->GetHeapSpaceStatistics(&s, i);
heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name())
.ToLocalChecked();
}
target
->Set(
context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
Array::New(env->isolate(), heap_spaces.out(), number_of_heap_spaces))
->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces.ToArray())
.Check();

SetMethod(context,
Expand Down
5 changes: 2 additions & 3 deletions src/spawn_sync.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -767,7 +767,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
CHECK(!stdio_pipes_.empty());

EscapableHandleScope scope(env()->isolate());
MaybeStackBuffer<Local<Value>, 8> js_output(stdio_pipes_.size());
MaybeStackBuffer<Value, 8> js_output(env()->isolate(), stdio_pipes_.size());

for (uint32_t i = 0; i < stdio_pipes_.size(); i++) {
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
Expand All@@ -781,8 +781,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
}
}

return scope.Escape(
Array::New(env()->isolate(), js_output.out(), js_output.length()));
return scope.Escape(js_output.ToArray());
}

Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Expand Down
40 changes: 33 additions & 7 deletions src/util-inl.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,14 +394,13 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T>
Expand DownExpand Up@@ -430,16 +429,15 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
auto it = vec.begin();
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, *it, isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
std::advance(it, 1);
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T, typename U>
Expand DownExpand Up@@ -519,7 +517,14 @@ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
}

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: SlicedArguments(args.GetIsolate(), args, start) {}

SlicedArguments::SlicedArguments(
v8::Isolate* isolate,
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start)
: MaybeStackBuffer<v8::Value>(isolate) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
Expand All@@ -545,6 +550,27 @@ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
length_ = storage;
}

template <V8Type T, size_t kStackStorageSize>
void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
if (!local_vector_.has_value()) {
local_vector_.emplace(isolate_, storage);
// Copy existing stack data into the LocalVector.
for (size_t i = 0; i < length_; i++) {
(*local_vector_)[i] = buf_st_[i];
}
} else {
local_vector_->resize(storage);
}
buf_ = local_vector_->data();
capacity_ = storage;
}

length_ = storage;
}

template <typename T, size_t S>
requires(sizeof(T) == 1)
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/api/callback.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,

Local<Context> context = env->context();
if (use_async_hooks_trampoline) {
MaybeStackBuffer<Local<Value>, 16> args(3 + argc);
MaybeStackBuffer<Value, 16> args(env->isolate(), 3 + argc);
args[0] = Number::New(env->isolate(), asyncContext.async_id);
args[1] = resource;
args[2] = callback;
Expand Down
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,12 +187,12 @@ Local<Array> AddrTTLToArray(
Environment* env,
const T* addrttls,
size_t naddrttls) {
MaybeStackBuffer<Local<Value>, 8> ttls(naddrttls);
MaybeStackBuffer<Value, 8> ttls(env->isolate(), naddrttls);
for (size_t i = 0; i < naddrttls; i++) {
ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl);
}

return Array::New(env->isolate(), ttls.out(), naddrttls);
return ttls.ToArray();
}

// Parse the CSV produced by ares_get_servers_csv() back into (ip, port)
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/crypto_tls.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,6 @@ using ncrypto::MarkPopErrorOnReturn;
using ncrypto::SSLPointer;
using ncrypto::SSLSessionPointer;
using ncrypto::X509Pointer;
using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
Expand DownExpand Up@@ -1956,7 +1955,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
SSL* ssl = w->ssl_.get();
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
nullptr);
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
MaybeStackBuffer<Value, 16> ret_arr(env->isolate(), nsig);

for (int i = 0; i < nsig; i++) {
int hash_nid;
Expand DownExpand Up@@ -2023,8 +2022,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
ret_arr[i] = OneByteString(env->isolate(), sig_with_md);
}

args.GetReturnValue().Set(
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
args.GetReturnValue().Set(ret_arr.ToArray());
}

void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
Expand Down
8 changes: 2 additions & 6 deletions src/js_stream.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ namespace node {

using errors::TryCatchScope;

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -119,17 +118,14 @@ int JSStream::DoWrite(WriteWrap* w,

int value_int = UV_EPROTO;

MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
MaybeStackBuffer<Value, 16> bufs_arr(env()->isolate(), count);
for (size_t i = 0; i < count; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
return value_int;
}
}

Local<Value> argv[] = {
w->object(),
Array::New(env()->isolate(), bufs_arr.out(), count)
};
Local<Value> argv[] = {w->object(), bufs_arr.ToArray()};

TryCatchScope try_catch(env());
Local<Value> value;
Expand Down
9 changes: 4 additions & 5 deletions src/js_udp_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@
namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -98,7 +97,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
int64_t value_int = JS_EXCEPTION_PENDING;
size_t total_len = 0;

MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
MaybeStackBuffer<Value, 16> buffers(env()->isolate(), nbufs);
for (size_t i = 0; i < nbufs; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
return value_int;
Expand All@@ -110,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int;

Local<Value> args[] = {
listener()->CreateSendWrap(total_len)->object(),
Array::New(env()->isolate(), buffers.out(), nbufs),
address,
listener()->CreateSendWrap(total_len)->object(),
buffers.ToArray(),
address,
};

if (!MakeCallback(env()->onwrite_string(), arraysize(args), args)
Expand Down
7 changes: 7 additions & 0 deletions src/node_concepts.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <v8.h>
#include <concepts>
#include <limits>
#include <type_traits>
Expand DownExpand Up@@ -32,6 +33,12 @@ concept StandardCharType =
template <typename T>
concept IsCallable = std::is_function<T>::value || requires { &T::operator(); };

// Types that can reside on V8's managed heap (v8::Value, v8::Object, etc.).
// Used to select the MaybeStackBuffer specialization that holds handles in a
// v8::LocalVector instead of malloc'd memory.
template <typename T>
concept V8Type = std::is_base_of_v<v8::Data, T>;

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
uv_dirent_t* ents,
int num,
enum encoding encoding) {
MaybeStackBuffer<Local<Value>, 64> entries(num * 2);
MaybeStackBuffer<Value, 64> entries(env->isolate(), num * 2);

// Return an array of all read filenames.
int j = 0;
Expand All@@ -222,7 +222,8 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
entries[j++] = Integer::New(env->isolate(), ents[i].type);
}

return Array::New(env->isolate(), entries.out(), j);
CHECK_EQ(j, num * 2);
return entries.ToArray();
}

static void AfterDirRead(uv_fs_t* req) {
Expand Down
7 changes: 5 additions & 2 deletions src/node_env_var.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); });
CHECK_EQ(uv_os_environ(&items, &count), 0);

MaybeStackBuffer<Local<Value>, 256> env_v(count);
MaybeStackBuffer<Value, 256> env_v(isolate, count);
int env_v_index = 0;
for (int i = 0; i < count; i++) {
#ifdef _WIN32
Expand All@@ -216,7 +216,10 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
env_v[env_v_index++] = str;
}

return Array::New(isolate, env_v.out(), env_v_index);
// We're possibly not filling the entire buffer.
CHECK_LE(env_v_index, count);
env_v.SetLength(env_v_index);
return env_v.ToArray();
}

std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const {
Expand Down
17 changes: 9 additions & 8 deletions src/node_http2.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1609,8 +1609,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
// this way for performance reasons (it's faster to generate and pass an
// array than it is to generate and pass the object).

MaybeStackBuffer<Local<Value>, 64> headers_v(stream->headers_count() * 2);
MaybeStackBuffer<Local<Value>, 32> sensitive_v(stream->headers_count());
MaybeStackBuffer<Value, 64> headers_v(isolate, stream->headers_count() * 2);
MaybeStackBuffer<Value, 32> sensitive_v(isolate, stream->headers_count());
size_t sensitive_count = 0;

stream->TransferHeaders([&](const Http2Header& header, size_t i) {
Expand All@@ -1627,13 +1627,14 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
stream->retained_headers_length_ += stream->current_headers_length_;
stream->current_headers_length_ = 0;

sensitive_v.SetLength(sensitive_count);
Local<Value> args[] = {
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
Array::New(isolate, headers_v.out(), headers_v.length()),
Array::New(isolate, sensitive_v.out(), sensitive_count),
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
headers_v.ToArray(),
sensitive_v.ToArray(),
};
MakeCallback(env()->http2session_on_headers_function(),
arraysize(args), args);
Expand Down
4 changes: 2 additions & 2 deletions src/node_messaging.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1093,7 +1093,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
"MessagePort.postMessage");
}

TransferList transfer_list;
TransferList transfer_list(env->isolate());
if (!GetTransferList(env, context, args[1], &transfer_list)) {
return;
}
Expand DownExpand Up@@ -1607,7 +1607,7 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) {

Local<Value> value = args[0];

TransferList transfer_list;
TransferList transfer_list(isolate);
Local<Object> options = args[1].As<Object>();
Local<Value> transfer_list_v;
if (!options->Get(context, env->transfer_string())
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ namespace worker {
class MessagePortData;
class MessagePort;

typedef MaybeStackBuffer<v8::Local<v8::Value>, 8> TransferList;
typedef MaybeStackBuffer<v8::Value, 8> TransferList;

// Used to represent the in-flight structure of an object that is being
// transferred or cloned using postMessage().
Expand Down
10 changes: 5 additions & 5 deletions src/node_v8.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -745,17 +745,17 @@ void Initialize(Local<Object> target,
// Heap space names are extracted once and exposed to JavaScript to
// avoid excessive creation of heap space name Strings.
HeapSpaceStatistics s;
MaybeStackBuffer<Local<Value>, 16> heap_spaces(number_of_heap_spaces);
MaybeStackBuffer<Value, 16> heap_spaces(env->isolate(),
number_of_heap_spaces);
for (size_t i = 0; i < number_of_heap_spaces; i++) {
env->isolate()->GetHeapSpaceStatistics(&s, i);
heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name())
.ToLocalChecked();
}
target
->Set(
context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
Array::New(env->isolate(), heap_spaces.out(), number_of_heap_spaces))
->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces.ToArray())
.Check();

SetMethod(context,
Expand Down
5 changes: 2 additions & 3 deletions src/spawn_sync.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -767,7 +767,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
CHECK(!stdio_pipes_.empty());

EscapableHandleScope scope(env()->isolate());
MaybeStackBuffer<Local<Value>, 8> js_output(stdio_pipes_.size());
MaybeStackBuffer<Value, 8> js_output(env()->isolate(), stdio_pipes_.size());

for (uint32_t i = 0; i < stdio_pipes_.size(); i++) {
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
Expand All@@ -781,8 +781,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
}
}

return scope.Escape(
Array::New(env()->isolate(), js_output.out(), js_output.length()));
return scope.Escape(js_output.ToArray());
}

Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Expand Down
40 changes: 33 additions & 7 deletions src/util-inl.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,14 +394,13 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T>
Expand DownExpand Up@@ -430,16 +429,15 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
auto it = vec.begin();
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, *it, isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
std::advance(it, 1);
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T, typename U>
Expand DownExpand Up@@ -519,7 +517,14 @@ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
}

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: SlicedArguments(args.GetIsolate(), args, start) {}

SlicedArguments::SlicedArguments(
v8::Isolate* isolate,
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start)
: MaybeStackBuffer<v8::Value>(isolate) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
Expand All@@ -545,6 +550,27 @@ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
length_ = storage;
}

template <V8Type T, size_t kStackStorageSize>
void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
if (!local_vector_.has_value()) {
local_vector_.emplace(isolate_, storage);
// Copy existing stack data into the LocalVector.
for (size_t i = 0; i < length_; i++) {
(*local_vector_)[i] = buf_st_[i];
}
} else {
local_vector_->resize(storage);
}
buf_ = local_vector_->data();
capacity_ = storage;
}

length_ = storage;
}

template <typename T, size_t S>
requires(sizeof(T) == 1)
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/api/callback.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,

Local<Context> context = env->context();
if (use_async_hooks_trampoline) {
MaybeStackBuffer<Local<Value>, 16> args(3 + argc);
MaybeStackBuffer<Value, 16> args(env->isolate(), 3 + argc);
args[0] = Number::New(env->isolate(), asyncContext.async_id);
args[1] = resource;
args[2] = callback;
Expand Down
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,12 +187,12 @@ Local<Array> AddrTTLToArray(
Environment* env,
const T* addrttls,
size_t naddrttls) {
MaybeStackBuffer<Local<Value>, 8> ttls(naddrttls);
MaybeStackBuffer<Value, 8> ttls(env->isolate(), naddrttls);
for (size_t i = 0; i < naddrttls; i++) {
ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl);
}

return Array::New(env->isolate(), ttls.out(), naddrttls);
return ttls.ToArray();
}

// Parse the CSV produced by ares_get_servers_csv() back into (ip, port)
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/crypto_tls.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,6 @@ using ncrypto::MarkPopErrorOnReturn;
using ncrypto::SSLPointer;
using ncrypto::SSLSessionPointer;
using ncrypto::X509Pointer;
using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
Expand DownExpand Up@@ -1956,7 +1955,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
SSL* ssl = w->ssl_.get();
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
nullptr);
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
MaybeStackBuffer<Value, 16> ret_arr(env->isolate(), nsig);

for (int i = 0; i < nsig; i++) {
int hash_nid;
Expand DownExpand Up@@ -2023,8 +2022,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
ret_arr[i] = OneByteString(env->isolate(), sig_with_md);
}

args.GetReturnValue().Set(
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
args.GetReturnValue().Set(ret_arr.ToArray());
}

void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
Expand Down
8 changes: 2 additions & 6 deletions src/js_stream.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ namespace node {

using errors::TryCatchScope;

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -119,17 +118,14 @@ int JSStream::DoWrite(WriteWrap* w,

int value_int = UV_EPROTO;

MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
MaybeStackBuffer<Value, 16> bufs_arr(env()->isolate(), count);
for (size_t i = 0; i < count; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
return value_int;
}
}

Local<Value> argv[] = {
w->object(),
Array::New(env()->isolate(), bufs_arr.out(), count)
};
Local<Value> argv[] = {w->object(), bufs_arr.ToArray()};

TryCatchScope try_catch(env());
Local<Value> value;
Expand Down
9 changes: 4 additions & 5 deletions src/js_udp_wrap.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@
namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand DownExpand Up@@ -98,7 +97,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
int64_t value_int = JS_EXCEPTION_PENDING;
size_t total_len = 0;

MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
MaybeStackBuffer<Value, 16> buffers(env()->isolate(), nbufs);
for (size_t i = 0; i < nbufs; i++) {
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
return value_int;
Expand All@@ -110,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int;

Local<Value> args[] = {
listener()->CreateSendWrap(total_len)->object(),
Array::New(env()->isolate(), buffers.out(), nbufs),
address,
listener()->CreateSendWrap(total_len)->object(),
buffers.ToArray(),
address,
};

if (!MakeCallback(env()->onwrite_string(), arraysize(args), args)
Expand Down
7 changes: 7 additions & 0 deletions src/node_concepts.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <v8.h>
#include <concepts>
#include <limits>
#include <type_traits>
Expand DownExpand Up@@ -32,6 +33,12 @@ concept StandardCharType =
template <typename T>
concept IsCallable = std::is_function<T>::value || requires { &T::operator(); };

// Types that can reside on V8's managed heap (v8::Value, v8::Object, etc.).
// Used to select the MaybeStackBuffer specialization that holds handles in a
// v8::LocalVector instead of malloc'd memory.
template <typename T>
concept V8Type = std::is_base_of_v<v8::Data, T>;

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
uv_dirent_t* ents,
int num,
enum encoding encoding) {
MaybeStackBuffer<Local<Value>, 64> entries(num * 2);
MaybeStackBuffer<Value, 64> entries(env->isolate(), num * 2);

// Return an array of all read filenames.
int j = 0;
Expand All@@ -222,7 +222,8 @@ static MaybeLocal<Array> DirentListToArray(Environment* env,
entries[j++] = Integer::New(env->isolate(), ents[i].type);
}

return Array::New(env->isolate(), entries.out(), j);
CHECK_EQ(j, num * 2);
return entries.ToArray();
}

static void AfterDirRead(uv_fs_t* req) {
Expand Down
7 changes: 5 additions & 2 deletions src/node_env_var.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); });
CHECK_EQ(uv_os_environ(&items, &count), 0);

MaybeStackBuffer<Local<Value>, 256> env_v(count);
MaybeStackBuffer<Value, 256> env_v(isolate, count);
int env_v_index = 0;
for (int i = 0; i < count; i++) {
#ifdef _WIN32
Expand All@@ -216,7 +216,10 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
env_v[env_v_index++] = str;
}

return Array::New(isolate, env_v.out(), env_v_index);
// We're possibly not filling the entire buffer.
CHECK_LE(env_v_index, count);
env_v.SetLength(env_v_index);
return env_v.ToArray();
}

std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const {
Expand Down
17 changes: 9 additions & 8 deletions src/node_http2.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1609,8 +1609,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
// this way for performance reasons (it's faster to generate and pass an
// array than it is to generate and pass the object).

MaybeStackBuffer<Local<Value>, 64> headers_v(stream->headers_count() * 2);
MaybeStackBuffer<Local<Value>, 32> sensitive_v(stream->headers_count());
MaybeStackBuffer<Value, 64> headers_v(isolate, stream->headers_count() * 2);
MaybeStackBuffer<Value, 32> sensitive_v(isolate, stream->headers_count());
size_t sensitive_count = 0;

stream->TransferHeaders([&](const Http2Header& header, size_t i) {
Expand All@@ -1627,13 +1627,14 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
stream->retained_headers_length_ += stream->current_headers_length_;
stream->current_headers_length_ = 0;

sensitive_v.SetLength(sensitive_count);
Local<Value> args[] = {
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
Array::New(isolate, headers_v.out(), headers_v.length()),
Array::New(isolate, sensitive_v.out(), sensitive_count),
stream->object(),
Integer::New(isolate, id),
Integer::New(isolate, stream->headers_category()),
Integer::New(isolate, frame->hd.flags),
headers_v.ToArray(),
sensitive_v.ToArray(),
};
MakeCallback(env()->http2session_on_headers_function(),
arraysize(args), args);
Expand Down
4 changes: 2 additions & 2 deletions src/node_messaging.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -1093,7 +1093,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
"MessagePort.postMessage");
}

TransferList transfer_list;
TransferList transfer_list(env->isolate());
if (!GetTransferList(env, context, args[1], &transfer_list)) {
return;
}
Expand DownExpand Up@@ -1607,7 +1607,7 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) {

Local<Value> value = args[0];

TransferList transfer_list;
TransferList transfer_list(isolate);
Local<Object> options = args[1].As<Object>();
Local<Value> transfer_list_v;
if (!options->Get(context, env->transfer_string())
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ namespace worker {
class MessagePortData;
class MessagePort;

typedef MaybeStackBuffer<v8::Local<v8::Value>, 8> TransferList;
typedef MaybeStackBuffer<v8::Value, 8> TransferList;

// Used to represent the in-flight structure of an object that is being
// transferred or cloned using postMessage().
Expand Down
10 changes: 5 additions & 5 deletions src/node_v8.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -745,17 +745,17 @@ void Initialize(Local<Object> target,
// Heap space names are extracted once and exposed to JavaScript to
// avoid excessive creation of heap space name Strings.
HeapSpaceStatistics s;
MaybeStackBuffer<Local<Value>, 16> heap_spaces(number_of_heap_spaces);
MaybeStackBuffer<Value, 16> heap_spaces(env->isolate(),
number_of_heap_spaces);
for (size_t i = 0; i < number_of_heap_spaces; i++) {
env->isolate()->GetHeapSpaceStatistics(&s, i);
heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name())
.ToLocalChecked();
}
target
->Set(
context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
Array::New(env->isolate(), heap_spaces.out(), number_of_heap_spaces))
->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces.ToArray())
.Check();

SetMethod(context,
Expand Down
5 changes: 2 additions & 3 deletions src/spawn_sync.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -767,7 +767,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
CHECK(!stdio_pipes_.empty());

EscapableHandleScope scope(env()->isolate());
MaybeStackBuffer<Local<Value>, 8> js_output(stdio_pipes_.size());
MaybeStackBuffer<Value, 8> js_output(env()->isolate(), stdio_pipes_.size());

for (uint32_t i = 0; i < stdio_pipes_.size(); i++) {
SyncProcessStdioPipe* h = stdio_pipes_[i].get();
Expand All@@ -781,8 +781,7 @@ MaybeLocal<Array> SyncProcessRunner::BuildOutputArray() {
}
}

return scope.Escape(
Array::New(env()->isolate(), js_output.out(), js_output.length()));
return scope.Escape(js_output.ToArray());
}

Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Expand Down
40 changes: 33 additions & 7 deletions src/util-inl.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,14 +394,13 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T>
Expand DownExpand Up@@ -430,16 +429,15 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope handle_scope(isolate);

MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
arr.SetLength(vec.size());
MaybeStackBuffer<v8::Value, 128> arr(isolate, vec.size());
auto it = vec.begin();
for (size_t i = 0; i < vec.size(); ++i) {
if (!ToV8Value(context, *it, isolate).ToLocal(&arr[i]))
return v8::MaybeLocal<v8::Value>();
std::advance(it, 1);
}

return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length()));
return handle_scope.Escape(arr.ToArray());
}

template <typename T, typename U>
Expand DownExpand Up@@ -519,7 +517,14 @@ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
}

SlicedArguments::SlicedArguments(
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start) {
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start)
: SlicedArguments(args.GetIsolate(), args, start) {}

SlicedArguments::SlicedArguments(
v8::Isolate* isolate,
const v8::FunctionCallbackInfo<v8::Value>& args,
size_t start)
: MaybeStackBuffer<v8::Value>(isolate) {
const size_t length = static_cast<size_t>(args.Length());
if (start >= length) return;
const size_t size = length - start;
Expand All@@ -545,6 +550,27 @@ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
length_ = storage;
}

template <V8Type T, size_t kStackStorageSize>
void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
size_t storage) {
CHECK(!IsInvalidated());
if (storage > capacity()) {
if (!local_vector_.has_value()) {
local_vector_.emplace(isolate_, storage);
// Copy existing stack data into the LocalVector.
for (size_t i = 0; i < length_; i++) {
(*local_vector_)[i] = buf_st_[i];
}
} else {
local_vector_->resize(storage);
}
buf_ = local_vector_->data();
capacity_ = storage;
}

length_ = storage;
}

template <typename T, size_t S>
requires(sizeof(T) == 1)
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
Expand Down
Loading
Loading