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