blob: fbdbca7e0e429af4a17c18e95c12530bec2b0356 [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]5c969b82014-03-12 04:59:0517class IndexedPropertyInterceptor;
18class NamedPropertyInterceptor;
19class WrappableBase;
20
[email protected]60531d52013-11-27 02:10:1521// There is one instance of PerIsolateData per v8::Isolate managed by Gin. This
22// class stores all the Gin-related data that varies per isolate.
[email protected]48c21632013-12-12 21:32:3423class GIN_EXPORT PerIsolateData {
[email protected]a22998a2013-11-10 05:00:5024 public:
[email protected]73dcce92014-02-20 08:24:0425 PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
[email protected]a22998a2013-11-10 05:00:5026 ~PerIsolateData();
27
28 static PerIsolateData* From(v8::Isolate* isolate);
29
[email protected]60531d52013-11-27 02:10:1530 // Each isolate is associated with a collection of v8::ObjectTemplates and
31 // v8::FunctionTemplates. Typically these template objects are created
32 // lazily.
[email protected]e87f3122013-11-12 00:41:2733 void SetObjectTemplate(WrapperInfo* info,
34 v8::Local<v8::ObjectTemplate> object_template);
[email protected]97f21ca2013-11-17 17:46:0735 void SetFunctionTemplate(WrapperInfo* info,
36 v8::Local<v8::FunctionTemplate> function_template);
[email protected]e87f3122013-11-12 00:41:2737
[email protected]60531d52013-11-27 02:10:1538 // These are low-level functions for retrieving object or function templates
39 // stored in this object. Because these templates are often created lazily,
40 // most clients should call higher-level functions that know how to populate
41 // these templates if they haven't already been created.
[email protected]e87f3122013-11-12 00:41:2742 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info);
[email protected]97f21ca2013-11-17 17:46:0743 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
[email protected]a22998a2013-11-10 05:00:5044
[email protected]5c969b82014-03-12 04:59:0545 // We maintain a map from Wrappable objects that derive from one of the
46 // interceptor interfaces to the interceptor interface pointers.
47 void SetIndexedPropertyInterceptor(WrappableBase* base,
48 IndexedPropertyInterceptor* interceptor);
49 void SetNamedPropertyInterceptor(WrappableBase* base,
50 NamedPropertyInterceptor* interceptor);
51
52 void ClearIndexedPropertyInterceptor(WrappableBase* base,
53 IndexedPropertyInterceptor* interceptor);
54 void ClearNamedPropertyInterceptor(WrappableBase* base,
55 NamedPropertyInterceptor* interceptor);
56
57 IndexedPropertyInterceptor* GetIndexedPropertyInterceptor(
58 WrappableBase* base);
59 NamedPropertyInterceptor* GetNamedPropertyInterceptor(WrappableBase* base);
60
[email protected]91cd4fe2013-11-28 09:31:5861 v8::Isolate* isolate() { return isolate_; }
[email protected]73dcce92014-02-20 08:24:0462 v8::ArrayBuffer::Allocator* allocator() { return allocator_; }
[email protected]91cd4fe2013-11-28 09:31:5863
[email protected]a22998a2013-11-10 05:00:5064 private:
65 typedef std::map<
66 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap;
[email protected]97f21ca2013-11-17 17:46:0767 typedef std::map<
68 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap;
[email protected]5c969b82014-03-12 04:59:0569 typedef std::map<WrappableBase*, IndexedPropertyInterceptor*>
70 IndexedPropertyInterceptorMap;
71 typedef std::map<WrappableBase*, NamedPropertyInterceptor*>
72 NamedPropertyInterceptorMap;
[email protected]a22998a2013-11-10 05:00:5073
[email protected]60531d52013-11-27 02:10:1574 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
75 // owned by the IsolateHolder, which also owns the PerIsolateData.
[email protected]a22998a2013-11-10 05:00:5076 v8::Isolate* isolate_;
[email protected]73dcce92014-02-20 08:24:0477 v8::ArrayBuffer::Allocator* allocator_;
[email protected]a22998a2013-11-10 05:00:5078 ObjectTemplateMap object_templates_;
[email protected]97f21ca2013-11-17 17:46:0779 FunctionTemplateMap function_templates_;
[email protected]5c969b82014-03-12 04:59:0580 IndexedPropertyInterceptorMap indexed_interceptors_;
81 NamedPropertyInterceptorMap named_interceptors_;
[email protected]a22998a2013-11-10 05:00:5082
83 DISALLOW_COPY_AND_ASSIGN(PerIsolateData);
84};
85
86} // namespace gin
87
88#endif // GIN_PER_ISOLATE_DATA_H_