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
3 // found in the LICENSE file.
5 #ifndef GIN_PER_ISOLATE_DATA_H_
6 #define GIN_PER_ISOLATE_DATA_H_
10 #include "base/basictypes.h"
11 #include "gin/gin_export.h"
12 #include "gin/public/wrapper_info.h"
13 #include "v8/include/v8.h"
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.
19 class GIN_EXPORT PerIsolateData
{
21 PerIsolateData(v8::Isolate
* isolate
, v8::ArrayBuffer::Allocator
* allocator
);
24 static PerIsolateData
* From(v8::Isolate
* isolate
);
26 // Each isolate is associated with a collection of v8::ObjectTemplates and
27 // v8::FunctionTemplates. Typically these template objects are created
29 void SetObjectTemplate(WrapperInfo
* info
,
30 v8::Local
<v8::ObjectTemplate
> object_template
);
31 void SetFunctionTemplate(WrapperInfo
* info
,
32 v8::Local
<v8::FunctionTemplate
> function_template
);
34 // These are low-level functions for retrieving object or function templates
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
37 // these templates if they haven't already been created.
38 v8::Local
<v8::ObjectTemplate
> GetObjectTemplate(WrapperInfo
* info
);
39 v8::Local
<v8::FunctionTemplate
> GetFunctionTemplate(WrapperInfo
* info
);
41 v8::Isolate
* isolate() { return isolate_
; }
42 v8::ArrayBuffer::Allocator
* allocator() { return allocator_
; }
46 WrapperInfo
*, v8::Eternal
<v8::ObjectTemplate
> > ObjectTemplateMap
;
48 WrapperInfo
*, v8::Eternal
<v8::FunctionTemplate
> > FunctionTemplateMap
;
50 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
51 // owned by the IsolateHolder, which also owns the PerIsolateData.
52 v8::Isolate
* isolate_
;
53 v8::ArrayBuffer::Allocator
* allocator_
;
54 ObjectTemplateMap object_templates_
;
55 FunctionTemplateMap function_templates_
;
57 DISALLOW_COPY_AND_ASSIGN(PerIsolateData
);
62 #endif // GIN_PER_ISOLATE_DATA_H_