OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium 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 "mojo/apps/js/v8_environment.h" | 5 #include "mojo/public/bindings/js/v8_environment.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
| 10 #include "mojo/public/bindings/js/v8_array_buffer.h" |
| 11 #include "mojo/public/bindings/js/v8_per_isolate_data.h" |
10 #include "mojo/public/system/macros.h" | 12 #include "mojo/public/system/macros.h" |
11 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
12 | 14 |
13 namespace mojo { | 15 namespace mojo { |
14 namespace apps { | 16 namespace js { |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | |
19 virtual void* Allocate(size_t length) MOJO_OVERRIDE { | |
20 return calloc(1, length); | |
21 } | |
22 virtual void* AllocateUninitialized(size_t length) MOJO_OVERRIDE { | |
23 return malloc(length); | |
24 } | |
25 virtual void Free(void* data, size_t length) MOJO_OVERRIDE { | |
26 free(data); | |
27 } | |
28 }; | |
29 | |
30 bool GenerateEntropy(unsigned char* buffer, size_t amount) { | 20 bool GenerateEntropy(unsigned char* buffer, size_t amount) { |
31 // TODO(abarth): Mojo needs a source of entropy. | 21 // TODO(abarth): Mojo needs a source of entropy. |
32 // https://code.google.com/p/chromium/issues/detail?id=316387 | 22 // https://code.google.com/p/chromium/issues/detail?id=316387 |
33 return false; | 23 return false; |
34 } | 24 } |
35 | 25 |
36 const char kFlags[] = "--use_strict --harmony"; | 26 const char kFlags[] = "--use_strict --harmony"; |
37 | 27 |
38 } | 28 } |
39 | 29 |
40 void InitializeV8() { | 30 void Initialize() { |
41 v8::V8::SetArrayBufferAllocator(new ArrayBufferAllocator()); | 31 v8::V8::SetArrayBufferAllocator(js::ArrayBufferAllocator::SharedInstance()); |
42 v8::V8::InitializeICU(); | 32 v8::V8::InitializeICU(); |
43 v8::V8::SetFlagsFromString(kFlags, strlen(kFlags)); | 33 v8::V8::SetFlagsFromString(kFlags, strlen(kFlags)); |
44 v8::V8::SetEntropySource(&GenerateEntropy); | 34 v8::V8::SetEntropySource(&GenerateEntropy); |
45 v8::V8::Initialize(); | 35 v8::V8::Initialize(); |
| 36 |
| 37 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 38 v8::HandleScope handle_scope(isolate); |
| 39 new V8PerIsolateData(isolate); |
46 } | 40 } |
47 | 41 |
48 } // namespace apps | 42 } // namespace js |
49 } // mojo | 43 } // namespace mojo |
OLD | NEW |