From c198c32164bbb5fec45b4e0950f29dda7a7968a9 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 27 Oct 2014 17:22:55 -0700 Subject: [PATCH] Don't crash when importing a 404 Now we have a test for this case. R=esprehn@chromium.org Review URL: https://codereview.chromium.org/682913002 --- engine/bindings/core/v8/ScriptController.cpp | 5 ++++- engine/core/html/imports/HTMLImportLoader.cpp | 6 ++++-- tests/modules/imports-can-load-404s-expected.txt | 1 + tests/modules/imports-can-load-404s.html | 9 +++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/modules/imports-can-load-404s-expected.txt create mode 100644 tests/modules/imports-can-load-404s.html diff --git a/engine/bindings/core/v8/ScriptController.cpp b/engine/bindings/core/v8/ScriptController.cpp index 38f1942d6e3..e257975a347 100644 --- a/engine/bindings/core/v8/ScriptController.cpp +++ b/engine/bindings/core/v8/ScriptController.cpp @@ -353,7 +353,10 @@ void ScriptController::executeModuleScript(Document& document, const String& sou String name = link->as(); if (!name.isEmpty()) { module.formalDependenciesAndSource.append(v8String(m_isolate, name)); - module.resolvedDependencies.append(child->document() ? child->document()->exports().v8Value() : v8Undefined()); + v8::Handle actual = v8::Undefined(m_isolate); + if (child->document()) + actual = child->document()->exports().v8Value(); + module.resolvedDependencies.append(actual); } } } diff --git a/engine/core/html/imports/HTMLImportLoader.cpp b/engine/core/html/imports/HTMLImportLoader.cpp index a96b38566d3..22e5b599bc1 100644 --- a/engine/core/html/imports/HTMLImportLoader.cpp +++ b/engine/core/html/imports/HTMLImportLoader.cpp @@ -121,8 +121,10 @@ void HTMLImportLoader::setState(State state) m_state = state; - if (m_state == StateParsed || m_state == StateError || m_state == StateWritten) - m_document->cancelParsing(); + if (m_state == StateParsed || m_state == StateError || m_state == StateWritten) { + if (m_document) + m_document->cancelParsing(); + } // Since DocumentWriter::end() can let setState() reenter, we shouldn't refer to m_state here. if (state == StateLoaded || state == StateError) diff --git a/tests/modules/imports-can-load-404s-expected.txt b/tests/modules/imports-can-load-404s-expected.txt new file mode 100644 index 00000000000..7ef22e9a431 --- /dev/null +++ b/tests/modules/imports-can-load-404s-expected.txt @@ -0,0 +1 @@ +PASS diff --git a/tests/modules/imports-can-load-404s.html b/tests/modules/imports-can-load-404s.html new file mode 100644 index 00000000000..318e0a33ced --- /dev/null +++ b/tests/modules/imports-can-load-404s.html @@ -0,0 +1,9 @@ + + + +
FAIL - Script did not execute
+ +