| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef GIN_PUBLIC_CONTEXT_HOLDER_H_ | 5 #ifndef GIN_PUBLIC_CONTEXT_HOLDER_H_ | 
| 6 #define GIN_PUBLIC_CONTEXT_HOLDER_H_ | 6 #define GIN_PUBLIC_CONTEXT_HOLDER_H_ | 
| 7 | 7 | 
| 8 #include <list> | 8 #include <list> | 
| 9 | 9 | 
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" | 
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" | 
|  | 12 #include "gin/gin_export.h" | 
| 12 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" | 
| 13 | 14 | 
| 14 namespace gin { | 15 namespace gin { | 
| 15 | 16 | 
| 16 // Gin embedder that store embedder data in v8::Contexts must do so in a | 17 // Gin embedder that store embedder data in v8::Contexts must do so in a | 
| 17 // single field with the index kPerContextDataStartIndex + GinEmbedder-enum. | 18 // single field with the index kPerContextDataStartIndex + GinEmbedder-enum. | 
| 18 // The field at kDebugIdIndex is treated specially by V8 and is reserved for | 19 // The field at kDebugIdIndex is treated specially by V8 and is reserved for | 
| 19 // a V8 debugger implementation (not used by gin). | 20 // a V8 debugger implementation (not used by gin). | 
| 20 enum ContextEmbedderDataFields { | 21 enum ContextEmbedderDataFields { | 
| 21   kDebugIdIndex = 0, | 22   kDebugIdIndex = 0, | 
| 22   kPerContextDataStartIndex, | 23   kPerContextDataStartIndex, | 
| 23 }; | 24 }; | 
| 24 | 25 | 
| 25 class PerContextData; | 26 class PerContextData; | 
| 26 | 27 | 
| 27 // ContextHolder is a generic class for holding a v8::Context. Rather than | 28 // ContextHolder is a generic class for holding a v8::Context. Rather than | 
| 28 // using ContextHolder directly, most code should use a subclass of | 29 // using ContextHolder directly, most code should use a subclass of | 
| 29 // ContextHolder, such as Runner. | 30 // ContextHolder, such as Runner. | 
| 30 class ContextHolder { | 31 class GIN_EXPORT ContextHolder { | 
| 31  public: | 32  public: | 
| 32   explicit ContextHolder(v8::Isolate* isolate); | 33   explicit ContextHolder(v8::Isolate* isolate); | 
| 33   ~ContextHolder(); | 34   ~ContextHolder(); | 
| 34 | 35 | 
| 35   v8::Isolate* isolate() const { return isolate_; } | 36   v8::Isolate* isolate() const { return isolate_; } | 
| 36 | 37 | 
| 37   v8::Handle<v8::Context> context() const { | 38   v8::Handle<v8::Context> context() const { | 
| 38     return v8::Local<v8::Context>::New(isolate_, context_); | 39     return v8::Local<v8::Context>::New(isolate_, context_); | 
| 39   } | 40   } | 
| 40 | 41 | 
| 41   void SetContext(v8::Handle<v8::Context> context); | 42   void SetContext(v8::Handle<v8::Context> context); | 
| 42 | 43 | 
| 43  private: | 44  private: | 
| 44   v8::Isolate* isolate_; | 45   v8::Isolate* isolate_; | 
| 45   v8::Persistent<v8::Context> context_; | 46   v8::Persistent<v8::Context> context_; | 
| 46   scoped_ptr<PerContextData> data_; | 47   scoped_ptr<PerContextData> data_; | 
| 47 | 48 | 
| 48   DISALLOW_COPY_AND_ASSIGN(ContextHolder); | 49   DISALLOW_COPY_AND_ASSIGN(ContextHolder); | 
| 49 }; | 50 }; | 
| 50 | 51 | 
| 51 }  // namespace gin | 52 }  // namespace gin | 
| 52 | 53 | 
| 53 #endif  // GIN_PUBLIC_CONTEXT_HOLDER_H_ | 54 #endif  // GIN_PUBLIC_CONTEXT_HOLDER_H_ | 
| OLD | NEW | 
|---|