blob: ab4f049ae2dbf1d80dc239ae6547b7b678cfa674 [file] [log] [blame]
Avi Drissman468e51b62022-09-13 20:47:011// Copyright 2013 The Chromium Authors
abarth@chromium.org97f21ca2013-11-17 17:46:072// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
jochen@chromium.org36e374082013-12-06 01:51:175#include "gin/public/context_holder.h"
abarth@chromium.org97f21ca2013-11-17 17:46:076
Peter Boströmfb60ea02021-04-05 21:06:127#include <memory>
8
Hans Wennborgdcc5ada2020-04-27 13:27:239#include "base/check.h"
abarth@chromium.org97f21ca2013-11-17 17:46:0710#include "gin/per_context_data.h"
11
12namespace gin {
13
14ContextHolder::ContextHolder(v8::Isolate* isolate)
15 : isolate_(isolate) {
16}
17
18ContextHolder::~ContextHolder() {
sky@chromium.orgf2eec2ec2014-02-28 15:26:4919 // PerContextData needs to be destroyed before the context.
abarth@chromium.org855ab432013-11-18 17:09:3620 data_.reset();
abarth@chromium.org97f21ca2013-11-17 17:46:0721}
22
deepak.sfaaa1b62015-04-30 07:30:4823void ContextHolder::SetContext(v8::Local<v8::Context> context) {
abarth@chromium.org855ab432013-11-18 17:09:3624 DCHECK(context_.IsEmpty());
abarth@chromium.org97f21ca2013-11-17 17:46:0725 context_.Reset(isolate_, context);
Michael Lippautz1ab087d2018-03-16 13:43:3926 context_.AnnotateStrongRetainer("gin::ContextHolder::context_");
Peter Boströmfb60ea02021-04-05 21:06:1227 data_ = std::make_unique<PerContextData>(this, context);
abarth@chromium.org97f21ca2013-11-17 17:46:0728}
29
30} // namespace gin