summaryrefslogtreecommitdiffstats
path: root/chromium/gin/context_holder.cc
blob: 23cbc3265583e0c6a9357cdb3fc6c254347d35da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gin/public/context_holder.h"

#include <memory>

#include "base/check.h"
#include "gin/per_context_data.h"

namespace gin {

ContextHolder::ContextHolder(v8::Isolate* isolate)
    : isolate_(isolate) {
}

ContextHolder::~ContextHolder() {
  // PerContextData needs to be destroyed before the context.
  data_.reset();
}

void ContextHolder::SetContext(v8::Local<v8::Context> context) {
  DCHECK(context_.IsEmpty());
  context_.Reset(isolate_, context);
  context_.AnnotateStrongRetainer("gin::ContextHolder::context_");
  data_ = std::make_unique<PerContextData>(this, context);
}

}  // namespace gin