Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: gin/per_isolate_data.h

Issue 194603003: gin: Add the concept of named and indexed interceptors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gin/object_template_builder.cc ('k') | gin/per_isolate_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GIN_PER_ISOLATE_DATA_H_ 5 #ifndef GIN_PER_ISOLATE_DATA_H_
6 #define GIN_PER_ISOLATE_DATA_H_ 6 #define GIN_PER_ISOLATE_DATA_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "gin/gin_export.h" 11 #include "gin/gin_export.h"
12 #include "gin/public/wrapper_info.h" 12 #include "gin/public/wrapper_info.h"
13 #include "v8/include/v8.h" 13 #include "v8/include/v8.h"
14 14
15 namespace gin { 15 namespace gin {
16 16
17 class IndexedPropertyInterceptor;
18 class NamedPropertyInterceptor;
19 class WrappableBase;
20
17 // There is one instance of PerIsolateData per v8::Isolate managed by Gin. This 21 // 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. 22 // class stores all the Gin-related data that varies per isolate.
19 class GIN_EXPORT PerIsolateData { 23 class GIN_EXPORT PerIsolateData {
20 public: 24 public:
21 PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator); 25 PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
22 ~PerIsolateData(); 26 ~PerIsolateData();
23 27
24 static PerIsolateData* From(v8::Isolate* isolate); 28 static PerIsolateData* From(v8::Isolate* isolate);
25 29
26 // Each isolate is associated with a collection of v8::ObjectTemplates and 30 // Each isolate is associated with a collection of v8::ObjectTemplates and
27 // v8::FunctionTemplates. Typically these template objects are created 31 // v8::FunctionTemplates. Typically these template objects are created
28 // lazily. 32 // lazily.
29 void SetObjectTemplate(WrapperInfo* info, 33 void SetObjectTemplate(WrapperInfo* info,
30 v8::Local<v8::ObjectTemplate> object_template); 34 v8::Local<v8::ObjectTemplate> object_template);
31 void SetFunctionTemplate(WrapperInfo* info, 35 void SetFunctionTemplate(WrapperInfo* info,
32 v8::Local<v8::FunctionTemplate> function_template); 36 v8::Local<v8::FunctionTemplate> function_template);
33 37
34 // These are low-level functions for retrieving object or function templates 38 // These are low-level functions for retrieving object or function templates
35 // stored in this object. Because these templates are often created lazily, 39 // stored in this object. Because these templates are often created lazily,
36 // most clients should call higher-level functions that know how to populate 40 // most clients should call higher-level functions that know how to populate
37 // these templates if they haven't already been created. 41 // these templates if they haven't already been created.
38 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info); 42 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info);
39 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info); 43 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
40 44
45 // 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
41 v8::Isolate* isolate() { return isolate_; } 61 v8::Isolate* isolate() { return isolate_; }
42 v8::ArrayBuffer::Allocator* allocator() { return allocator_; } 62 v8::ArrayBuffer::Allocator* allocator() { return allocator_; }
43 63
44 private: 64 private:
45 typedef std::map< 65 typedef std::map<
46 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap; 66 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap;
47 typedef std::map< 67 typedef std::map<
48 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap; 68 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap;
69 typedef std::map<WrappableBase*, IndexedPropertyInterceptor*>
70 IndexedPropertyInterceptorMap;
71 typedef std::map<WrappableBase*, NamedPropertyInterceptor*>
72 NamedPropertyInterceptorMap;
49 73
50 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is 74 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
51 // owned by the IsolateHolder, which also owns the PerIsolateData. 75 // owned by the IsolateHolder, which also owns the PerIsolateData.
52 v8::Isolate* isolate_; 76 v8::Isolate* isolate_;
53 v8::ArrayBuffer::Allocator* allocator_; 77 v8::ArrayBuffer::Allocator* allocator_;
54 ObjectTemplateMap object_templates_; 78 ObjectTemplateMap object_templates_;
55 FunctionTemplateMap function_templates_; 79 FunctionTemplateMap function_templates_;
80 IndexedPropertyInterceptorMap indexed_interceptors_;
81 NamedPropertyInterceptorMap named_interceptors_;
56 82
57 DISALLOW_COPY_AND_ASSIGN(PerIsolateData); 83 DISALLOW_COPY_AND_ASSIGN(PerIsolateData);
58 }; 84 };
59 85
60 } // namespace gin 86 } // namespace gin
61 87
62 #endif // GIN_PER_ISOLATE_DATA_H_ 88 #endif // GIN_PER_ISOLATE_DATA_H_
OLDNEW
« no previous file with comments | « gin/object_template_builder.cc ('k') | gin/per_isolate_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698