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/apps/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" |
10 #include "mojo/public/system/macros.h" | 11 #include "mojo/public/system/macros.h" |
11 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
12 | 13 |
13 namespace mojo { | 14 namespace mojo { |
14 namespace apps { | 15 namespace apps { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
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) { | 19 bool GenerateEntropy(unsigned char* buffer, size_t amount) { |
31 // TODO(abarth): Mojo needs a source of entropy. | 20 // TODO(abarth): Mojo needs a source of entropy. |
32 // https://code.google.com/p/chromium/issues/detail?id=316387 | 21 // https://code.google.com/p/chromium/issues/detail?id=316387 |
33 return false; | 22 return false; |
34 } | 23 } |
35 | 24 |
36 const char kFlags[] = "--use_strict --harmony"; | 25 const char kFlags[] = "--use_strict --harmony"; |
37 | 26 |
38 } | 27 } |
39 | 28 |
40 void InitializeV8() { | 29 void InitializeV8() { |
41 v8::V8::SetArrayBufferAllocator(new ArrayBufferAllocator()); | 30 v8::V8::SetArrayBufferAllocator(js::ArrayBufferAllocator::SharedInstance()); |
42 v8::V8::InitializeICU(); | 31 v8::V8::InitializeICU(); |
43 v8::V8::SetFlagsFromString(kFlags, strlen(kFlags)); | 32 v8::V8::SetFlagsFromString(kFlags, strlen(kFlags)); |
44 v8::V8::SetEntropySource(&GenerateEntropy); | 33 v8::V8::SetEntropySource(&GenerateEntropy); |
45 v8::V8::Initialize(); | 34 v8::V8::Initialize(); |
46 } | 35 } |
47 | 36 |
48 } // namespace apps | 37 } // namespace apps |
49 } // mojo | 38 } // mojo |
OLD | NEW |