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/single_thread_task_runner.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "gin/per_isolate_data.h"
9 #include "gin/public/gin_embedders.h"
11 using v8::ArrayBuffer
;
16 using v8::FunctionTemplate
;
17 using v8::ObjectTemplate
;
21 PerIsolateData::PerIsolateData(Isolate
* isolate
,
22 ArrayBuffer::Allocator
* allocator
)
24 allocator_(allocator
),
25 task_runner_(base::ThreadTaskRunnerHandle::Get()) {
26 isolate_
->SetData(kEmbedderNativeGin
, this);
29 PerIsolateData::~PerIsolateData() {
30 isolate_
->SetData(kEmbedderNativeGin
, NULL
);
33 PerIsolateData
* PerIsolateData::From(Isolate
* isolate
) {
34 return static_cast<PerIsolateData
*>(isolate
->GetData(kEmbedderNativeGin
));
37 void PerIsolateData::SetObjectTemplate(WrapperInfo
* info
,
38 Local
<ObjectTemplate
> templ
) {
39 object_templates_
[info
] = Eternal
<ObjectTemplate
>(isolate_
, templ
);
42 void PerIsolateData::SetFunctionTemplate(WrapperInfo
* info
,
43 Local
<FunctionTemplate
> templ
) {
44 function_templates_
[info
] = Eternal
<FunctionTemplate
>(isolate_
, templ
);
47 v8::Local
<v8::ObjectTemplate
> PerIsolateData::GetObjectTemplate(
49 ObjectTemplateMap::iterator it
= object_templates_
.find(info
);
50 if (it
== object_templates_
.end())
51 return v8::Local
<v8::ObjectTemplate
>();
52 return it
->second
.Get(isolate_
);
55 v8::Local
<v8::FunctionTemplate
> PerIsolateData::GetFunctionTemplate(
57 FunctionTemplateMap::iterator it
= function_templates_
.find(info
);
58 if (it
== function_templates_
.end())
59 return v8::Local
<v8::FunctionTemplate
>();
60 return it
->second
.Get(isolate_
);
63 void PerIsolateData::SetIndexedPropertyInterceptor(
65 IndexedPropertyInterceptor
* interceptor
) {
66 indexed_interceptors_
[base
] = interceptor
;
69 void PerIsolateData::SetNamedPropertyInterceptor(
71 NamedPropertyInterceptor
* interceptor
) {
72 named_interceptors_
[base
] = interceptor
;
75 void PerIsolateData::ClearIndexedPropertyInterceptor(
77 IndexedPropertyInterceptor
* interceptor
) {
78 IndexedPropertyInterceptorMap::iterator it
= indexed_interceptors_
.find(base
);
79 if (it
!= indexed_interceptors_
.end())
80 indexed_interceptors_
.erase(it
);
85 void PerIsolateData::ClearNamedPropertyInterceptor(
87 NamedPropertyInterceptor
* interceptor
) {
88 NamedPropertyInterceptorMap::iterator it
= named_interceptors_
.find(base
);
89 if (it
!= named_interceptors_
.end())
90 named_interceptors_
.erase(it
);
95 IndexedPropertyInterceptor
* PerIsolateData::GetIndexedPropertyInterceptor(
96 WrappableBase
* base
) {
97 IndexedPropertyInterceptorMap::iterator it
= indexed_interceptors_
.find(base
);
98 if (it
!= indexed_interceptors_
.end())
104 NamedPropertyInterceptor
* PerIsolateData::GetNamedPropertyInterceptor(
105 WrappableBase
* base
) {
106 NamedPropertyInterceptorMap::iterator it
= named_interceptors_
.find(base
);
107 if (it
!= named_interceptors_
.end())