| 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 #ifndef GIN_PER_ISOLATE_DATA_H_ | 5 #ifndef GIN_PER_ISOLATE_DATA_H_ |
| 6 #define GIN_PER_ISOLATE_DATA_H_ | 6 #define GIN_PER_ISOLATE_DATA_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "gin/gin_export.h" | 11 #include "gin/gin_export.h" |
| 12 #include "gin/public/wrapper_info.h" | 12 #include "gin/public/wrapper_info.h" |
| 13 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
| 14 | 14 |
| 15 namespace gin { | 15 namespace gin { |
| 16 | 16 |
| 17 // There is one instance of PerIsolateData per v8::Isolate managed by Gin. This | 17 // There is one instance of PerIsolateData per v8::Isolate managed by Gin. This |
| 18 // class stores all the Gin-related data that varies per isolate. | 18 // class stores all the Gin-related data that varies per isolate. |
| 19 class GIN_EXPORT PerIsolateData { | 19 class GIN_EXPORT PerIsolateData { |
| 20 public: | 20 public: |
| 21 explicit PerIsolateData(v8::Isolate* isolate); | 21 PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator); |
| 22 ~PerIsolateData(); | 22 ~PerIsolateData(); |
| 23 | 23 |
| 24 static PerIsolateData* From(v8::Isolate* isolate); | 24 static PerIsolateData* From(v8::Isolate* isolate); |
| 25 | 25 |
| 26 // Each isolate is associated with a collection of v8::ObjectTemplates and | 26 // Each isolate is associated with a collection of v8::ObjectTemplates and |
| 27 // v8::FunctionTemplates. Typically these template objects are created | 27 // v8::FunctionTemplates. Typically these template objects are created |
| 28 // lazily. | 28 // lazily. |
| 29 void SetObjectTemplate(WrapperInfo* info, | 29 void SetObjectTemplate(WrapperInfo* info, |
| 30 v8::Local<v8::ObjectTemplate> object_template); | 30 v8::Local<v8::ObjectTemplate> object_template); |
| 31 void SetFunctionTemplate(WrapperInfo* info, | 31 void SetFunctionTemplate(WrapperInfo* info, |
| 32 v8::Local<v8::FunctionTemplate> function_template); | 32 v8::Local<v8::FunctionTemplate> function_template); |
| 33 | 33 |
| 34 // These are low-level functions for retrieving object or function templates | 34 // These are low-level functions for retrieving object or function templates |
| 35 // stored in this object. Because these templates are often created lazily, | 35 // stored in this object. Because these templates are often created lazily, |
| 36 // most clients should call higher-level functions that know how to populate | 36 // most clients should call higher-level functions that know how to populate |
| 37 // these templates if they haven't already been created. | 37 // these templates if they haven't already been created. |
| 38 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info); | 38 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info); |
| 39 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info); | 39 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info); |
| 40 | 40 |
| 41 v8::Isolate* isolate() { return isolate_; } | 41 v8::Isolate* isolate() { return isolate_; } |
| 42 v8::ArrayBuffer::Allocator* allocator() { return allocator_; } |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 typedef std::map< | 45 typedef std::map< |
| 45 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap; | 46 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap; |
| 46 typedef std::map< | 47 typedef std::map< |
| 47 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap; | 48 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap; |
| 48 | 49 |
| 49 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is | 50 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is |
| 50 // owned by the IsolateHolder, which also owns the PerIsolateData. | 51 // owned by the IsolateHolder, which also owns the PerIsolateData. |
| 51 v8::Isolate* isolate_; | 52 v8::Isolate* isolate_; |
| 53 v8::ArrayBuffer::Allocator* allocator_; |
| 52 ObjectTemplateMap object_templates_; | 54 ObjectTemplateMap object_templates_; |
| 53 FunctionTemplateMap function_templates_; | 55 FunctionTemplateMap function_templates_; |
| 54 | 56 |
| 55 DISALLOW_COPY_AND_ASSIGN(PerIsolateData); | 57 DISALLOW_COPY_AND_ASSIGN(PerIsolateData); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 } // namespace gin | 60 } // namespace gin |
| 59 | 61 |
| 60 #endif // GIN_PER_ISOLATE_DATA_H_ | 62 #endif // GIN_PER_ISOLATE_DATA_H_ |
| OLD | NEW |