Avi Drissman | 468e51b6 | 2022-09-13 20:47:01 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 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_context_data.h" | ||||
6 | |||||
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 7 | #include "gin/public/context_holder.h" |
[email protected] | c07006b | 2013-11-20 03:01:44 | [diff] [blame] | 8 | #include "gin/public/wrapper_info.h" |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 9 | |
10 | namespace gin { | ||||
11 | |||||
[email protected] | 7f12ca7 | 2014-02-28 22:11:53 | [diff] [blame] | 12 | PerContextData::PerContextData(ContextHolder* context_holder, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 13 | v8::Local<v8::Context> context) |
Lukasz Anforowicz | c695e53 | 2020-06-09 02:09:45 | [diff] [blame] | 14 | : context_holder_(context_holder), runner_(nullptr) { |
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 15 | context->SetAlignedPointerInEmbedderData( |
Peter Kasting | a3a48293 | 2022-05-09 19:49:50 | [diff] [blame] | 16 | int{kPerContextDataStartIndex} + kEmbedderNativeGin, this); |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 17 | } |
18 | |||||
19 | PerContextData::~PerContextData() { | ||||
[email protected] | 6d73d2a6 | 2014-03-01 06:45:10 | [diff] [blame] | 20 | context_holder_->context()->SetAlignedPointerInEmbedderData( |
Peter Kasting | a3a48293 | 2022-05-09 19:49:50 | [diff] [blame] | 21 | int{kPerContextDataStartIndex} + kEmbedderNativeGin, NULL); |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 22 | } |
23 | |||||
[email protected] | 1771610d | 2014-02-27 06:08:24 | [diff] [blame] | 24 | // static |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 25 | PerContextData* PerContextData::From(v8::Local<v8::Context> context) { |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 26 | return static_cast<PerContextData*>( |
27 | context->GetAlignedPointerFromEmbedderData(kEncodedValueIndex)); | ||||
28 | } | ||||
29 | |||||
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 30 | } // namespace gin |