blob: 666c414f0444466f765f7a8f8b0c937dd6a8ba3f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gin/per_context_data.h"
#include "base/logging.h"
#include "gin/public/wrapper_info.h"
namespace gin {
ContextSupplement::ContextSupplement() {
}
ContextSupplement::~ContextSupplement() {
}
PerContextData::PerContextData(v8::Handle<v8::Context> context)
: runner_(NULL) {
context->SetAlignedPointerInEmbedderData(kEncodedValueIndex, this);
}
PerContextData::~PerContextData() {
DCHECK(supplements_.empty());
}
void PerContextData::Detach(v8::Handle<v8::Context> context) {
DCHECK(From(context) == this);
context->SetAlignedPointerInEmbedderData(kEncodedValueIndex, NULL);
SuplementVector supplements;
supplements.swap(supplements_);
for (SuplementVector::iterator it = supplements.begin();
it != supplements.end(); ++it) {
(*it)->Detach(context);
}
}
PerContextData* PerContextData::From(v8::Handle<v8::Context> context) {
return static_cast<PerContextData*>(
context->GetAlignedPointerFromEmbedderData(kEncodedValueIndex));
}
void PerContextData::AddSupplement(scoped_ptr<ContextSupplement> supplement) {
supplements_.push_back(supplement.release());
}
} // namespace gin
|