-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathv8isolate.cc
36 lines (26 loc) · 1.04 KB
/
v8isolate.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "v8isolate.h"
#include <cstdlib>
#include <cstring>
void* ArrayBufferAllocator::Allocate(size_t length) {
void* data = AllocateUninitialized(length);
return data == nullptr ? data : memset(data, 0, length);
}
void* ArrayBufferAllocator::AllocateUninitialized(size_t length) {
return malloc(length);
}
void ArrayBufferAllocator::Free(void* data, size_t) { free(data); }
V8Isolate::V8Isolate() {
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &allocator;
isolate_ = v8::Isolate::New(create_params);
}
V8Isolate::V8Isolate(v8::StartupData* startup_data) {
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &allocator;
create_params.snapshot_blob = startup_data;
isolate_ = v8::Isolate::New(create_params);
}
V8Context* V8Isolate::MakeContext() { return new V8Context(isolate_); }
V8Isolate::~V8Isolate() { isolate_->Dispose(); }
void V8Isolate::Terminate() { v8::V8::TerminateExecution(isolate_); }
v8::Unlocker* V8Isolate::Unlock() { return new v8::Unlocker(isolate_); }