blob: 9b804aa4ba5d885dc96d3d0d903f430ab7dfae1f [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>
mostynbc862da82016-04-03 15:54:339#include <memory>
[email protected]a22998a2013-11-10 05:00:5010
avi90e658dd2015-12-21 07:16:1911#include "base/macros.h"
[email protected]b64e5212014-04-04 21:09:1612#include "base/memory/ref_counted.h"
[email protected]48c21632013-12-12 21:32:3413#include "gin/gin_export.h"
ulan3cbdcd02015-07-20 11:32:5814#include "gin/public/v8_idle_task_runner.h"
[email protected]c07006b2013-11-20 03:01:4415#include "gin/public/wrapper_info.h"
[email protected]a22998a2013-11-10 05:00:5016#include "v8/include/v8.h"
17
[email protected]b64e5212014-04-04 21:09:1618namespace base {
skyostila3899862015-06-12 18:21:5819class SingleThreadTaskRunner;
[email protected]b64e5212014-04-04 21:09:1620}
21
[email protected]a22998a2013-11-10 05:00:5022namespace gin {
23
[email protected]5c969b82014-03-12 04:59:0524class IndexedPropertyInterceptor;
25class NamedPropertyInterceptor;
26class WrappableBase;
27
[email protected]60531d52013-11-27 02:10:1528// There is one instance of PerIsolateData per v8::Isolate managed by Gin. This
29// class stores all the Gin-related data that varies per isolate.
[email protected]48c21632013-12-12 21:32:3430class GIN_EXPORT PerIsolateData {
[email protected]a22998a2013-11-10 05:00:5031 public:
[email protected]73dcce92014-02-20 08:24:0432 PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
[email protected]a22998a2013-11-10 05:00:5033 ~PerIsolateData();
34
35 static PerIsolateData* From(v8::Isolate* isolate);
36
[email protected]60531d52013-11-27 02:10:1537 // Each isolate is associated with a collection of v8::ObjectTemplates and
38 // v8::FunctionTemplates. Typically these template objects are created
39 // lazily.
[email protected]e87f3122013-11-12 00:41:2740 void SetObjectTemplate(WrapperInfo* info,
41 v8::Local<v8::ObjectTemplate> object_template);
[email protected]97f21ca2013-11-17 17:46:0742 void SetFunctionTemplate(WrapperInfo* info,
43 v8::Local<v8::FunctionTemplate> function_template);
[email protected]e87f3122013-11-12 00:41:2744
[email protected]60531d52013-11-27 02:10:1545 // These are low-level functions for retrieving object or function templates
46 // stored in this object. Because these templates are often created lazily,
47 // most clients should call higher-level functions that know how to populate
48 // these templates if they haven't already been created.
[email protected]e87f3122013-11-12 00:41:2749 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info);
[email protected]97f21ca2013-11-17 17:46:0750 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
[email protected]a22998a2013-11-10 05:00:5051
[email protected]5c969b82014-03-12 04:59:0552 // We maintain a map from Wrappable objects that derive from one of the
53 // interceptor interfaces to the interceptor interface pointers.
54 void SetIndexedPropertyInterceptor(WrappableBase* base,
55 IndexedPropertyInterceptor* interceptor);
56 void SetNamedPropertyInterceptor(WrappableBase* base,
57 NamedPropertyInterceptor* interceptor);
58
59 void ClearIndexedPropertyInterceptor(WrappableBase* base,
60 IndexedPropertyInterceptor* interceptor);
61 void ClearNamedPropertyInterceptor(WrappableBase* base,
62 NamedPropertyInterceptor* interceptor);
63
64 IndexedPropertyInterceptor* GetIndexedPropertyInterceptor(
65 WrappableBase* base);
66 NamedPropertyInterceptor* GetNamedPropertyInterceptor(WrappableBase* base);
67
mostynbc862da82016-04-03 15:54:3368 void EnableIdleTasks(std::unique_ptr<V8IdleTaskRunner> idle_task_runner);
ulan3cbdcd02015-07-20 11:32:5869
[email protected]91cd4fe2013-11-28 09:31:5870 v8::Isolate* isolate() { return isolate_; }
[email protected]73dcce92014-02-20 08:24:0471 v8::ArrayBuffer::Allocator* allocator() { return allocator_; }
skyostila3899862015-06-12 18:21:5872 base::SingleThreadTaskRunner* task_runner() { return task_runner_.get(); }
ulan3cbdcd02015-07-20 11:32:5873 V8IdleTaskRunner* idle_task_runner() {
74 return idle_task_runner_.get();
75 }
[email protected]91cd4fe2013-11-28 09:31:5876
[email protected]a22998a2013-11-10 05:00:5077 private:
78 typedef std::map<
79 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap;
[email protected]97f21ca2013-11-17 17:46:0780 typedef std::map<
81 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap;
[email protected]5c969b82014-03-12 04:59:0582 typedef std::map<WrappableBase*, IndexedPropertyInterceptor*>
83 IndexedPropertyInterceptorMap;
84 typedef std::map<WrappableBase*, NamedPropertyInterceptor*>
85 NamedPropertyInterceptorMap;
[email protected]a22998a2013-11-10 05:00:5086
[email protected]60531d52013-11-27 02:10:1587 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
88 // owned by the IsolateHolder, which also owns the PerIsolateData.
[email protected]a22998a2013-11-10 05:00:5089 v8::Isolate* isolate_;
[email protected]73dcce92014-02-20 08:24:0490 v8::ArrayBuffer::Allocator* allocator_;
[email protected]a22998a2013-11-10 05:00:5091 ObjectTemplateMap object_templates_;
[email protected]97f21ca2013-11-17 17:46:0792 FunctionTemplateMap function_templates_;
[email protected]5c969b82014-03-12 04:59:0593 IndexedPropertyInterceptorMap indexed_interceptors_;
94 NamedPropertyInterceptorMap named_interceptors_;
skyostila3899862015-06-12 18:21:5895 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
mostynbc862da82016-04-03 15:54:3396 std::unique_ptr<V8IdleTaskRunner> idle_task_runner_;
[email protected]a22998a2013-11-10 05:00:5097
98 DISALLOW_COPY_AND_ASSIGN(PerIsolateData);
99};
100
101} // namespace gin
102
103#endif // GIN_PER_ISOLATE_DATA_H_