OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "core/dom/ModulePendingScript.h" |
| 6 |
| 7 #include "core/dom/ScriptLoader.h" |
| 8 #include "core/frame/LocalFrame.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 ModulePendingScriptTreeClient::ModulePendingScriptTreeClient() |
| 13 : module_script_(nullptr), pending_script_(nullptr) {} |
| 14 |
| 15 void ModulePendingScriptTreeClient::SetPendingScript( |
| 16 ModulePendingScript* pending_script) { |
| 17 DCHECK(!pending_script_); |
| 18 pending_script_ = pending_script; |
| 19 |
| 20 if (finished_) { |
| 21 pending_script_->NotifyModuleTreeLoadFinished(); |
| 22 } |
| 23 } |
| 24 |
| 25 void ModulePendingScriptTreeClient::NotifyModuleTreeLoadFinished( |
| 26 ModuleScript* module_script) { |
| 27 DCHECK(!(module_script && module_script->InstantiationState() == |
| 28 ModuleInstantiationState::kUninstantiated)); |
| 29 DCHECK(!finished_); |
| 30 finished_ = true; |
| 31 module_script_ = module_script; |
| 32 |
| 33 if (pending_script_) |
| 34 pending_script_->NotifyModuleTreeLoadFinished(); |
| 35 } |
| 36 |
| 37 DEFINE_TRACE(ModulePendingScriptTreeClient) { |
| 38 visitor->Trace(module_script_); |
| 39 visitor->Trace(pending_script_); |
| 40 ModuleTreeClient::Trace(visitor); |
| 41 } |
| 42 |
| 43 ModulePendingScript::ModulePendingScript(ScriptElementBase* element, |
| 44 ModulePendingScriptTreeClient* client) |
| 45 : PendingScript(element, TextPosition()), module_tree_client_(client) { |
| 46 CHECK(this->GetElement()); |
| 47 DCHECK(module_tree_client_); |
| 48 client->SetPendingScript(this); |
| 49 } |
| 50 |
| 51 ModulePendingScript::~ModulePendingScript() {} |
| 52 |
| 53 void ModulePendingScript::DisposeInternal() { |
| 54 module_tree_client_ = nullptr; |
| 55 } |
| 56 |
| 57 DEFINE_TRACE(ModulePendingScript) { |
| 58 visitor->Trace(module_tree_client_); |
| 59 PendingScript::Trace(visitor); |
| 60 } |
| 61 |
| 62 void ModulePendingScript::NotifyModuleTreeLoadFinished() { |
| 63 CHECK(!IsReady()); |
| 64 ready_ = true; |
| 65 |
| 66 if (Client()) |
| 67 Client()->PendingScriptFinished(this); |
| 68 } |
| 69 |
| 70 Script* ModulePendingScript::GetSource(const KURL& document_url, |
| 71 bool& error_occurred) const { |
| 72 CHECK(IsReady()); |
| 73 error_occurred = ErrorOccurred(); |
| 74 return GetModuleScript(); |
| 75 } |
| 76 |
| 77 bool ModulePendingScript::ErrorOccurred() const { |
| 78 CHECK(IsReady()); |
| 79 return !GetModuleScript(); |
| 80 } |
| 81 |
| 82 } // namespace blink |
OLD | NEW |