OLD | NEW |
(Empty) | |
| 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 <assert.h> |
| 8 #include "gin/wrapper_info.h" |
| 9 |
| 10 namespace gin { |
| 11 |
| 12 ContextSupplement::ContextSupplement() { |
| 13 } |
| 14 |
| 15 ContextSupplement::~ContextSupplement() { |
| 16 } |
| 17 |
| 18 PerContextData::PerContextData(v8::Handle<v8::Context> context) { |
| 19 context->SetAlignedPointerInEmbedderData(kEncodedValueIndex, this); |
| 20 } |
| 21 |
| 22 PerContextData::~PerContextData() { |
| 23 assert(supplements_.empty()); |
| 24 } |
| 25 |
| 26 void PerContextData::Detach(v8::Handle<v8::Context> context) { |
| 27 assert(From(context) == this); |
| 28 context->SetAlignedPointerInEmbedderData(kEncodedValueIndex, NULL); |
| 29 |
| 30 SuplementVector supplements; |
| 31 supplements.swap(supplements_); |
| 32 |
| 33 for (SuplementVector::iterator it = supplements.begin(); |
| 34 it != supplements.end(); ++it) { |
| 35 (*it)->Detach(context); |
| 36 delete *it; |
| 37 } |
| 38 } |
| 39 |
| 40 PerContextData* PerContextData::From(v8::Handle<v8::Context> context) { |
| 41 return static_cast<PerContextData*>( |
| 42 context->GetAlignedPointerFromEmbedderData(kEncodedValueIndex)); |
| 43 } |
| 44 |
| 45 void PerContextData::AddSupplement(ContextSupplement* supplement) { |
| 46 supplements_.push_back(supplement); |
| 47 } |
| 48 |
| 49 } // namespace gin |
OLD | NEW |