[email protected] | 97f21ca | 2013-11-17 17:46:07 | [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 | |||||
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 5 | #include "gin/public/context_holder.h" |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 6 | |
Peter Boström | fb60ea0 | 2021-04-05 21:06:12 | [diff] [blame] | 7 | #include <memory> |
8 | |||||
Hans Wennborg | dcc5ada | 2020-04-27 13:27:23 | [diff] [blame] | 9 | #include "base/check.h" |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 10 | #include "gin/per_context_data.h" |
11 | |||||
12 | namespace gin { | ||||
13 | |||||
14 | ContextHolder::ContextHolder(v8::Isolate* isolate) | ||||
15 | : isolate_(isolate) { | ||||
16 | } | ||||
17 | |||||
18 | ContextHolder::~ContextHolder() { | ||||
[email protected] | f2eec2ec | 2014-02-28 15:26:49 | [diff] [blame] | 19 | // PerContextData needs to be destroyed before the context. |
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 20 | data_.reset(); |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 21 | } |
22 | |||||
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 23 | void ContextHolder::SetContext(v8::Local<v8::Context> context) { |
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 24 | DCHECK(context_.IsEmpty()); |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 25 | context_.Reset(isolate_, context); |
Michael Lippautz | 1ab087d | 2018-03-16 13:43:39 | [diff] [blame] | 26 | context_.AnnotateStrongRetainer("gin::ContextHolder::context_"); |
Peter Boström | fb60ea0 | 2021-04-05 21:06:12 | [diff] [blame] | 27 | data_ = std::make_unique<PerContextData>(this, context); |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 28 | } |
29 | |||||
30 | } // namespace gin |