diff --git a/testharnessreport.js b/testharnessreport.js index d8387b255e96b7..c95506ea6198f0 100644 --- a/testharnessreport.js +++ b/testharnessreport.js @@ -1,4 +1,6 @@ -/*global add_completion_callback, setup */ +/* global add_completion_callback */ +/* global setup */ + /* * This file is intended for vendors to implement * code needed to integrate testharness.js tests with their own test systems. @@ -23,8 +25,6 @@ * parameters they are called with see testharness.js */ - - var metadata_generator = { currentMetadata: {}, @@ -389,13 +389,20 @@ function dump_test_results(tests, status) { var test_results = tests.map(function(x) { return {name:x.name, status:x.status, message:x.message, stack:x.stack} }); - data = {test:window.location.href, - tests:test_results, - status: status.status, - message: status.message, - stack: status.stack}; + var data = {test:window.location.href, + tests:test_results, + status: status.status, + message: status.message, + stack: status.stack}; results_element.textContent = JSON.stringify(data); - document.documentElement.lastChild.appendChild(results_element); + + // To avoid a HierarchyRequestError with XML documents, ensure that 'results_element' + // is inserted at a location that results in a valid document. + var parent = document.body + ? document.body // is required in XHTML documents + : document.documentElement; // fallback for optional in HTML5, SVG, etc. + + parent.appendChild(results_element); } metadata_generator.setup();