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
5#include "gin/per_context_data.h"
6
7#include "base/logging.h"
8#include "gin/public/context_holder.h"
9#include "gin/public/wrapper_info.h"
10
11namespace gin {
12
13PerContextData::PerContextData(ContextHolder* context_holder,
14                               v8::Handle<v8::Context> context)
15    : context_holder_(context_holder),
16      runner_(NULL) {
17  context->SetAlignedPointerInEmbedderData(
18      kPerContextDataStartIndex + kEmbedderNativeGin, this);
19}
20
21PerContextData::~PerContextData() {
22  v8::HandleScope handle_scope(context_holder_->isolate());
23  context_holder_->context()->SetAlignedPointerInEmbedderData(
24      kPerContextDataStartIndex + kEmbedderNativeGin, NULL);
25}
26
27// static
28PerContextData* PerContextData::From(v8::Handle<v8::Context> context) {
29  return static_cast<PerContextData*>(
30      context->GetAlignedPointerFromEmbedderData(kEncodedValueIndex));
31}
32
33}  // namespace gin
34