66
77using namespace v8 ;
88
9- class ArrayBufferAllocator : public v8 ::ArrayBuffer::Allocator {
10- public:
11- virtual void * Allocate (size_t length) {
12- void * data = AllocateUninitialized (length);
13- return data == NULL ? data : memset (data, 0 , length);
14- }
15- virtual void * AllocateUninitialized (size_t length) { return malloc (length); }
16- virtual void Free (void * data, size_t ) { free (data); }
17- };
18-
19-
209void weak_callback (const v8::WeakCallbackInfo<v8::Persistent<v8::String>>& data) {
2110 printf (" Weak callback called\n " );
2211 data.GetParameter ()->Reset ();
@@ -29,20 +18,16 @@ int main(int argc, char* argv[]) {
2918 v8::Platform *platform = v8::platform::CreateDefaultPlatform ();
3019 v8::V8::InitializePlatform (platform);
3120
32- V8::Initialize ();
33-
21+ // std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform ();
22+ // v8::V8::InitializePlatform(platform.get());
3423
35- ArrayBufferAllocator *array_buffer_allocator;
36- v8::Isolate::CreateParams *create_params;
37-
38- array_buffer_allocator = new ArrayBufferAllocator ();
39- create_params = new v8::Isolate::CreateParams ();
40-
41- create_params->array_buffer_allocator = array_buffer_allocator;
24+ V8::Initialize ();
4225
26+ v8::Isolate::CreateParams create_params;
27+ create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator ();
4328
4429 // Create a new Isolate and make it the current one.
45- Isolate* isolate = v8::Isolate::New (* create_params);
30+ Isolate* isolate = v8::Isolate::New (create_params);
4631
4732 v8::Persistent<v8::String> test;
4833
@@ -90,9 +75,5 @@ int main(int argc, char* argv[]) {
9075 V8::Dispose ();
9176 V8::ShutdownPlatform ();
9277
93- delete array_buffer_allocator;
94- delete create_params;
95- delete platform;
96-
9778 return 0 ;
9879}
0 commit comments