[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #include "gin/per_isolate_data.h" | ||||
[email protected] | f04b0e9 | 2013-11-22 14:20:55 | [diff] [blame] | 6 | #include "gin/public/gin_embedders.h" |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 7 | |
8 | using v8::Eternal; | ||||
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 9 | using v8::Isolate; |
10 | using v8::Local; | ||||
11 | using v8::Object; | ||||
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 12 | using v8::FunctionTemplate; |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 13 | using v8::ObjectTemplate; |
14 | |||||
15 | namespace gin { | ||||
16 | |||||
17 | PerIsolateData::PerIsolateData(Isolate* isolate) | ||||
18 | : isolate_(isolate) { | ||||
[email protected] | f04b0e9 | 2013-11-22 14:20:55 | [diff] [blame] | 19 | isolate_->SetData(kEmbedderNativeGin, this); |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 20 | } |
21 | |||||
22 | PerIsolateData::~PerIsolateData() { | ||||
[email protected] | f04b0e9 | 2013-11-22 14:20:55 | [diff] [blame] | 23 | isolate_->SetData(kEmbedderNativeGin, NULL); |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 24 | } |
25 | |||||
26 | PerIsolateData* PerIsolateData::From(Isolate* isolate) { | ||||
[email protected] | f04b0e9 | 2013-11-22 14:20:55 | [diff] [blame] | 27 | return static_cast<PerIsolateData*>(isolate->GetData(kEmbedderNativeGin)); |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 28 | } |
29 | |||||
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 30 | void PerIsolateData::SetObjectTemplate(WrapperInfo* info, |
31 | Local<ObjectTemplate> templ) { | ||||
32 | object_templates_[info] = Eternal<ObjectTemplate>(isolate_, templ); | ||||
33 | } | ||||
34 | |||||
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 35 | void PerIsolateData::SetFunctionTemplate(WrapperInfo* info, |
36 | Local<FunctionTemplate> templ) { | ||||
37 | function_templates_[info] = Eternal<FunctionTemplate>(isolate_, templ); | ||||
38 | } | ||||
39 | |||||
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 40 | v8::Local<v8::ObjectTemplate> PerIsolateData::GetObjectTemplate( |
41 | WrapperInfo* info) { | ||||
42 | ObjectTemplateMap::iterator it = object_templates_.find(info); | ||||
43 | if (it == object_templates_.end()) | ||||
44 | return v8::Local<v8::ObjectTemplate>(); | ||||
45 | return it->second.Get(isolate_); | ||||
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 46 | } |
47 | |||||
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 48 | v8::Local<v8::FunctionTemplate> PerIsolateData::GetFunctionTemplate( |
49 | WrapperInfo* info) { | ||||
50 | FunctionTemplateMap::iterator it = function_templates_.find(info); | ||||
51 | if (it == function_templates_.end()) | ||||
52 | return v8::Local<v8::FunctionTemplate>(); | ||||
53 | return it->second.Get(isolate_); | ||||
54 | } | ||||
55 | |||||
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 56 | } // namespace gin |