OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "include/libplatform/libplatform.h" | 9 #include "include/libplatform/libplatform.h" |
10 #include "include/v8.h" | 10 #include "include/v8.h" |
11 | 11 |
12 using namespace v8; | 12 using namespace v8; |
13 | 13 |
14 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 14 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
15 public: | 15 public: |
16 virtual void* Allocate(size_t length) { | 16 virtual void* Allocate(size_t length) { |
17 void* data = AllocateUninitialized(length); | 17 void* data = AllocateUninitialized(length); |
18 return data == NULL ? data : memset(data, 0, length); | 18 return data == NULL ? data : memset(data, 0, length); |
19 } | 19 } |
20 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } | 20 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } |
21 virtual void Free(void* data, size_t) { free(data); } | 21 virtual void Free(void* data, size_t) { free(data); } |
22 }; | 22 }; |
23 | 23 |
24 | 24 |
25 int main(int argc, char* argv[]) { | 25 int main(int argc, char* argv[]) { |
26 // Initialize V8. | 26 // Initialize V8. |
27 V8::InitializeICU(); | 27 V8::InitializeICU(); |
| 28 V8::InitializeExternalStartupData(argv[0]); |
28 Platform* platform = platform::CreateDefaultPlatform(); | 29 Platform* platform = platform::CreateDefaultPlatform(); |
29 V8::InitializePlatform(platform); | 30 V8::InitializePlatform(platform); |
30 V8::Initialize(); | 31 V8::Initialize(); |
31 | 32 |
32 // Create a new Isolate and make it the current one. | 33 // Create a new Isolate and make it the current one. |
33 ArrayBufferAllocator allocator; | 34 ArrayBufferAllocator allocator; |
34 Isolate::CreateParams create_params; | 35 Isolate::CreateParams create_params; |
35 create_params.array_buffer_allocator = &allocator; | 36 create_params.array_buffer_allocator = &allocator; |
36 Isolate* isolate = Isolate::New(create_params); | 37 Isolate* isolate = Isolate::New(create_params); |
37 { | 38 { |
(...skipping 24 matching lines...) Expand all Loading... |
62 printf("%s\n", *utf8); | 63 printf("%s\n", *utf8); |
63 } | 64 } |
64 | 65 |
65 // Dispose the isolate and tear down V8. | 66 // Dispose the isolate and tear down V8. |
66 isolate->Dispose(); | 67 isolate->Dispose(); |
67 V8::Dispose(); | 68 V8::Dispose(); |
68 V8::ShutdownPlatform(); | 69 V8::ShutdownPlatform(); |
69 delete platform; | 70 delete platform; |
70 return 0; | 71 return 0; |
71 } | 72 } |
OLD | NEW |