blob: bffe5fb2c6f6e6c4a420171c6a5d8b74b676429e [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]b64e5212014-04-04 21:09:1611#include "base/memory/ref_counted.h"
[email protected]48c21632013-12-12 21:32:3412#include "gin/gin_export.h"
[email protected]c07006b2013-11-20 03:01:4413#include "gin/public/wrapper_info.h"
[email protected]a22998a2013-11-10 05:00:5014#include "v8/include/v8.h"
15
[email protected]b64e5212014-04-04 21:09:1616namespace base {
17class MessageLoopProxy;
18}
19
[email protected]a22998a2013-11-10 05:00:5020namespace gin {
21
[email protected]5c969b82014-03-12 04:59:0522class IndexedPropertyInterceptor;
23class NamedPropertyInterceptor;
24class WrappableBase;
25
[email protected]60531d52013-11-27 02:10:1526// There is one instance of PerIsolateData per v8::Isolate managed by Gin. This
27// class stores all the Gin-related data that varies per isolate.
[email protected]48c21632013-12-12 21:32:3428class GIN_EXPORT PerIsolateData {
[email protected]a22998a2013-11-10 05:00:5029 public:
[email protected]73dcce92014-02-20 08:24:0430 PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
[email protected]a22998a2013-11-10 05:00:5031 ~PerIsolateData();
32
33 static PerIsolateData* From(v8::Isolate* isolate);
34
[email protected]60531d52013-11-27 02:10:1535 // Each isolate is associated with a collection of v8::ObjectTemplates and
36 // v8::FunctionTemplates. Typically these template objects are created
37 // lazily.
[email protected]e87f3122013-11-12 00:41:2738 void SetObjectTemplate(WrapperInfo* info,
39 v8::Local<v8::ObjectTemplate> object_template);
[email protected]97f21ca2013-11-17 17:46:0740 void SetFunctionTemplate(WrapperInfo* info,
41 v8::Local<v8::FunctionTemplate> function_template);
[email protected]e87f3122013-11-12 00:41:2742
[email protected]60531d52013-11-27 02:10:1543 // These are low-level functions for retrieving object or function templates
44 // stored in this object. Because these templates are often created lazily,
45 // most clients should call higher-level functions that know how to populate
46 // these templates if they haven't already been created.
[email protected]e87f3122013-11-12 00:41:2747 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info);
[email protected]97f21ca2013-11-17 17:46:0748 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
[email protected]a22998a2013-11-10 05:00:5049
[email protected]5c969b82014-03-12 04:59:0550 // We maintain a map from Wrappable objects that derive from one of the
51 // interceptor interfaces to the interceptor interface pointers.
52 void SetIndexedPropertyInterceptor(WrappableBase* base,
53 IndexedPropertyInterceptor* interceptor);
54 void SetNamedPropertyInterceptor(WrappableBase* base,
55 NamedPropertyInterceptor* interceptor);
56
57 void ClearIndexedPropertyInterceptor(WrappableBase* base,
58 IndexedPropertyInterceptor* interceptor);
59 void ClearNamedPropertyInterceptor(WrappableBase* base,
60 NamedPropertyInterceptor* interceptor);
61
62 IndexedPropertyInterceptor* GetIndexedPropertyInterceptor(
63 WrappableBase* base);
64 NamedPropertyInterceptor* GetNamedPropertyInterceptor(WrappableBase* base);
65
[email protected]91cd4fe2013-11-28 09:31:5866 v8::Isolate* isolate() { return isolate_; }
[email protected]73dcce92014-02-20 08:24:0467 v8::ArrayBuffer::Allocator* allocator() { return allocator_; }
[email protected]b64e5212014-04-04 21:09:1668 base::MessageLoopProxy* message_loop_proxy() {
69 return message_loop_proxy_.get();
70 }
[email protected]91cd4fe2013-11-28 09:31:5871
[email protected]a22998a2013-11-10 05:00:5072 private:
73 typedef std::map<
74 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap;
[email protected]97f21ca2013-11-17 17:46:0775 typedef std::map<
76 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap;
[email protected]5c969b82014-03-12 04:59:0577 typedef std::map<WrappableBase*, IndexedPropertyInterceptor*>
78 IndexedPropertyInterceptorMap;
79 typedef std::map<WrappableBase*, NamedPropertyInterceptor*>
80 NamedPropertyInterceptorMap;
[email protected]a22998a2013-11-10 05:00:5081
[email protected]60531d52013-11-27 02:10:1582 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
83 // owned by the IsolateHolder, which also owns the PerIsolateData.
[email protected]a22998a2013-11-10 05:00:5084 v8::Isolate* isolate_;
[email protected]73dcce92014-02-20 08:24:0485 v8::ArrayBuffer::Allocator* allocator_;
[email protected]a22998a2013-11-10 05:00:5086 ObjectTemplateMap object_templates_;
[email protected]97f21ca2013-11-17 17:46:0787 FunctionTemplateMap function_templates_;
[email protected]5c969b82014-03-12 04:59:0588 IndexedPropertyInterceptorMap indexed_interceptors_;
89 NamedPropertyInterceptorMap named_interceptors_;
[email protected]b64e5212014-04-04 21:09:1690 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
[email protected]a22998a2013-11-10 05:00:5091
92 DISALLOW_COPY_AND_ASSIGN(PerIsolateData);
93};
94
95} // namespace gin
96
97#endif // GIN_PER_ISOLATE_DATA_H_