@@ -129,6 +129,7 @@ void context::run_file(v8::FunctionCallbackInfo<v8::Value> const& args)
129
129
args.GetReturnValue ().Set (scope.Escape (result));
130
130
}
131
131
132
+ #if V8_MAJOR_VERSION < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 4)
132
133
struct array_buffer_allocator : v8::ArrayBuffer::Allocator
133
134
{
134
135
void * Allocate (size_t length)
@@ -145,12 +146,16 @@ struct array_buffer_allocator : v8::ArrayBuffer::Allocator
145
146
(void )length;
146
147
}
147
148
};
148
- static array_buffer_allocator array_buffer_allocator_;
149
+ # endif
149
150
150
151
v8::Isolate* context::create_isolate (v8::ArrayBuffer::Allocator* allocator)
151
152
{
152
153
v8::Isolate::CreateParams create_params;
153
- create_params.array_buffer_allocator = allocator ? allocator : &array_buffer_allocator_;
154
+ #if V8_MAJOR_VERSION < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 4)
155
+ create_params.array_buffer_allocator = allocator ? allocator : new array_buffer_allocator;
156
+ #else
157
+ create_params.array_buffer_allocator = allocator ? allocator : v8::ArrayBuffer::Allocator::NewDefaultAllocator ();
158
+ #endif
154
159
155
160
return v8::Isolate::New (create_params);
156
161
}
@@ -165,6 +170,11 @@ context::context(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator,
165
170
if (own_isolate_)
166
171
{
167
172
isolate_->Enter ();
173
+ if (!allocator)
174
+ {
175
+ // take ownership over the new allocator created in create_isolate()
176
+ array_buffer_allocator_.reset (isolate_->GetArrayBufferAllocator ());
177
+ }
168
178
}
169
179
170
180
v8::HandleScope scope (isolate_);
@@ -196,6 +206,7 @@ context::context(context&& src) noexcept
196
206
, enter_context_(std::exchange(src.enter_context_, false ))
197
207
, isolate_(std::exchange(src.isolate_, nullptr ))
198
208
, impl_(std::move(src.impl_))
209
+ , array_buffer_allocator_(std::move(src.array_buffer_allocator_))
199
210
, modules_(std::move(src.modules_))
200
211
, lib_path_(std::move(src.lib_path_))
201
212
{
@@ -210,6 +221,7 @@ context& context::operator=(context&& src) noexcept
210
221
own_isolate_ = std::exchange (src.own_isolate_ , false );
211
222
enter_context_ = std::exchange (src.enter_context_ , false );
212
223
isolate_ = std::exchange (src.isolate_ , nullptr );
224
+ array_buffer_allocator_ = std::move (src.array_buffer_allocator_ );
213
225
impl_ = std::move (src.impl_ );
214
226
modules_ = std::move (src.modules_ );
215
227
lib_path_ = std::move (src.lib_path_ );
@@ -260,6 +272,7 @@ void context::destroy()
260
272
isolate_->Dispose ();
261
273
}
262
274
isolate_ = nullptr ;
275
+ array_buffer_allocator_.reset ();
263
276
}
264
277
265
278
context& context::value (std::string_view name, v8::Local<v8::Value> value)
0 commit comments