blob: 18c230bf112c78f666e333985beaaa67fad2762a [file] [log] [blame]
[email protected]a22998a2013-11-10 05:00:501// 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.
4
5#ifndef GIN_PER_ISOLATE_DATA_H_
6#define GIN_PER_ISOLATE_DATA_H_
7
8#include <map>
9
10#include "base/basictypes.h"
[email protected]48c21632013-12-12 21:32:3411#include "gin/gin_export.h"
[email protected]c07006b2013-11-20 03:01:4412#include "gin/public/wrapper_info.h"
[email protected]a22998a2013-11-10 05:00:5013#include "v8/include/v8.h"
14
15namespace gin {
16
[email protected]60531d52013-11-27 02:10:1517// 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.
[email protected]48c21632013-12-12 21:32:3419class GIN_EXPORT PerIsolateData {
[email protected]a22998a2013-11-10 05:00:5020 public:
[email protected]73dcce92014-02-20 08:24:0421 PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
[email protected]a22998a2013-11-10 05:00:5022 ~PerIsolateData();
23
24 static PerIsolateData* From(v8::Isolate* isolate);
25
[email protected]60531d52013-11-27 02:10:1526 // Each isolate is associated with a collection of v8::ObjectTemplates and
27 // v8::FunctionTemplates. Typically these template objects are created
28 // lazily.
[email protected]e87f3122013-11-12 00:41:2729 void SetObjectTemplate(WrapperInfo* info,
30 v8::Local<v8::ObjectTemplate> object_template);
[email protected]97f21ca2013-11-17 17:46:0731 void SetFunctionTemplate(WrapperInfo* info,
32 v8::Local<v8::FunctionTemplate> function_template);
[email protected]e87f3122013-11-12 00:41:2733
[email protected]60531d52013-11-27 02:10:1534 // 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.
[email protected]e87f3122013-11-12 00:41:2738 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info);
[email protected]97f21ca2013-11-17 17:46:0739 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
[email protected]a22998a2013-11-10 05:00:5040
[email protected]91cd4fe2013-11-28 09:31:5841 v8::Isolate* isolate() { return isolate_; }
[email protected]73dcce92014-02-20 08:24:0442 v8::ArrayBuffer::Allocator* allocator() { return allocator_; }
[email protected]91cd4fe2013-11-28 09:31:5843
[email protected]a22998a2013-11-10 05:00:5044 private:
45 typedef std::map<
46 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap;
[email protected]97f21ca2013-11-17 17:46:0747 typedef std::map<
48 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap;
[email protected]a22998a2013-11-10 05:00:5049
[email protected]60531d52013-11-27 02:10:1550 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
51 // owned by the IsolateHolder, which also owns the PerIsolateData.
[email protected]a22998a2013-11-10 05:00:5052 v8::Isolate* isolate_;
[email protected]73dcce92014-02-20 08:24:0453 v8::ArrayBuffer::Allocator* allocator_;
[email protected]a22998a2013-11-10 05:00:5054 ObjectTemplateMap object_templates_;
[email protected]97f21ca2013-11-17 17:46:0755 FunctionTemplateMap function_templates_;
[email protected]a22998a2013-11-10 05:00:5056
57 DISALLOW_COPY_AND_ASSIGN(PerIsolateData);
58};
59
60} // namespace gin
61
62#endif // GIN_PER_ISOLATE_DATA_H_