OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/workers/Worklet.h" | 5 #include "core/workers/Worklet.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptSourceCode.h" | 7 #include "bindings/core/v8/ScriptSourceCode.h" |
8 #include "bindings/core/v8/V8Binding.h" | 8 #include "bindings/core/v8/V8Binding.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 m_loaderAndResolvers.set(scriptLoader, resolver); | 38 m_loaderAndResolvers.set(scriptLoader, resolver); |
39 scriptLoader->fetchScript(scriptURL); | 39 scriptLoader->fetchScript(scriptURL); |
40 return promise; | 40 return promise; |
41 } | 41 } |
42 | 42 |
43 void Worklet::notifyWorkletScriptLoadingFinished( | 43 void Worklet::notifyWorkletScriptLoadingFinished( |
44 WorkletScriptLoader* scriptLoader, | 44 WorkletScriptLoader* scriptLoader, |
45 const ScriptSourceCode& sourceCode) { | 45 const ScriptSourceCode& sourceCode) { |
46 DCHECK(isMainThread()); | 46 DCHECK(isMainThread()); |
47 ScriptPromiseResolver* resolver = m_loaderAndResolvers.get(scriptLoader); | 47 ScriptPromiseResolver* resolver = m_loaderAndResolvers.get(scriptLoader); |
48 m_loaderAndResolvers.remove(scriptLoader); | 48 m_loaderAndResolvers.erase(scriptLoader); |
49 | 49 |
50 if (!scriptLoader->wasScriptLoadSuccessful()) { | 50 if (!scriptLoader->wasScriptLoadSuccessful()) { |
51 resolver->reject(DOMException::create(NetworkError)); | 51 resolver->reject(DOMException::create(NetworkError)); |
52 return; | 52 return; |
53 } | 53 } |
54 | 54 |
55 workletGlobalScopeProxy()->evaluateScript(sourceCode); | 55 workletGlobalScopeProxy()->evaluateScript(sourceCode); |
56 resolver->resolve(); | 56 resolver->resolve(); |
57 } | 57 } |
58 | 58 |
59 void Worklet::contextDestroyed(ExecutionContext*) { | 59 void Worklet::contextDestroyed(ExecutionContext*) { |
60 DCHECK(isMainThread()); | 60 DCHECK(isMainThread()); |
61 if (isInitialized()) | 61 if (isInitialized()) |
62 workletGlobalScopeProxy()->terminateWorkletGlobalScope(); | 62 workletGlobalScopeProxy()->terminateWorkletGlobalScope(); |
63 for (const auto& scriptLoader : m_loaderAndResolvers.keys()) | 63 for (const auto& scriptLoader : m_loaderAndResolvers.keys()) |
64 scriptLoader->cancel(); | 64 scriptLoader->cancel(); |
65 m_loaderAndResolvers.clear(); | 65 m_loaderAndResolvers.clear(); |
66 m_frame = nullptr; | 66 m_frame = nullptr; |
67 } | 67 } |
68 | 68 |
69 DEFINE_TRACE(Worklet) { | 69 DEFINE_TRACE(Worklet) { |
70 visitor->trace(m_frame); | 70 visitor->trace(m_frame); |
71 visitor->trace(m_loaderAndResolvers); | 71 visitor->trace(m_loaderAndResolvers); |
72 ContextLifecycleObserver::trace(visitor); | 72 ContextLifecycleObserver::trace(visitor); |
73 } | 73 } |
74 | 74 |
75 } // namespace blink | 75 } // namespace blink |
OLD | NEW |