blob: 8185d3fd1bc2a402c3e777c2b3feedf3860ed04b [file] [log] [blame]
[email protected]97f21ca2013-11-17 17:46:071// 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_context_data.h"
6
[email protected]855ab432013-11-18 17:09:367#include "base/logging.h"
[email protected]36e374082013-12-06 01:51:178#include "gin/public/context_holder.h"
[email protected]c07006b2013-11-20 03:01:449#include "gin/public/wrapper_info.h"
[email protected]97f21ca2013-11-17 17:46:0710
11namespace gin {
12
[email protected]7f12ca72014-02-28 22:11:5313PerContextData::PerContextData(ContextHolder* context_holder,
deepak.sfaaa1b62015-04-30 07:30:4814 v8::Local<v8::Context> context)
[email protected]7f12ca72014-02-28 22:11:5315 : context_holder_(context_holder),
16 runner_(NULL) {
[email protected]36e374082013-12-06 01:51:1717 context->SetAlignedPointerInEmbedderData(
18 kPerContextDataStartIndex + kEmbedderNativeGin, this);
[email protected]97f21ca2013-11-17 17:46:0719}
20
21PerContextData::~PerContextData() {
[email protected]6d73d2a62014-03-01 06:45:1022 v8::HandleScope handle_scope(context_holder_->isolate());
23 context_holder_->context()->SetAlignedPointerInEmbedderData(
24 kPerContextDataStartIndex + kEmbedderNativeGin, NULL);
[email protected]97f21ca2013-11-17 17:46:0725}
26
[email protected]1771610d2014-02-27 06:08:2427// static
deepak.sfaaa1b62015-04-30 07:30:4828PerContextData* PerContextData::From(v8::Local<v8::Context> context) {
[email protected]97f21ca2013-11-17 17:46:0729 return static_cast<PerContextData*>(
30 context->GetAlignedPointerFromEmbedderData(kEncodedValueIndex));
31}
32
[email protected]97f21ca2013-11-17 17:46:0733} // namespace gin