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
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "base/message_loop/message_loop_proxy.h"
7 #include "gin/per_isolate_data.h"
8 #include "gin/public/gin_embedders.h"
10 using v8::ArrayBuffer
;
15 using v8::FunctionTemplate
;
16 using v8::ObjectTemplate
;
20 PerIsolateData::PerIsolateData(Isolate
* isolate
,
21 ArrayBuffer::Allocator
* allocator
)
23 allocator_(allocator
),
24 message_loop_proxy_(base::MessageLoopProxy::current()) {
25 isolate_
->SetData(kEmbedderNativeGin
, this);
28 PerIsolateData::~PerIsolateData() {
29 isolate_
->SetData(kEmbedderNativeGin
, NULL
);
32 PerIsolateData
* PerIsolateData::From(Isolate
* isolate
) {
33 return static_cast<PerIsolateData
*>(isolate
->GetData(kEmbedderNativeGin
));
36 void PerIsolateData::SetObjectTemplate(WrapperInfo
* info
,
37 Local
<ObjectTemplate
> templ
) {
38 object_templates_
[info
] = Eternal
<ObjectTemplate
>(isolate_
, templ
);
41 void PerIsolateData::SetFunctionTemplate(WrapperInfo
* info
,
42 Local
<FunctionTemplate
> templ
) {
43 function_templates_
[info
] = Eternal
<FunctionTemplate
>(isolate_
, templ
);
46 v8::Local
<v8::ObjectTemplate
> PerIsolateData::GetObjectTemplate(
48 ObjectTemplateMap::iterator it
= object_templates_
.find(info
);
49 if (it
== object_templates_
.end())
50 return v8::Local
<v8::ObjectTemplate
>();
51 return it
->second
.Get(isolate_
);
54 v8::Local
<v8::FunctionTemplate
> PerIsolateData::GetFunctionTemplate(
56 FunctionTemplateMap::iterator it
= function_templates_
.find(info
);
57 if (it
== function_templates_
.end())
58 return v8::Local
<v8::FunctionTemplate
>();
59 return it
->second
.Get(isolate_
);
62 void PerIsolateData::SetIndexedPropertyInterceptor(
64 IndexedPropertyInterceptor
* interceptor
) {
65 indexed_interceptors_
[base
] = interceptor
;
68 void PerIsolateData::SetNamedPropertyInterceptor(
70 NamedPropertyInterceptor
* interceptor
) {
71 named_interceptors_
[base
] = interceptor
;
74 void PerIsolateData::ClearIndexedPropertyInterceptor(
76 IndexedPropertyInterceptor
* interceptor
) {
77 IndexedPropertyInterceptorMap::iterator it
= indexed_interceptors_
.find(base
);
78 if (it
!= indexed_interceptors_
.end())
79 indexed_interceptors_
.erase(it
);
84 void PerIsolateData::ClearNamedPropertyInterceptor(
86 NamedPropertyInterceptor
* interceptor
) {
87 NamedPropertyInterceptorMap::iterator it
= named_interceptors_
.find(base
);
88 if (it
!= named_interceptors_
.end())
89 named_interceptors_
.erase(it
);
94 IndexedPropertyInterceptor
* PerIsolateData::GetIndexedPropertyInterceptor(
95 WrappableBase
* base
) {
96 IndexedPropertyInterceptorMap::iterator it
= indexed_interceptors_
.find(base
);
97 if (it
!= indexed_interceptors_
.end())
103 NamedPropertyInterceptor
* PerIsolateData::GetNamedPropertyInterceptor(
104 WrappableBase
* base
) {
105 NamedPropertyInterceptorMap::iterator it
= named_interceptors_
.find(base
);
106 if (it
!= named_interceptors_
.end())