blob: f0efc9b6473f89eb26694c895f4b300dc4a1f499 [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
[email protected]36e374082013-12-06 01:51:175#ifndef GIN_PUBLIC_CONTEXT_HOLDER_H_
6#define GIN_PUBLIC_CONTEXT_HOLDER_H_
[email protected]97f21ca2013-11-17 17:46:077
8#include <list>
mostynbc862da82016-04-03 15:54:339#include <memory>
[email protected]855ab432013-11-18 17:09:3610
avi90e658dd2015-12-21 07:16:1911#include "base/macros.h"
[email protected]48c21632013-12-12 21:32:3412#include "gin/gin_export.h"
[email protected]97f21ca2013-11-17 17:46:0713#include "v8/include/v8.h"
14
15namespace gin {
16
[email protected]36e374082013-12-06 01:51:1717// Gin embedder that store embedder data in v8::Contexts must do so in a
18// single field with the index kPerContextDataStartIndex + GinEmbedder-enum.
19// The field at kDebugIdIndex is treated specially by V8 and is reserved for
20// a V8 debugger implementation (not used by gin).
21enum ContextEmbedderDataFields {
yurysea4636e2015-03-20 08:53:5422 kDebugIdIndex = v8::Context::kDebugIdIndex,
[email protected]36e374082013-12-06 01:51:1723 kPerContextDataStartIndex,
24};
25
[email protected]855ab432013-11-18 17:09:3626class PerContextData;
27
[email protected]1771610d2014-02-27 06:08:2428// ContextHolder is a generic class for holding a v8::Context.
[email protected]48c21632013-12-12 21:32:3429class GIN_EXPORT ContextHolder {
[email protected]97f21ca2013-11-17 17:46:0730 public:
31 explicit ContextHolder(v8::Isolate* isolate);
32 ~ContextHolder();
33
34 v8::Isolate* isolate() const { return isolate_; }
35
deepak.sfaaa1b62015-04-30 07:30:4836 v8::Local<v8::Context> context() const {
[email protected]97f21ca2013-11-17 17:46:0737 return v8::Local<v8::Context>::New(isolate_, context_);
38 }
39
deepak.sfaaa1b62015-04-30 07:30:4840 void SetContext(v8::Local<v8::Context> context);
[email protected]97f21ca2013-11-17 17:46:0741
42 private:
43 v8::Isolate* isolate_;
[email protected]e13402e12013-12-17 07:56:5944 v8::UniquePersistent<v8::Context> context_;
mostynbc862da82016-04-03 15:54:3345 std::unique_ptr<PerContextData> data_;
[email protected]97f21ca2013-11-17 17:46:0746
47 DISALLOW_COPY_AND_ASSIGN(ContextHolder);
48};
49
50} // namespace gin
51
[email protected]36e374082013-12-06 01:51:1752#endif // GIN_PUBLIC_CONTEXT_HOLDER_H_