Commit 498a5211 authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Remove nullptr ExecutionContext early-exits in DOMImplementation

They were necessary to prevent crashes at one point, but other
refactoring appear to have rendered them unnecessary, and they can cause
createDocument/createHTMLDocument to incorrectly return null when they
are called on an implementation object from a detached document.

Bug: 1128911
Test: dom/nodes/DOMImplementation-createHTMLDocument-with-saved-implementation.html
Change-Id: Ia37201a15db195f24e6d3988ee9dddd1d15806c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2432850
Commit-Queue: Nate Chapin <japhet@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812261}
parent 6b9381e4
......@@ -73,11 +73,8 @@ XMLDocument* DOMImplementation::createDocument(
const AtomicString& qualified_name,
DocumentType* doctype,
ExceptionState& exception_state) {
ExecutionContext* context = document_->GetExecutionContext();
if (!context)
return nullptr;
XMLDocument* doc = nullptr;
ExecutionContext* context = document_->GetExecutionContext();
DocumentInit init = DocumentInit::Create().WithExecutionContext(context);
if (namespace_uri == svg_names::kNamespaceURI) {
doc = XMLDocument::CreateSVG(init);
......@@ -107,8 +104,6 @@ XMLDocument* DOMImplementation::createDocument(
}
Document* DOMImplementation::createHTMLDocument(const String& title) {
if (!document_->GetExecutionContext())
return nullptr;
DocumentInit init =
DocumentInit::Create()
.WithExecutionContext(document_->GetExecutionContext())
......
<!DOCTYPE html>
<title>DOMImplementation.createHTMLDocument</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
// Test the document location getter is null outside of browser context
test(function() {
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
var implementation = iframe.contentDocument.implementation;
iframe.remove();
assert_not_equals(implementation.createHTMLDocument(), null);
}, "createHTMLDocument(): from a saved and detached implementation does not return null")
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment