|
29 | 29 | #if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
|
30 | 30 |
|
31 | 31 | using node::ExitCode;
|
| 32 | +using v8::ArrayBuffer; |
| 33 | +using v8::BackingStore; |
32 | 34 | using v8::Context;
|
| 35 | +using v8::DataView; |
33 | 36 | using v8::Function;
|
34 | 37 | using v8::FunctionCallbackInfo;
|
35 | 38 | using v8::HandleScope;
|
@@ -202,21 +205,20 @@ void GetCodeCache(const FunctionCallbackInfo<Value>& args) {
|
202 | 205 |
|
203 | 206 | SeaResource sea_resource = FindSingleExecutableResource();
|
204 | 207 |
|
205 |
| - Local<Object> buf; |
206 |
| - if (!Buffer::New( |
207 |
| - env, |
208 |
| - const_cast<char*>(sea_resource.code_cache.data()), |
209 |
| - sea_resource.code_cache.length(), |
210 |
| - [](char* /* data */, void* /* hint */) { |
211 |
| - // We don't free the code cache data string because it is not owned |
212 |
| - // by us. |
213 |
| - }, |
214 |
| - nullptr) |
215 |
| - .ToLocal(&buf)) { |
216 |
| - return; |
217 |
| - } |
218 |
| - |
219 |
| - args.GetReturnValue().Set(buf); |
| 208 | + std::shared_ptr<BackingStore> backing_store = ArrayBuffer::NewBackingStore( |
| 209 | + const_cast<void*>( |
| 210 | + static_cast<const void*>(sea_resource.code_cache.data())), |
| 211 | + sea_resource.code_cache.length(), |
| 212 | + [](void* /* data */, size_t /* length */, void* /* deleter_data */) { |
| 213 | + // The code cache data string is not freed here because it is a static |
| 214 | + // string which is not allocated by the BackingStore allocator. |
| 215 | + }, |
| 216 | + nullptr); |
| 217 | + Local<ArrayBuffer> array_buffer = ArrayBuffer::New(isolate, backing_store); |
| 218 | + Local<DataView> data_view = |
| 219 | + DataView::New(array_buffer, 0, array_buffer->ByteLength()); |
| 220 | + |
| 221 | + args.GetReturnValue().Set(data_view); |
220 | 222 | }
|
221 | 223 |
|
222 | 224 | void GetCodePath(const FunctionCallbackInfo<Value>& args) {
|
|
0 commit comments