Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptState.cpp

Issue 2843603002: Move ScriptWrappable and dependencies to platform/bindings (Closed)
Patch Set: Rebase and try again Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 "bindings/core/v8/ScriptState.h"
6
7 #include "bindings/core/v8/V8Binding.h"
8 #include "core/dom/ExecutionContext.h"
9
10 namespace blink {
11
12 PassRefPtr<ScriptState> ScriptState::Create(v8::Local<v8::Context> context,
13 PassRefPtr<DOMWrapperWorld> world) {
14 RefPtr<ScriptState> script_state =
15 AdoptRef(new ScriptState(context, std::move(world)));
16 // This ref() is for keeping this ScriptState alive as long as the v8::Context
17 // is alive. This is deref()ed in the weak callback of the v8::Context.
18 script_state->Ref();
19 return script_state;
20 }
21
22 static void DerefCallback(const v8::WeakCallbackInfo<ScriptState>& data) {
23 data.GetParameter()->Deref();
24 }
25
26 static void ContextCollectedCallback(
27 const v8::WeakCallbackInfo<ScriptState>& data) {
28 data.GetParameter()->ClearContext();
29 data.SetSecondPassCallback(DerefCallback);
30 }
31
32 ScriptState::ScriptState(v8::Local<v8::Context> context,
33 PassRefPtr<DOMWrapperWorld> world)
34 : isolate_(context->GetIsolate()),
35 context_(isolate_, context),
36 world_(std::move(world)),
37 per_context_data_(V8PerContextData::Create(context)) {
38 DCHECK(world_);
39 context_.SetWeak(this, &ContextCollectedCallback);
40 context->SetAlignedPointerInEmbedderData(kV8ContextPerContextDataIndex, this);
41 }
42
43 ScriptState::~ScriptState() {
44 DCHECK(!per_context_data_);
45 DCHECK(context_.IsEmpty());
46 }
47
48 void ScriptState::DetachGlobalObject() {
49 DCHECK(!context_.IsEmpty());
50 GetContext()->DetachGlobal();
51 }
52
53 void ScriptState::DisposePerContextData() {
54 per_context_data_ = nullptr;
55 }
56
57 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ScriptState.h ('k') | third_party/WebKit/Source/bindings/core/v8/ScriptWrappable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698