Skip to content

Commit

Permalink
src: use DataView instead of Buffer for code cache
Browse files Browse the repository at this point in the history
Refs: nodejs#48191 (comment)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen committed Jun 1, 2023
1 parent cf1bdc2 commit 5dfdbd1
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/node_sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)

using node::ExitCode;
using v8::ArrayBuffer;
using v8::BackingStore;
using v8::Context;
using v8::DataView;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::HandleScope;
Expand Down Expand Up @@ -202,21 +205,20 @@ void GetCodeCache(const FunctionCallbackInfo<Value>& args) {

SeaResource sea_resource = FindSingleExecutableResource();

Local<Object> buf;
if (!Buffer::New(
env,
const_cast<char*>(sea_resource.code_cache.data()),
sea_resource.code_cache.length(),
[](char* /* data */, void* /* hint */) {
// We don't free the code cache data string because it is not owned
// by us.
},
nullptr)
.ToLocal(&buf)) {
return;
}

args.GetReturnValue().Set(buf);
std::shared_ptr<BackingStore> backing_store = ArrayBuffer::NewBackingStore(
const_cast<void*>(
static_cast<const void*>(sea_resource.code_cache.data())),
sea_resource.code_cache.length(),
[](void* /* data */, size_t /* length */, void* /* deleter_data */) {
// The code cache data string is not freed here because it is a static
// string which is not allocated by the BackingStore allocator.
},
nullptr);
Local<ArrayBuffer> array_buffer = ArrayBuffer::New(isolate, backing_store);
Local<DataView> data_view =
DataView::New(array_buffer, 0, array_buffer->ByteLength());

args.GetReturnValue().Set(data_view);
}

void GetCodePath(const FunctionCallbackInfo<Value>& args) {
Expand Down

0 comments on commit 5dfdbd1

Please sign in to comment.