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