OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "config.h" | 5 #include "config.h" |
6 #include "bindings/core/v8/ScriptState.h" | 6 #include "bindings/core/v8/ScriptState.h" |
7 | 7 |
8 #include "bindings/core/v8/V8Binding.h" | 8 #include "bindings/core/v8/V8Binding.h" |
9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
10 #include "core/frame/LocalDOMWindow.h" | 10 #include "core/frame/LocalDOMWindow.h" |
11 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 PassRefPtr<ScriptState> ScriptState::create(v8::Handle<v8::Context> context, Pas
sRefPtr<DOMWrapperWorld> world) | 15 PassRefPtr<ScriptState> ScriptState::create(v8::Local<v8::Context> context, Pass
RefPtr<DOMWrapperWorld> world) |
16 { | 16 { |
17 RefPtr<ScriptState> scriptState = adoptRef(new ScriptState(context, world)); | 17 RefPtr<ScriptState> scriptState = adoptRef(new ScriptState(context, world)); |
18 // This ref() is for keeping this ScriptState alive as long as the v8::Conte
xt is alive. | 18 // This ref() is for keeping this ScriptState alive as long as the v8::Conte
xt is alive. |
19 // This is deref()ed in the weak callback of the v8::Context. | 19 // This is deref()ed in the weak callback of the v8::Context. |
20 scriptState->ref(); | 20 scriptState->ref(); |
21 return scriptState; | 21 return scriptState; |
22 } | 22 } |
23 | 23 |
24 static void derefCallback(const v8::WeakCallbackInfo<ScriptState>& data) | 24 static void derefCallback(const v8::WeakCallbackInfo<ScriptState>& data) |
25 { | 25 { |
26 data.GetParameter()->deref(); | 26 data.GetParameter()->deref(); |
27 } | 27 } |
28 | 28 |
29 static void weakCallback(const v8::WeakCallbackInfo<ScriptState>& data) | 29 static void weakCallback(const v8::WeakCallbackInfo<ScriptState>& data) |
30 { | 30 { |
31 data.GetParameter()->clearContext(); | 31 data.GetParameter()->clearContext(); |
32 data.SetSecondPassCallback(derefCallback); | 32 data.SetSecondPassCallback(derefCallback); |
33 } | 33 } |
34 | 34 |
35 ScriptState::ScriptState(v8::Handle<v8::Context> context, PassRefPtr<DOMWrapperW
orld> world) | 35 ScriptState::ScriptState(v8::Local<v8::Context> context, PassRefPtr<DOMWrapperWo
rld> world) |
36 : m_isolate(context->GetIsolate()) | 36 : m_isolate(context->GetIsolate()) |
37 , m_context(m_isolate, context) | 37 , m_context(m_isolate, context) |
38 , m_world(world) | 38 , m_world(world) |
39 , m_perContextData(V8PerContextData::create(context)) | 39 , m_perContextData(V8PerContextData::create(context)) |
40 #if ENABLE(ASSERT) | 40 #if ENABLE(ASSERT) |
41 , m_globalObjectDetached(false) | 41 , m_globalObjectDetached(false) |
42 #endif | 42 #endif |
43 { | 43 { |
44 ASSERT(m_world); | 44 ASSERT(m_world); |
45 m_context.setWeak(this, &weakCallback); | 45 m_context.setWeak(this, &weakCallback); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 120 } |
121 | 121 |
122 ScriptState* ScriptState::forMainWorld(LocalFrame* frame) | 122 ScriptState* ScriptState::forMainWorld(LocalFrame* frame) |
123 { | 123 { |
124 v8::Isolate* isolate = toIsolate(frame); | 124 v8::Isolate* isolate = toIsolate(frame); |
125 v8::HandleScope handleScope(isolate); | 125 v8::HandleScope handleScope(isolate); |
126 return ScriptState::from(toV8Context(frame, DOMWrapperWorld::mainWorld())); | 126 return ScriptState::from(toV8Context(frame, DOMWrapperWorld::mainWorld())); |
127 } | 127 } |
128 | 128 |
129 } | 129 } |
OLD | NEW |