Skip to content
Open
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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 Down Expand Up @@ -1958,7 +1957,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 Down Expand Up @@ -2025,8 +2024,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 number Diff line number Diff 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 Down Expand 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 number Diff line number Diff 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 Down Expand 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
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 Down Expand 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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 Down Expand 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 Down Expand Up @@ -523,7 +521,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 @@ -549,6 +554,27 @@ void MaybeStackBuffer<T, kStackStorageSize>::AllocateSufficientStorage(
length_ = storage;
}

template <v8_type 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>
ArrayBufferViewContents<T, S>::ArrayBufferViewContents(
v8::Local<v8::Value> value) {
Expand Down
Loading
Loading