<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[175695] trunk/LayoutTests</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/175695">175695</a></dd>
<dt>Author</dt> <dd>bjonesbe@adobe.com</dd>
<dt>Date</dt> <dd>2014-11-06 07:22:15 -0800 (Thu, 06 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Update testharness.js to the latest version
https://bugs.webkit.org/show_bug.cgi?id=138446

Reviewed by Ryosuke Niwa.

The only change I've made from upstream is to set output to false by
default.

* resources/testharness.js:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsresourcestestharnessjs">trunk/LayoutTests/resources/testharness.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (175694 => 175695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-11-06 15:08:07 UTC (rev 175694)
+++ trunk/LayoutTests/ChangeLog        2014-11-06 15:22:15 UTC (rev 175695)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-11-06  Bem Jones-Bey  &lt;bjonesbe@adobe.com&gt;
+
+        Update testharness.js to the latest version
+        https://bugs.webkit.org/show_bug.cgi?id=138446
+
+        Reviewed by Ryosuke Niwa.
+
+        The only change I've made from upstream is to set output to false by
+        default.
+
+        * resources/testharness.js:
+
</ins><span class="cx"> 2014-11-06  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, fix nits after r175688.
</span></span></pre></div>
<a id="trunkLayoutTestsresourcestestharnessjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/resources/testharness.js (175694 => 175695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/resources/testharness.js        2014-11-06 15:08:07 UTC (rev 175694)
+++ trunk/LayoutTests/resources/testharness.js        2014-11-06 15:22:15 UTC (rev 175695)
</span><span class="lines">@@ -1,3 +1,5 @@
</span><ins>+/*global self*/
+/*jshint latedef: nofunc*/
</ins><span class="cx"> /*
</span><span class="cx"> Distributed under both the W3C Test Suite License [1] and the W3C
</span><span class="cx"> 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
</span><span class="lines">@@ -8,374 +10,19 @@
</span><span class="cx"> [3] http://www.w3.org/2004/10/27-testcases
</span><span class="cx"> */
</span><span class="cx"> 
</span><del>-/*
- * == Introduction ==
- *
- * This file provides a framework for writing testcases. It is intended to
- * provide a convenient API for making common assertions, and to work both
- * for testing synchronous and asynchronous DOM features in a way that
- * promotes clear, robust, tests.
- *
- * == Basic Usage ==
- *
- * To use this file, import the script and the testharnessreport script into
- * the test document:
- * &lt;script src=&quot;/resources/testharness.js&quot;&gt;&lt;/script&gt;
- * &lt;script src=&quot;/resources/testharnessreport.js&quot;&gt;&lt;/script&gt;
- *
- * Within each file one may define one or more tests. Each test is atomic
- * in the sense that a single test has a single result (pass/fail/timeout).
- * Within each test one may have a number of asserts. The test fails at the
- * first failing assert, and the remainder of the test is (typically) not run.
- *
- * If the file containing the tests is a HTML file with an element of id &quot;log&quot;
- * this will be populated with a table containing the test results after all
- * the tests have run.
- *
- * NOTE: By default tests must be created before the load event fires. For ways
- *       to create tests after the load event, see &quot;Determining when all tests
- *       are complete&quot;, below
- *
- * == Synchronous Tests ==
- *
- * To create a synchronous test use the test() function:
- *
- * test(test_function, name, properties)
- *
- * test_function is a function that contains the code to test. For example a
- * trivial passing test would be:
- *
- * test(function() {assert_true(true)}, &quot;assert_true with true&quot;)
- *
- * The function passed in is run in the test() call.
- *
- * properties is an object that overrides default test properties. The
- * recognised properties are:
- *    timeout - the test timeout in ms
- *
- * e.g.
- * test(test_function, &quot;Sample test&quot;, {timeout:1000})
- *
- * would run test_function with a timeout of 1s.
- *
- * Additionally, test-specific metadata can be passed in the properties. These
- * are used when the individual test has different metadata from that stored
- * in the &lt;head&gt;.
- * The recognized metadata properties are:
- *
- *    help - The url of the part of the specification being tested
- *
- *    assert - A human readable description of what the test is attempting
- *             to prove
- *
- *    author - Name and contact information for the author of the test in the
- *             format: &quot;Name &lt;email_addr&gt;&quot; or &quot;Name http://contact/url&quot;
- *
- * == Asynchronous Tests ==
- *
- * Testing asynchronous features is somewhat more complex since the result of
- * a test may depend on one or more events or other callbacks. The API provided
- * for testing these features is indended to be rather low-level but hopefully
- * applicable to many situations.
- *
- * To create a test, one starts by getting a Test object using async_test:
- *
- * async_test(name, properties)
- *
- * e.g.
- * var t = async_test(&quot;Simple async test&quot;)
- *
- * Assertions can be added to the test by calling the step method of the test
- * object with a function containing the test assertions:
- *
- * t.step(function() {assert_true(true)});
- *
- * When all the steps are complete, the done() method must be called:
- *
- * t.done();
- *
- * As a convenience, async_test can also takes a function as first argument.
- * This function is called with the test object as both its `this` object and
- * first argument. The above example can be rewritten as:
- *
- * async_test(function(t) {
- *     object.some_event = function() {
- *         t.step(function (){assert_true(true); t.done();});
- *     };
- * }, &quot;Simple async test&quot;);
- *
- * which avoids cluttering the global scope with references to async
- * tests instances.
- *
- * The properties argument is identical to that for test().
- *
- * In many cases it is convenient to run a step in response to an event or a
- * callback. A convenient method of doing this is through the step_func method
- * which returns a function that, when called runs a test step. For example
- *
- * object.some_event = t.step_func(function(e) {assert_true(e.a)});
- *
- * == Making assertions ==
- *
- * Functions for making assertions start assert_
- * The best way to get a list is to look in this file for functions names
- * matching that pattern. The general signature is
- *
- * assert_something(actual, expected, description)
- *
- * although not all assertions precisely match this pattern e.g. assert_true
- * only takes actual and description as arguments.
- *
- * The description parameter is used to present more useful error messages when
- * a test fails
- *
- * NOTE: All asserts must be located in a test() or a step of an async_test().
- *       asserts outside these places won't be detected correctly by the harness
- *       and may cause a file to stop testing.
- *
- * == Harness Timeout ==
- * 
- * The overall harness admits two timeout values &quot;normal&quot; (the
- * default) and &quot;long&quot;, used for tests which have an unusually long
- * runtime. After the timeout is reached, the harness will stop
- * waiting for further async tests to complete. By default the
- * timeouts are set to 10s and 60s, respectively, but may be changed
- * when the test is run on hardware with different performance
- * characteristics to a common desktop computer.  In order to opt-in
- * to the longer test timeout, the test must specify a meta element:
- * &lt;meta name=&quot;timeout&quot; content=&quot;long&quot;&gt;
- *
- * == Setup ==
- *
- * Sometimes tests require non-trivial setup that may fail. For this purpose
- * there is a setup() function, that may be called with one or two arguments.
- * The two argument version is:
- *
- * setup(func, properties)
- *
- * The one argument versions may omit either argument.
- * func is a function to be run synchronously. setup() becomes a no-op once
- * any tests have returned results. Properties are global properties of the test
- * harness. Currently recognised properties are:
- *
- *
- * explicit_done - Wait for an explicit call to done() before declaring all
- *                 tests complete (see below)
- *
- * output_document - The document to which results should be logged. By default
- *                   this is the current document but could be an ancestor
- *                   document in some cases e.g. a SVG test loaded in an HTML
- *                   wrapper
- *
- * explicit_timeout - disable file timeout; only stop waiting for results
- *                    when the timeout() function is called (typically for
- *                    use when integrating with some existing test framework
- *                    that has its own timeout mechanism).
- *
- * allow_uncaught_exception - don't treat an uncaught exception as an error;
- *                            needed when e.g. testing the window.onerror
- *                            handler.
- *
- * timeout_multiplier - Multiplier to apply to per-test timeouts.
- *
- * == Determining when all tests are complete ==
- *
- * By default the test harness will assume there are no more results to come
- * when:
- * 1) There are no Test objects that have been created but not completed
- * 2) The load event on the document has fired
- *
- * This behaviour can be overridden by setting the explicit_done property to
- * true in a call to setup(). If explicit_done is true, the test harness will
- * not assume it is done until the global done() function is called. Once done()
- * is called, the two conditions above apply like normal.
- *
- * == Generating tests ==
- *
- * NOTE: this functionality may be removed
- *
- * There are scenarios in which is is desirable to create a large number of
- * (synchronous) tests that are internally similar but vary in the parameters
- * used. To make this easier, the generate_tests function allows a single
- * function to be called with each set of parameters in a list:
- *
- * generate_tests(test_function, parameter_lists, properties)
- *
- * For example:
- *
- * generate_tests(assert_equals, [
- *     [&quot;Sum one and one&quot;, 1+1, 2],
- *     [&quot;Sum one and zero&quot;, 1+0, 1]
- *     ])
- *
- * Is equivalent to:
- *
- * test(function() {assert_equals(1+1, 2)}, &quot;Sum one and one&quot;)
- * test(function() {assert_equals(1+0, 1)}, &quot;Sum one and zero&quot;)
- *
- * Note that the first item in each parameter list corresponds to the name of
- * the test.
- *
- * The properties argument is identical to that for test(). This may be a
- * single object (used for all generated tests) or an array.
- *
- * == Callback API ==
- *
- * The framework provides callbacks corresponding to 3 events:
- *
- * start - happens when the first Test is created
- * result - happens when a test result is recieved
- * complete - happens when all results are recieved
- *
- * The page defining the tests may add callbacks for these events by calling
- * the following methods:
- *
- *   add_start_callback(callback) - callback called with no arguments
- *   add_result_callback(callback) - callback called with a test argument
- *   add_completion_callback(callback) - callback called with an array of tests
- *                                       and an status object
- *
- * tests have the following properties:
- *   status: A status code. This can be compared to the PASS, FAIL, TIMEOUT and
- *           NOTRUN properties on the test object
- *   message: A message indicating the reason for failure. In the future this
- *            will always be a string
- *
- *  The status object gives the overall status of the harness. It has the
- *  following properties:
- *    status: Can be compared to the OK, ERROR and TIMEOUT properties
- *    message: An error message set when the status is ERROR
- *
- * == External API ==
- *
- * In order to collect the results of multiple pages containing tests, the test
- * harness will, when loaded in a nested browsing context, attempt to call
- * certain functions in each ancestor and opener browsing context:
- *
- * start - start_callback
- * result - result_callback
- * complete - completion_callback
- *
- * These are given the same arguments as the corresponding internal callbacks
- * described above.
- *
- * == External API through cross-document messaging ==
- *
- * Where supported, the test harness will also send messages using
- * cross-document messaging to each ancestor and opener browsing context. Since
- * it uses the wildcard keyword (*), cross-origin communication is enabled and
- * script on different origins can collect the results.
- *
- * This API follows similar conventions as those described above only slightly
- * modified to accommodate message event API. Each message is sent by the harness
- * is passed a single vanilla object, available as the `data` property of the
- * event object. These objects are structures as follows:
- *
- * start - { type: &quot;start&quot; }
- * result - { type: &quot;result&quot;, test: Test }
- * complete - { type: &quot;complete&quot;, tests: [Test, ...], status: TestsStatus }
- *
- * == List of assertions ==
- *
- * assert_true(actual, description)
- *   asserts that /actual/ is strictly true
- *
- * assert_false(actual, description)
- *   asserts that /actual/ is strictly false
- *
- * assert_equals(actual, expected, description)
- *   asserts that /actual/ is the same value as /expected/
- *
- * assert_not_equals(actual, expected, description)
- *   asserts that /actual/ is a different value to /expected/. Yes, this means
- *   that &quot;expected&quot; is a misnomer
- *
- * assert_in_array(actual, expected, description)
- *   asserts that /expected/ is an Array, and /actual/ is equal to one of the
- *   members -- expected.indexOf(actual) != -1
- *
- * assert_array_equals(actual, expected, description)
- *   asserts that /actual/ and /expected/ have the same length and the value of
- *   each indexed property in /actual/ is the strictly equal to the corresponding
- *   property value in /expected/
- *
- * assert_approx_equals(actual, expected, epsilon, description)
- *   asserts that /actual/ is a number within +/- /epsilon/ of /expected/
- *
- * assert_less_than(actual, expected, description)
- *   asserts that /actual/ is a number less than /expected/
- *
- * assert_greater_than(actual, expected, description)
- *   asserts that /actual/ is a number greater than /expected/
- *
- * assert_less_than_equal(actual, expected, description)
- *   asserts that /actual/ is a number less than or equal to /expected/
- *
- * assert_greater_than_equal(actual, expected, description)
- *   asserts that /actual/ is a number greater than or equal to /expected/
- *
- * assert_regexp_match(actual, expected, description)
- *   asserts that /actual/ matches the regexp /expected/
- *
- * assert_class_string(object, class_name, description)
- *   asserts that the class string of /object/ as returned in
- *   Object.prototype.toString is equal to /class_name/.
- *
- * assert_own_property(object, property_name, description)
- *   assert that object has own property property_name
- *
- * assert_inherits(object, property_name, description)
- *   assert that object does not have an own property named property_name
- *   but that property_name is present in the prototype chain for object
- *
- * assert_idl_attribute(object, attribute_name, description)
- *   assert that an object that is an instance of some interface has the
- *   attribute attribute_name following the conditions specified by WebIDL
- *
- * assert_readonly(object, property_name, description)
- *   assert that property property_name on object is readonly
- *
- * assert_throws(code, func, description)
- *   code - the expected exception:
- *     o string: the thrown exception must be a DOMException with the given
- *               name, e.g., &quot;TimeoutError&quot; (for compatibility with existing
- *               tests, a constant is also supported, e.g., &quot;TIMEOUT_ERR&quot;)
- *     o object: the thrown exception must have a property called &quot;name&quot; that
- *               matches code.name
- *     o null:   allow any exception (in general, one of the options above
- *               should be used)
- *   func - a function that should throw
- *
- * assert_unreached(description)
- *   asserts if called. Used to ensure that some codepath is *not* taken e.g.
- *   an event does not fire.
- *
- * assert_any(assert_func, actual, expected_array, extra_arg_1, ... extra_arg_N)
- *   asserts that one assert_func(actual, expected_array_N, extra_arg1, ..., extra_arg_N)
- *   is true for some expected_array_N in expected_array. This only works for assert_func
- *   with signature assert_func(actual, expected, args_1, ..., args_N). Note that tests
- *   with multiple allowed pass conditions are bad practice unless the spec specifically
- *   allows multiple behaviours. Test authors should not use this method simply to hide
- *   UA bugs.
- *
- * assert_exists(object, property_name, description)
- *   *** deprecated ***
- *   asserts that object has an own property property_name
- *
- * assert_not_exists(object, property_name, description)
- *   *** deprecated ***
- *   assert that object does not have own property property_name
- */
</del><ins>+/* Documentation is in docs/api.md */
</ins><span class="cx"> 
</span><span class="cx"> (function ()
</span><span class="cx"> {
</span><span class="cx">     var debug = false;
</span><span class="cx">     // default timeout is 10 seconds, test can override if needed
</span><span class="cx">     var settings = {
</span><del>-      output:true,
-      harness_timeout:{&quot;normal&quot;:10000,
-                       &quot;long&quot;:60000},
-      test_timeout:null
</del><ins>+        output:false,
+        harness_timeout:{
+            &quot;normal&quot;:10000,
+            &quot;long&quot;:60000
+        },
+        test_timeout:null
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     var xhtml_ns = &quot;http://www.w3.org/1999/xhtml&quot;;
</span><span class="lines">@@ -387,19 +34,16 @@
</span><span class="cx">     (function ()
</span><span class="cx">     {
</span><span class="cx">         var scripts = document.getElementsByTagName(&quot;script&quot;);
</span><del>-        for (var i = 0; i &lt; scripts.length; i++)
-        {
-            if (scripts[i].src)
-            {
-                var src = scripts[i].src;
-            }
-            else if (scripts[i].href)
-            {
</del><ins>+        for (var i = 0; i &lt; scripts.length; i++) {
+            var src;
+            if (scripts[i].src) {
+                src = scripts[i].src;
+            } else if (scripts[i].href) {
</ins><span class="cx">                 //SVG case
</span><del>-                var src = scripts[i].href.baseVal;
</del><ins>+                src = scripts[i].href.baseVal;
</ins><span class="cx">             }
</span><del>-            if (src &amp;&amp; src.slice(src.length - &quot;testharness.js&quot;.length) === &quot;testharness.js&quot;)
-            {
</del><ins>+
+            if (src &amp;&amp; src.slice(src.length - &quot;testharness.js&quot;.length) === &quot;testharness.js&quot;) {
</ins><span class="cx">                 script_prefix = src.slice(0, src.length - &quot;testharness.js&quot;.length);
</span><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="lines">@@ -426,7 +70,7 @@
</span><span class="cx">         var test_name = name ? name : next_default_name();
</span><span class="cx">         properties = properties ? properties : {};
</span><span class="cx">         var test_obj = new Test(test_name, properties);
</span><del>-        test_obj.step(func);
</del><ins>+        test_obj.step(func, test_obj, test_obj);
</ins><span class="cx">         if (test_obj.phase === test_obj.phases.STARTED) {
</span><span class="cx">             test_obj.done();
</span><span class="cx">         }
</span><span class="lines">@@ -455,7 +99,7 @@
</span><span class="cx">         if (arguments.length === 2) {
</span><span class="cx">             func = func_or_properties;
</span><span class="cx">             properties = maybe_properties;
</span><del>-        } else if (func_or_properties instanceof Function){
</del><ins>+        } else if (func_or_properties instanceof Function) {
</ins><span class="cx">             func = func_or_properties;
</span><span class="cx">         } else {
</span><span class="cx">             properties = func_or_properties;
</span><span class="lines">@@ -465,6 +109,12 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     function done() {
</span><ins>+        if (tests.tests.length === 0) {
+            tests.set_file_is_test();
+        }
+        if (tests.file_is_test) {
+            tests.tests[0].done();
+        }
</ins><span class="cx">         tests.end_wait();
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -483,7 +133,7 @@
</span><span class="cx"> 
</span><span class="cx">     function on_event(object, event, callback)
</span><span class="cx">     {
</span><del>-      object.addEventListener(event, callback, false);
</del><ins>+        object.addEventListener(event, callback, false);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     expose(test, 'test');
</span><span class="lines">@@ -514,17 +164,13 @@
</span><span class="cx">         // instanceof doesn't work if the node is from another window (like an
</span><span class="cx">         // iframe's contentWindow):
</span><span class="cx">         // http://www.w3.org/Bugs/Public/show_bug.cgi?id=12295
</span><del>-        if (&quot;nodeType&quot; in object
-        &amp;&amp; &quot;nodeName&quot; in object
-        &amp;&amp; &quot;nodeValue&quot; in object
-        &amp;&amp; &quot;childNodes&quot; in object)
-        {
-            try
-            {
</del><ins>+        if (&quot;nodeType&quot; in object &amp;&amp;
+            &quot;nodeName&quot; in object &amp;&amp;
+            &quot;nodeValue&quot; in object &amp;&amp;
+            &quot;childNodes&quot; in object) {
+            try {
</ins><span class="cx">                 object.nodeType;
</span><del>-            }
-            catch (e)
-            {
</del><ins>+            } catch (e) {
</ins><span class="cx">                 // The object is probably Node.prototype or another prototype
</span><span class="cx">                 // object that inherits from it, and not a Node instance.
</span><span class="cx">                 return false;
</span><span class="lines">@@ -542,25 +188,20 @@
</span><span class="cx">         if (!seen) {
</span><span class="cx">             seen = [];
</span><span class="cx">         }
</span><del>-        if (typeof val === &quot;object&quot; &amp;&amp; val !== null)
-        {
-            if (seen.indexOf(val) &gt;= 0)
-            {
</del><ins>+        if (typeof val === &quot;object&quot; &amp;&amp; val !== null) {
+            if (seen.indexOf(val) &gt;= 0) {
</ins><span class="cx">                 return &quot;[...]&quot;;
</span><span class="cx">             }
</span><span class="cx">             seen.push(val);
</span><span class="cx">         }
</span><del>-        if (Array.isArray(val))
-        {
-            return &quot;[&quot; + val.map(function(x) {return format_value(x, seen)}).join(&quot;, &quot;) + &quot;]&quot;;
</del><ins>+        if (Array.isArray(val)) {
+            return &quot;[&quot; + val.map(function(x) {return format_value(x, seen);}).join(&quot;, &quot;) + &quot;]&quot;;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        switch (typeof val)
-        {
</del><ins>+        switch (typeof val) {
</ins><span class="cx">         case &quot;string&quot;:
</span><span class="cx">             val = val.replace(&quot;\\&quot;, &quot;\\\\&quot;);
</span><del>-            for (var i = 0; i &lt; 32; i++)
-            {
</del><ins>+            for (var i = 0; i &lt; 32; i++) {
</ins><span class="cx">                 var replace = &quot;\\&quot;;
</span><span class="cx">                 switch (i) {
</span><span class="cx">                 case 0: replace += &quot;0&quot;; break;
</span><span class="lines">@@ -605,30 +246,25 @@
</span><span class="cx">         case &quot;number&quot;:
</span><span class="cx">             // In JavaScript, -0 === 0 and String(-0) == &quot;0&quot;, so we have to
</span><span class="cx">             // special-case.
</span><del>-            if (val === -0 &amp;&amp; 1/val === -Infinity)
-            {
</del><ins>+            if (val === -0 &amp;&amp; 1/val === -Infinity) {
</ins><span class="cx">                 return &quot;-0&quot;;
</span><span class="cx">             }
</span><span class="cx">             return String(val);
</span><span class="cx">         case &quot;object&quot;:
</span><del>-            if (val === null)
-            {
</del><ins>+            if (val === null) {
</ins><span class="cx">                 return &quot;null&quot;;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             // Special-case Node objects, since those come up a lot in my tests.  I
</span><span class="cx">             // ignore namespaces.
</span><del>-            if (is_node(val))
-            {
-                switch (val.nodeType)
-                {
</del><ins>+            if (is_node(val)) {
+                switch (val.nodeType) {
</ins><span class="cx">                 case Node.ELEMENT_NODE:
</span><del>-                    var ret = &quot;&lt;&quot; + val.tagName.toLowerCase();
-                    for (var i = 0; i &lt; val.attributes.length; i++)
-                    {
</del><ins>+                    var ret = &quot;&lt;&quot; + val.localName;
+                    for (var i = 0; i &lt; val.attributes.length; i++) {
</ins><span class="cx">                         ret += &quot; &quot; + val.attributes[i].name + '=&quot;' + val.attributes[i].value + '&quot;';
</span><span class="cx">                     }
</span><del>-                    ret += &quot;&gt;&quot; + val.innerHTML + &quot;&lt;/&quot; + val.tagName.toLowerCase() + &quot;&gt;&quot;;
</del><ins>+                    ret += &quot;&gt;&quot; + val.innerHTML + &quot;&lt;/&quot; + val.localName + &quot;&gt;&quot;;
</ins><span class="cx">                     return &quot;Element node &quot; + truncate(ret, 60);
</span><span class="cx">                 case Node.TEXT_NODE:
</span><span class="cx">                     return 'Text node &quot;' + truncate(val.data, 60) + '&quot;';
</span><span class="lines">@@ -647,7 +283,7 @@
</span><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            // Fall through to default
</del><ins>+        /* falls through */
</ins><span class="cx">         default:
</span><span class="cx">             return typeof val + ' &quot;' + truncate(String(val), 60) + '&quot;';
</span><span class="cx">         }
</span><span class="lines">@@ -662,31 +298,26 @@
</span><span class="cx">     {
</span><span class="cx">         assert(actual === true, &quot;assert_true&quot;, description,
</span><span class="cx">                                 &quot;expected true got ${actual}&quot;, {actual:actual});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_true, &quot;assert_true&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_false(actual, description)
</span><span class="cx">     {
</span><span class="cx">         assert(actual === false, &quot;assert_false&quot;, description,
</span><span class="cx">                                  &quot;expected false got ${actual}&quot;, {actual:actual});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_false, &quot;assert_false&quot;);
</span><span class="cx"> 
</span><span class="cx">     function same_value(x, y) {
</span><del>-        if (y !== y)
-        {
</del><ins>+        if (y !== y) {
</ins><span class="cx">             //NaN case
</span><span class="cx">             return x !== x;
</span><span class="cx">         }
</span><del>-        else if (x === 0 &amp;&amp; y === 0) {
</del><ins>+        if (x === 0 &amp;&amp; y === 0) {
</ins><span class="cx">             //Distinguish +0 and -0
</span><span class="cx">             return 1/x === 1/y;
</span><span class="cx">         }
</span><del>-        else
-        {
-            //typical case
-            return x === y;
-        }
</del><ins>+        return x === y;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     function assert_equals(actual, expected, description)
</span><span class="lines">@@ -695,8 +326,7 @@
</span><span class="cx">           * Test if two primitives are equal or two objects
</span><span class="cx">           * are the same object
</span><span class="cx">           */
</span><del>-        if (typeof actual != typeof expected)
-        {
</del><ins>+        if (typeof actual != typeof expected) {
</ins><span class="cx">             assert(false, &quot;assert_equals&quot;, description,
</span><span class="cx">                           &quot;expected (&quot; + typeof expected + &quot;) ${expected} but got (&quot; + typeof actual + &quot;) ${actual}&quot;,
</span><span class="cx">                           {expected:expected, actual:actual});
</span><span class="lines">@@ -705,7 +335,7 @@
</span><span class="cx">         assert(same_value(actual, expected), &quot;assert_equals&quot;, description,
</span><span class="cx">                                              &quot;expected ${expected} but got ${actual}&quot;,
</span><span class="cx">                                              {expected:expected, actual:actual});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_equals, &quot;assert_equals&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_not_equals(actual, expected, description)
</span><span class="lines">@@ -717,7 +347,7 @@
</span><span class="cx">         assert(!same_value(actual, expected), &quot;assert_not_equals&quot;, description,
</span><span class="cx">                                               &quot;got disallowed value ${actual}&quot;,
</span><span class="cx">                                               {actual:actual});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_not_equals, &quot;assert_not_equals&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_in_array(actual, expected, description)
</span><span class="lines">@@ -736,27 +366,21 @@
</span><span class="cx">              stack.push(actual);
</span><span class="cx"> 
</span><span class="cx">              var p;
</span><del>-             for (p in actual)
-             {
</del><ins>+             for (p in actual) {
</ins><span class="cx">                  assert(expected.hasOwnProperty(p), &quot;assert_object_equals&quot;, description,
</span><span class="cx">                                                     &quot;unexpected property ${p}&quot;, {p:p});
</span><span class="cx"> 
</span><del>-                 if (typeof actual[p] === &quot;object&quot; &amp;&amp; actual[p] !== null)
-                 {
-                     if (stack.indexOf(actual[p]) === -1)
-                     {
</del><ins>+                 if (typeof actual[p] === &quot;object&quot; &amp;&amp; actual[p] !== null) {
+                     if (stack.indexOf(actual[p]) === -1) {
</ins><span class="cx">                          check_equal(actual[p], expected[p], stack);
</span><span class="cx">                      }
</span><del>-                 }
-                 else
-                 {
</del><ins>+                 } else {
</ins><span class="cx">                      assert(same_value(actual[p], expected[p]), &quot;assert_object_equals&quot;, description,
</span><span class="cx">                                                        &quot;property ${p} expected ${expected} got ${actual}&quot;,
</span><span class="cx">                                                        {p:p, expected:expected, actual:actual});
</span><span class="cx">                  }
</span><span class="cx">              }
</span><del>-             for (p in expected)
-             {
</del><ins>+             for (p in expected) {
</ins><span class="cx">                  assert(actual.hasOwnProperty(p),
</span><span class="cx">                         &quot;assert_object_equals&quot;, description,
</span><span class="cx">                         &quot;expected property ${p} missing&quot;, {p:p});
</span><span class="lines">@@ -764,7 +388,7 @@
</span><span class="cx">              stack.pop();
</span><span class="cx">          }
</span><span class="cx">          check_equal(actual, expected, []);
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_object_equals, &quot;assert_object_equals&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_array_equals(actual, expected, description)
</span><span class="lines">@@ -774,8 +398,7 @@
</span><span class="cx">                &quot;lengths differ, expected ${expected} got ${actual}&quot;,
</span><span class="cx">                {expected:expected.length, actual:actual.length});
</span><span class="cx"> 
</span><del>-        for (var i=0; i &lt; actual.length; i++)
-        {
</del><ins>+        for (var i = 0; i &lt; actual.length; i++) {
</ins><span class="cx">             assert(actual.hasOwnProperty(i) === expected.hasOwnProperty(i),
</span><span class="cx">                    &quot;assert_array_equals&quot;, description,
</span><span class="cx">                    &quot;property ${i}, property expected to be $expected but was $actual&quot;,
</span><span class="lines">@@ -803,7 +426,7 @@
</span><span class="cx">                &quot;assert_approx_equals&quot;, description,
</span><span class="cx">                &quot;expected ${expected} +/- ${epsilon} but got ${actual}&quot;,
</span><span class="cx">                {expected:expected, actual:actual, epsilon:epsilon});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_approx_equals, &quot;assert_approx_equals&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_less_than(actual, expected, description)
</span><span class="lines">@@ -820,7 +443,7 @@
</span><span class="cx">                &quot;assert_less_than&quot;, description,
</span><span class="cx">                &quot;expected a number less than ${expected} but got ${actual}&quot;,
</span><span class="cx">                {expected:expected, actual:actual});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_less_than, &quot;assert_less_than&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_greater_than(actual, expected, description)
</span><span class="lines">@@ -837,7 +460,7 @@
</span><span class="cx">                &quot;assert_greater_than&quot;, description,
</span><span class="cx">                &quot;expected a number greater than ${expected} but got ${actual}&quot;,
</span><span class="cx">                {expected:expected, actual:actual});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_greater_than, &quot;assert_greater_than&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_less_than_equal(actual, expected, description)
</span><span class="lines">@@ -854,7 +477,7 @@
</span><span class="cx">                &quot;assert_less_than&quot;, description,
</span><span class="cx">                &quot;expected a number less than or equal to ${expected} but got ${actual}&quot;,
</span><span class="cx">                {expected:expected, actual:actual});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_less_than_equal, &quot;assert_less_than_equal&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_greater_than_equal(actual, expected, description)
</span><span class="lines">@@ -871,7 +494,7 @@
</span><span class="cx">                &quot;assert_greater_than_equal&quot;, description,
</span><span class="cx">                &quot;expected a number greater than or equal to ${expected} but got ${actual}&quot;,
</span><span class="cx">                {expected:expected, actual:actual});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_greater_than_equal, &quot;assert_greater_than_equal&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_regexp_match(actual, expected, description) {
</span><span class="lines">@@ -908,7 +531,7 @@
</span><span class="cx">         assert(!object.hasOwnProperty(property_name),
</span><span class="cx">                &quot;assert_not_exists&quot;, description,
</span><span class="cx">                &quot;unexpected property ${p} found&quot;, {p:property_name});
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_not_exists, &quot;assert_not_exists&quot;);
</span><span class="cx"> 
</span><span class="cx">     function _assert_inherits(name) {
</span><span class="lines">@@ -947,33 +570,26 @@
</span><span class="cx">                     &quot;assert_readonly&quot;, description,
</span><span class="cx">                     &quot;changing property ${p} succeeded&quot;,
</span><span class="cx">                     {p:property_name});
</span><del>-         }
-         finally
-         {
</del><ins>+         } finally {
</ins><span class="cx">              object[property_name] = initial_value;
</span><span class="cx">          }
</span><del>-    };
</del><ins>+    }
</ins><span class="cx">     expose(assert_readonly, &quot;assert_readonly&quot;);
</span><span class="cx"> 
</span><span class="cx">     function assert_throws(code, func, description)
</span><span class="cx">     {
</span><del>-        try
-        {
</del><ins>+        try {
</ins><span class="cx">             func.call(this);
</span><span class="cx">             assert(false, &quot;assert_throws&quot;, description,
</span><span class="cx">                    &quot;${func} did not throw&quot;, {func:func});
</span><del>-        }
-        catch(e)
-        {
</del><ins>+        } catch (e) {
</ins><span class="cx">             if (e instanceof AssertionError) {
</span><del>-                throw(e);
</del><ins>+                throw e;
</ins><span class="cx">             }
</span><del>-            if (code === null)
-            {
</del><ins>+            if (code === null) {
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><del>-            if (typeof code === &quot;object&quot;)
-            {
</del><ins>+            if (typeof code === &quot;object&quot;) {
</ins><span class="cx">                 assert(typeof e == &quot;object&quot; &amp;&amp; &quot;name&quot; in e &amp;&amp; e.name == code.name,
</span><span class="cx">                        &quot;assert_throws&quot;, description,
</span><span class="cx">                        &quot;${func} threw ${actual} (${actual_name}) expected ${expected} (${expected_name})&quot;,
</span><span class="lines">@@ -1040,16 +656,14 @@
</span><span class="cx">                 VersionError: 0
</span><span class="cx">             };
</span><span class="cx"> 
</span><del>-            if (!(name in name_code_map))
-            {
</del><ins>+            if (!(name in name_code_map)) {
</ins><span class="cx">                 throw new AssertionError('Test bug: unrecognized DOMException code &quot;' + code + '&quot; passed to assert_throws()');
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             var required_props = { code: name_code_map[name] };
</span><span class="cx"> 
</span><del>-            if (required_props.code === 0
-            || (&quot;name&quot; in e &amp;&amp; e.name !== e.name.toUpperCase() &amp;&amp; e.name !== &quot;DOMException&quot;))
-            {
</del><ins>+            if (required_props.code === 0 ||
+               (&quot;name&quot; in e &amp;&amp; e.name !== e.name.toUpperCase() &amp;&amp; e.name !== &quot;DOMException&quot;)) {
</ins><span class="cx">                 // New style exception: also test the name property.
</span><span class="cx">                 required_props.name = name;
</span><span class="cx">             }
</span><span class="lines">@@ -1064,8 +678,7 @@
</span><span class="cx">                    &quot;${func} threw ${e} with type ${type}, not an object&quot;,
</span><span class="cx">                    {func:func, e:e, type:typeof e});
</span><span class="cx"> 
</span><del>-            for (var prop in required_props)
-            {
</del><ins>+            for (var prop in required_props) {
</ins><span class="cx">                 assert(typeof e == &quot;object&quot; &amp;&amp; prop in e &amp;&amp; e[prop] == required_props[prop],
</span><span class="cx">                        &quot;assert_throws&quot;, description,
</span><span class="cx">                        &quot;${func} threw ${e} that is not a DOMException &quot; + code + &quot;: property ${prop} is equal to ${actual}, expected ${expected}&quot;,
</span><span class="lines">@@ -1083,16 +696,16 @@
</span><span class="cx"> 
</span><span class="cx">     function assert_any(assert_func, actual, expected_array)
</span><span class="cx">     {
</span><del>-        var args = [].slice.call(arguments, 3)
-        var errors = []
</del><ins>+        var args = [].slice.call(arguments, 3);
+        var errors = [];
</ins><span class="cx">         var passed = false;
</span><span class="cx">         forEach(expected_array,
</span><span class="cx">                 function(expected)
</span><span class="cx">                 {
</span><span class="cx">                     try {
</span><del>-                        assert_func.apply(this, [actual, expected].concat(args))
</del><ins>+                        assert_func.apply(this, [actual, expected].concat(args));
</ins><span class="cx">                         passed = true;
</span><del>-                    } catch(e) {
</del><ins>+                    } catch (e) {
</ins><span class="cx">                         errors.push(e.message);
</span><span class="cx">                     }
</span><span class="cx">                 });
</span><span class="lines">@@ -1104,6 +717,9 @@
</span><span class="cx"> 
</span><span class="cx">     function Test(name, properties)
</span><span class="cx">     {
</span><ins>+        if (tests.file_is_test &amp;&amp; tests.tests.length) {
+            throw new Error(&quot;Tried to create a test with file_is_test&quot;);
+        }
</ins><span class="cx">         this.name = name;
</span><span class="cx"> 
</span><span class="cx">         this.phases = {
</span><span class="lines">@@ -1118,7 +734,7 @@
</span><span class="cx">         this.timeout_id = null;
</span><span class="cx"> 
</span><span class="cx">         this.properties = properties;
</span><del>-        var timeout = properties.timeout ? properties.timeout : settings.test_timeout
</del><ins>+        var timeout = properties.timeout ? properties.timeout : settings.test_timeout;
</ins><span class="cx">         if (timeout != null) {
</span><span class="cx">             this.timeout_length = timeout * tests.timeout_multiplier;
</span><span class="cx">         } else {
</span><span class="lines">@@ -1127,9 +743,10 @@
</span><span class="cx"> 
</span><span class="cx">         this.message = null;
</span><span class="cx"> 
</span><del>-        var this_obj = this;
</del><span class="cx">         this.steps = [];
</span><span class="cx"> 
</span><ins>+        this.cleanup_callbacks = [];
+
</ins><span class="cx">         tests.push(this);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -1144,8 +761,7 @@
</span><span class="cx"> 
</span><span class="cx">     Test.prototype.structured_clone = function()
</span><span class="cx">     {
</span><del>-        if(!this._structured_clone)
-        {
</del><ins>+        if (!this._structured_clone) {
</ins><span class="cx">             var msg = this.message;
</span><span class="cx">             msg = msg ? String(msg) : msg;
</span><span class="cx">             this._structured_clone = merge({
</span><span class="lines">@@ -1159,9 +775,8 @@
</span><span class="cx"> 
</span><span class="cx">     Test.prototype.step = function(func, this_obj)
</span><span class="cx">     {
</span><del>-        if (this.phase &gt; this.phases.STARTED)
-        {
-          return;
</del><ins>+        if (this.phase &gt; this.phases.STARTED) {
+            return;
</ins><span class="cx">         }
</span><span class="cx">         this.phase = this.phases.STARTED;
</span><span class="cx">         //If we don't get a result before the harness times out that will be a test timout
</span><span class="lines">@@ -1169,26 +784,20 @@
</span><span class="cx"> 
</span><span class="cx">         tests.started = true;
</span><span class="cx"> 
</span><del>-        if (this.timeout_id === null)
-        {
</del><ins>+        if (this.timeout_id === null) {
</ins><span class="cx">             this.set_timeout();
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         this.steps.push(func);
</span><span class="cx"> 
</span><del>-        if (arguments.length === 1)
-        {
</del><ins>+        if (arguments.length === 1) {
</ins><span class="cx">             this_obj = this;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        try
-        {
</del><ins>+        try {
</ins><span class="cx">             return func.apply(this_obj, Array.prototype.slice.call(arguments, 2));
</span><del>-        }
-        catch(e)
-        {
-            if (this.phase &gt;= this.phases.HAS_RESULT)
-            {
</del><ins>+        } catch (e) {
+            if (this.phase &gt;= this.phases.HAS_RESULT) {
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="cx">             var message = (typeof e === &quot;object&quot; &amp;&amp; e !== null) ? e.message : e;
</span><span class="lines">@@ -1209,14 +818,13 @@
</span><span class="cx">     {
</span><span class="cx">         var test_this = this;
</span><span class="cx"> 
</span><del>-        if (arguments.length === 1)
-        {
</del><ins>+        if (arguments.length === 1) {
</ins><span class="cx">             this_obj = test_this;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return function()
</span><span class="cx">         {
</span><del>-            test_this.step.apply(test_this, [func, this_obj].concat(
</del><ins>+            return test_this.step.apply(test_this, [func, this_obj].concat(
</ins><span class="cx">                 Array.prototype.slice.call(arguments)));
</span><span class="cx">         };
</span><span class="cx">     };
</span><span class="lines">@@ -1225,41 +833,57 @@
</span><span class="cx">     {
</span><span class="cx">         var test_this = this;
</span><span class="cx"> 
</span><del>-        if (arguments.length === 1)
-        {
</del><ins>+        if (arguments.length === 1) {
</ins><span class="cx">             this_obj = test_this;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return function()
</span><span class="cx">         {
</span><del>-            test_this.step.apply(test_this, [func, this_obj].concat(
-                Array.prototype.slice.call(arguments)));
</del><ins>+            if (func) {
+                test_this.step.apply(test_this, [func, this_obj].concat(
+                    Array.prototype.slice.call(arguments)));
+            }
</ins><span class="cx">             test_this.done();
</span><span class="cx">         };
</span><ins>+    };
+
+    Test.prototype.unreached_func = function(description)
+    {
+        return this.step_func(function() {
+            assert_unreached(description);
+        });
+    };
+
+    Test.prototype.add_cleanup = function(callback) {
+        this.cleanup_callbacks.push(callback);
+    };
+
+    Test.prototype.force_timeout = function() {
+        this.set_status(this.TIMEOUT);
+        this.phase = this.phases.HAS_RESULT;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     Test.prototype.set_timeout = function()
</span><span class="cx">     {
</span><del>-        if (this.timeout_length !== null)
-        {
</del><ins>+        if (this.timeout_length !== null) {
</ins><span class="cx">             var this_obj = this;
</span><span class="cx">             this.timeout_id = setTimeout(function()
</span><span class="cx">                                          {
</span><span class="cx">                                              this_obj.timeout();
</span><span class="cx">                                          }, this.timeout_length);
</span><span class="cx">         }
</span><del>-    }
</del><ins>+    };
</ins><span class="cx"> 
</span><span class="cx">     Test.prototype.set_status = function(status, message)
</span><span class="cx">     {
</span><span class="cx">         this.status = status;
</span><span class="cx">         this.message = message;
</span><del>-    }
</del><ins>+    };
</ins><span class="cx"> 
</span><span class="cx">     Test.prototype.timeout = function()
</span><span class="cx">     {
</span><span class="cx">         this.timeout_id = null;
</span><del>-        this.set_status(this.TIMEOUT, &quot;Test timed out&quot;)
</del><ins>+        this.set_status(this.TIMEOUT, &quot;Test timed out&quot;);
</ins><span class="cx">         this.phase = this.phases.HAS_RESULT;
</span><span class="cx">         this.done();
</span><span class="cx">     };
</span><span class="lines">@@ -1268,13 +892,13 @@
</span><span class="cx">     {
</span><span class="cx">         if (this.phase == this.phases.COMPLETE) {
</span><span class="cx">             return;
</span><del>-        } else if (this.phase &lt;= this.phases.STARTED)
-        {
</del><ins>+        }
+
+        if (this.phase &lt;= this.phases.STARTED) {
</ins><span class="cx">             this.set_status(this.PASS, null);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (this.status == this.NOTRUN)
-        {
</del><ins>+        if (this.status == this.NOTRUN) {
</ins><span class="cx">             alert(this.phase);
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -1282,8 +906,15 @@
</span><span class="cx"> 
</span><span class="cx">         clearTimeout(this.timeout_id);
</span><span class="cx">         tests.result(this);
</span><ins>+        this.cleanup();
</ins><span class="cx">     };
</span><span class="cx"> 
</span><ins>+    Test.prototype.cleanup = function() {
+        forEach(this.cleanup_callbacks,
+                function(cleanup_callback) {
+                    cleanup_callback();
+                });
+    };
</ins><span class="cx"> 
</span><span class="cx">     /*
</span><span class="cx">      * Harness
</span><span class="lines">@@ -1305,8 +936,7 @@
</span><span class="cx"> 
</span><span class="cx">     TestsStatus.prototype.structured_clone = function()
</span><span class="cx">     {
</span><del>-        if(!this._structured_clone)
-        {
</del><ins>+        if (!this._structured_clone) {
</ins><span class="cx">             var msg = this.message;
</span><span class="cx">             msg = msg ? String(msg) : msg;
</span><span class="cx">             this._structured_clone = merge({
</span><span class="lines">@@ -1340,6 +970,8 @@
</span><span class="cx"> 
</span><span class="cx">         this.allow_uncaught_exception = false;
</span><span class="cx"> 
</span><ins>+        this.file_is_test = false;
+
</ins><span class="cx">         this.timeout_multiplier = 1;
</span><span class="cx">         this.timeout_length = this.get_timeout();
</span><span class="cx">         this.timeout_id = null;
</span><span class="lines">@@ -1367,80 +999,73 @@
</span><span class="cx"> 
</span><span class="cx">     Tests.prototype.setup = function(func, properties)
</span><span class="cx">     {
</span><del>-        if (this.phase &gt;= this.phases.HAVE_RESULTS)
-        {
</del><ins>+        if (this.phase &gt;= this.phases.HAVE_RESULTS) {
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><del>-        if (this.phase &lt; this.phases.SETUP)
-        {
</del><ins>+
+        if (this.phase &lt; this.phases.SETUP) {
</ins><span class="cx">             this.phase = this.phases.SETUP;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         this.properties = properties;
</span><span class="cx"> 
</span><del>-        for (var p in properties)
-        {
-            if (properties.hasOwnProperty(p))
-            {
-                var value = properties[p]
</del><ins>+        for (var p in properties) {
+            if (properties.hasOwnProperty(p)) {
+                var value = properties[p];
</ins><span class="cx">                 if (p == &quot;allow_uncaught_exception&quot;) {
</span><span class="cx">                     this.allow_uncaught_exception = value;
</span><del>-                }
-                else if (p == &quot;explicit_done&quot; &amp;&amp; value)
-                {
</del><ins>+                } else if (p == &quot;explicit_done&quot; &amp;&amp; value) {
</ins><span class="cx">                     this.wait_for_finish = true;
</span><del>-                }
-                else if (p == &quot;explicit_timeout&quot; &amp;&amp; value) {
</del><ins>+                } else if (p == &quot;explicit_timeout&quot; &amp;&amp; value) {
</ins><span class="cx">                     this.timeout_length = null;
</span><span class="cx">                     if (this.timeout_id)
</span><span class="cx">                     {
</span><span class="cx">                         clearTimeout(this.timeout_id);
</span><span class="cx">                     }
</span><del>-                }
-                else if (p == &quot;timeout_multiplier&quot;)
-                {
</del><ins>+                } else if (p == &quot;timeout_multiplier&quot;) {
</ins><span class="cx">                     this.timeout_multiplier = value;
</span><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (func)
-        {
-            try
-            {
</del><ins>+        if (func) {
+            try {
</ins><span class="cx">                 func();
</span><del>-            } catch(e)
-            {
</del><ins>+            } catch (e) {
</ins><span class="cx">                 this.status.status = this.status.ERROR;
</span><del>-                this.status.message = e;
-            };
</del><ins>+                this.status.message = String(e);
+            }
</ins><span class="cx">         }
</span><span class="cx">         this.set_timeout();
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    Tests.prototype.get_timeout = function()
-    {
</del><ins>+    Tests.prototype.set_file_is_test = function() {
+        if (this.tests.length &gt; 0) {
+            throw new Error(&quot;Tried to set file as test after creating a test&quot;);
+        }
+        this.wait_for_finish = true;
+        this.file_is_test = true;
+        // Create the test, which will add it to the list of tests
+        async_test();
+    };
+
+    Tests.prototype.get_timeout = function() {
</ins><span class="cx">         var metas = document.getElementsByTagName(&quot;meta&quot;);
</span><del>-        for (var i=0; i&lt;metas.length; i++)
-        {
-            if (metas[i].name == &quot;timeout&quot;)
-            {
-                if (metas[i].content == &quot;long&quot;)
-                {
</del><ins>+        for (var i = 0; i &lt; metas.length; i++) {
+            if (metas[i].name == &quot;timeout&quot;) {
+                if (metas[i].content == &quot;long&quot;) {
</ins><span class="cx">                     return settings.harness_timeout.long;
</span><span class="cx">                 }
</span><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">         return settings.harness_timeout.normal;
</span><del>-    }
</del><ins>+    };
</ins><span class="cx"> 
</span><del>-    Tests.prototype.set_timeout = function()
-    {
</del><ins>+    Tests.prototype.set_timeout = function() {
</ins><span class="cx">         var this_obj = this;
</span><span class="cx">         clearTimeout(this.timeout_id);
</span><del>-        if (this.timeout_length !== null)
-        {
</del><ins>+        if (this.timeout_length !== null) {
</ins><span class="cx">             this.timeout_id = setTimeout(function() {
</span><span class="cx">                                              this_obj.timeout();
</span><span class="cx">                                          }, this.timeout_length);
</span><span class="lines">@@ -1448,7 +1073,9 @@
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     Tests.prototype.timeout = function() {
</span><del>-        this.status.status = this.status.TIMEOUT;
</del><ins>+        if (this.status.status === null) {
+            this.status.status = this.status.TIMEOUT;
+        }
</ins><span class="cx">         this.complete();
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="lines">@@ -1470,7 +1097,7 @@
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     Tests.prototype.all_done = function() {
</span><del>-        return (this.all_loaded &amp;&amp; this.num_pending === 0 &amp;&amp;
</del><ins>+        return (this.tests.length &gt; 0 &amp;&amp; this.all_loaded &amp;&amp; this.num_pending === 0 &amp;&amp;
</ins><span class="cx">                 !this.wait_for_finish &amp;&amp; !this.processing_callbacks);
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="lines">@@ -1489,22 +1116,16 @@
</span><span class="cx">         forEach_windows(
</span><span class="cx">                 function(w, is_same_origin)
</span><span class="cx">                 {
</span><del>-                    if(is_same_origin &amp;&amp; w.start_callback)
-                    {
-                        try
-                        {
</del><ins>+                    if (is_same_origin &amp;&amp; w.start_callback) {
+                        try {
</ins><span class="cx">                             w.start_callback(this_obj.properties);
</span><del>-                        }
-                        catch(e)
-                        {
-                            if (debug)
-                            {
-                                throw(e);
</del><ins>+                        } catch (e) {
+                            if (debug) {
+                                throw e;
</ins><span class="cx">                             }
</span><span class="cx">                         }
</span><span class="cx">                     }
</span><del>-                    if (supports_post_message(w) &amp;&amp; w !== self)
-                    {
</del><ins>+                    if (supports_post_message(w) &amp;&amp; w !== self) {
</ins><span class="cx">                         w.postMessage({
</span><span class="cx">                             type: &quot;start&quot;,
</span><span class="cx">                             properties: this_obj.properties
</span><span class="lines">@@ -1515,8 +1136,7 @@
</span><span class="cx"> 
</span><span class="cx">     Tests.prototype.result = function(test)
</span><span class="cx">     {
</span><del>-        if (this.phase &gt; this.phases.HAVE_RESULTS)
-        {
</del><ins>+        if (this.phase &gt; this.phases.HAVE_RESULTS) {
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">         this.phase = this.phases.HAVE_RESULTS;
</span><span class="lines">@@ -1536,21 +1156,16 @@
</span><span class="cx">         forEach_windows(
</span><span class="cx">                 function(w, is_same_origin)
</span><span class="cx">                 {
</span><del>-                    if(is_same_origin &amp;&amp; w.result_callback)
-                    {
-                        try
-                        {
</del><ins>+                    if (is_same_origin &amp;&amp; w.result_callback) {
+                        try {
</ins><span class="cx">                             w.result_callback(test);
</span><del>-                        }
-                        catch(e)
-                        {
-                            if(debug) {
</del><ins>+                        } catch (e) {
+                            if (debug) {
</ins><span class="cx">                                 throw e;
</span><span class="cx">                             }
</span><span class="cx">                         }
</span><span class="cx">                     }
</span><del>-                    if (supports_post_message(w) &amp;&amp; w !== self)
-                    {
</del><ins>+                    if (supports_post_message(w) &amp;&amp; w !== self) {
</ins><span class="cx">                         w.postMessage({
</span><span class="cx">                             type: &quot;result&quot;,
</span><span class="cx">                             test: test.structured_clone()
</span><span class="lines">@@ -1558,8 +1173,7 @@
</span><span class="cx">                     }
</span><span class="cx">                 });
</span><span class="cx">         this.processing_callbacks = false;
</span><del>-        if (this_obj.all_done())
-        {
</del><ins>+        if (this_obj.all_done()) {
</ins><span class="cx">             this_obj.complete();
</span><span class="cx">         }
</span><span class="cx">     };
</span><span class="lines">@@ -1573,9 +1187,9 @@
</span><span class="cx">         this.tests.forEach(
</span><span class="cx">             function(x)
</span><span class="cx">             {
</span><del>-                if(x.status === x.NOTRUN)
-                {
</del><ins>+                if (x.status === x.NOTRUN) {
</ins><span class="cx">                     this_obj.notify_result(x);
</span><ins>+                    x.cleanup();
</ins><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx">         );
</span><span class="lines">@@ -1591,8 +1205,7 @@
</span><span class="cx">                         {
</span><span class="cx">                             return test.structured_clone();
</span><span class="cx">                         });
</span><del>-        if (this.status.status === null)
-        {
</del><ins>+        if (this.status.status === null) {
</ins><span class="cx">             this.status.status = this.status.OK;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -1605,22 +1218,16 @@
</span><span class="cx">         forEach_windows(
</span><span class="cx">                 function(w, is_same_origin)
</span><span class="cx">                 {
</span><del>-                    if(is_same_origin &amp;&amp; w.completion_callback)
-                    {
-                        try
-                        {
</del><ins>+                    if (is_same_origin &amp;&amp; w.completion_callback) {
+                        try {
</ins><span class="cx">                             w.completion_callback(this_obj.tests, this_obj.status);
</span><del>-                        }
-                        catch(e)
-                        {
-                            if (debug)
-                            {
</del><ins>+                        } catch (e) {
+                            if (debug) {
</ins><span class="cx">                                 throw e;
</span><span class="cx">                             }
</span><span class="cx">                         }
</span><span class="cx">                     }
</span><del>-                    if (supports_post_message(w) &amp;&amp; w !== self)
-                    {
</del><ins>+                    if (supports_post_message(w) &amp;&amp; w !== self) {
</ins><span class="cx">                         w.postMessage({
</span><span class="cx">                             type: &quot;complete&quot;,
</span><span class="cx">                             tests: tests,
</span><span class="lines">@@ -1632,18 +1239,25 @@
</span><span class="cx"> 
</span><span class="cx">     var tests = new Tests();
</span><span class="cx"> 
</span><del>-    window.onerror = function(msg) {
-        if (!tests.allow_uncaught_exception)
-        {
</del><ins>+    addEventListener(&quot;error&quot;, function(e) {
+        if (tests.file_is_test) {
+            var test = tests.tests[0];
+            if (test.phase &gt;= test.phases.HAS_RESULT) {
+                return;
+            }
+            var message = e.message;
+            test.set_status(test.FAIL, message);
+            test.phase = test.phases.HAS_RESULT;
+            test.done();
+            done();
+        } else if (!tests.allow_uncaught_exception) {
</ins><span class="cx">             tests.status.status = tests.status.ERROR;
</span><del>-            tests.status.message = msg;
-            tests.complete();
</del><ins>+            tests.status.message = e.message;
</ins><span class="cx">         }
</span><del>-    }
</del><ins>+    });
</ins><span class="cx"> 
</span><span class="cx">     function timeout() {
</span><del>-        if (tests.timeout_length === null)
-        {
</del><ins>+        if (tests.timeout_length === null) {
</ins><span class="cx">             tests.timeout();
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="lines">@@ -1672,11 +1286,11 @@
</span><span class="cx">     */
</span><span class="cx"> 
</span><span class="cx">     function Output() {
</span><del>-      this.output_document = document;
-      this.output_node = null;
-      this.done_count = 0;
-      this.enabled = settings.output;
-      this.phase = this.INITIAL;
</del><ins>+        this.output_document = document;
+        this.output_node = null;
+        this.done_count = 0;
+        this.enabled = settings.output;
+        this.phase = this.INITIAL;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     Output.prototype.INITIAL = 0;
</span><span class="lines">@@ -1695,8 +1309,7 @@
</span><span class="cx">                                         properties.output : settings.output);
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    Output.prototype.init = function(properties)
-    {
</del><ins>+    Output.prototype.init = function(properties) {
</ins><span class="cx">         if (this.phase &gt;= this.STARTED) {
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="lines">@@ -1708,63 +1321,57 @@
</span><span class="cx">         this.phase = this.STARTED;
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    Output.prototype.resolve_log = function()
-    {
</del><ins>+    Output.prototype.resolve_log = function() {
</ins><span class="cx">         var output_document;
</span><del>-        if (typeof this.output_document === &quot;function&quot;)
-        {
</del><ins>+        if (typeof this.output_document === &quot;function&quot;) {
</ins><span class="cx">             output_document = this.output_document.apply(undefined);
</span><del>-        } else 
-        {
</del><ins>+        } else {
</ins><span class="cx">             output_document = this.output_document;
</span><span class="cx">         }
</span><del>-        if (!output_document)
-        {
</del><ins>+        if (!output_document) {
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">         var node = output_document.getElementById(&quot;log&quot;);
</span><del>-        if (node)
-        {
-            this.output_document = output_document;
-            this.output_node = node;
</del><ins>+        if (!node) {
+            if (!document.body || document.readyState == &quot;loading&quot;) {
+                return;
+            }
+            node = output_document.createElement(&quot;div&quot;);
+            node.id = &quot;log&quot;;
+            output_document.body.appendChild(node);
</ins><span class="cx">         }
</span><ins>+        this.output_document = output_document;
+        this.output_node = node;
</ins><span class="cx">     };
</span><span class="cx"> 
</span><del>-    Output.prototype.show_status = function(test)
-    {
-        if (this.phase &lt; this.STARTED)
-        {
</del><ins>+    Output.prototype.show_status = function() {
+        if (this.phase &lt; this.STARTED) {
</ins><span class="cx">             this.init();
</span><span class="cx">         }
</span><del>-        if (!this.enabled)
-        {
</del><ins>+        if (!this.enabled) {
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><del>-        if (this.phase &lt; this.HAVE_RESULTS)
-        {
</del><ins>+        if (this.phase &lt; this.HAVE_RESULTS) {
</ins><span class="cx">             this.resolve_log();
</span><span class="cx">             this.phase = this.HAVE_RESULTS;
</span><span class="cx">         }
</span><span class="cx">         this.done_count++;
</span><del>-        if (this.output_node)
-        {
-            if (this.done_count &lt; 100
-            || (this.done_count &lt; 1000 &amp;&amp; this.done_count % 100 == 0)
-            || this.done_count % 1000 == 0) {
-                this.output_node.textContent = &quot;Running, &quot;
-                    + this.done_count + &quot; complete, &quot;
-                    + tests.num_pending + &quot; remain&quot;;
</del><ins>+        if (this.output_node) {
+            if (this.done_count &lt; 100 ||
+                (this.done_count &lt; 1000 &amp;&amp; this.done_count % 100 === 0) ||
+                this.done_count % 1000 === 0) {
+                this.output_node.textContent = &quot;Running, &quot; +
+                    this.done_count + &quot; complete, &quot; +
+                    tests.num_pending + &quot; remain&quot;;
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    Output.prototype.show_results = function (tests, harness_status)
-    {
</del><ins>+    Output.prototype.show_results = function (tests, harness_status) {
</ins><span class="cx">         if (this.phase &gt;= this.COMPLETE) {
</span><span class="cx">             return;
</span><span class="cx">         }
</span><del>-        if (!this.enabled)
-        {
</del><ins>+        if (!this.enabled) {
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">         if (!this.output_node) {
</span><span class="lines">@@ -1773,14 +1380,12 @@
</span><span class="cx">         this.phase = this.COMPLETE;
</span><span class="cx"> 
</span><span class="cx">         var log = this.output_node;
</span><del>-        if (!log)
-        {
</del><ins>+        if (!log) {
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">         var output_document = this.output_document;
</span><span class="cx"> 
</span><del>-        while (log.lastChild)
-        {
</del><ins>+        while (log.lastChild) {
</ins><span class="cx">             log.removeChild(log.lastChild);
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -1806,10 +1411,10 @@
</span><span class="cx">         status_text[Test.prototype.NOTRUN] = &quot;Not Run&quot;;
</span><span class="cx"> 
</span><span class="cx">         var status_number = {};
</span><del>-        forEach(tests, function(test) {
</del><ins>+        forEach(tests,
+                function(test) {
</ins><span class="cx">                     var status = status_text[test.status];
</span><del>-                    if (status_number.hasOwnProperty(status))
-                    {
</del><ins>+                    if (status_number.hasOwnProperty(status)) {
</ins><span class="cx">                         status_number[status] += 1;
</span><span class="cx">                     } else {
</span><span class="cx">                         status_number[status] = 1;
</span><span class="lines">@@ -1823,38 +1428,28 @@
</span><span class="cx"> 
</span><span class="cx">         var summary_template = [&quot;section&quot;, {&quot;id&quot;:&quot;summary&quot;},
</span><span class="cx">                                 [&quot;h2&quot;, {}, &quot;Summary&quot;],
</span><del>-                                function(vars)
</del><ins>+                                function()
</ins><span class="cx">                                 {
</span><del>-                                    if (harness_status.status === harness_status.OK)
-                                    {
-                                        return null;
-                                    }
-                                    else
-                                    {
-                                        var status = status_text_harness[harness_status.status];
-                                        var rv = [[&quot;p&quot;, {&quot;class&quot;:status_class(status)}]];
</del><span class="cx"> 
</span><del>-                                        if (harness_status.status === harness_status.ERROR)
-                                        {
-                                            rv[0].push(&quot;Harness encountered an error:&quot;);
-                                            rv.push([&quot;pre&quot;, {}, harness_status.message]);
-                                        }
-                                        else if (harness_status.status === harness_status.TIMEOUT)
-                                        {
-                                            rv[0].push(&quot;Harness timed out.&quot;);
-                                        }
-                                        else
-                                        {
-                                            rv[0].push(&quot;Harness got an unexpected status.&quot;);
-                                        }
</del><ins>+                                    var status = status_text_harness[harness_status.status];
+                                    var rv = [[&quot;section&quot;, {},
+                                               [&quot;p&quot;, {},
+                                                &quot;Harness status: &quot;,
+                                                [&quot;span&quot;, {&quot;class&quot;:status_class(status)},
+                                                 status
+                                                ],
+                                               ]
+                                              ]];
</ins><span class="cx"> 
</span><del>-                                        return rv;
</del><ins>+                                    if (harness_status.status === harness_status.ERROR) {
+                                        rv[0].push([&quot;pre&quot;, {}, harness_status.message]);
</ins><span class="cx">                                     }
</span><ins>+                                    return rv;
</ins><span class="cx">                                 },
</span><span class="cx">                                 [&quot;p&quot;, {}, &quot;Found ${num_tests} tests&quot;],
</span><del>-                                function(vars) {
</del><ins>+                                function() {
</ins><span class="cx">                                     var rv = [[&quot;div&quot;, {}]];
</span><del>-                                    var i=0;
</del><ins>+                                    var i = 0;
</ins><span class="cx">                                     while (status_text.hasOwnProperty(i)) {
</span><span class="cx">                                         if (status_number.hasOwnProperty(status_text[i])) {
</span><span class="cx">                                             var status = status_text[i];
</span><span class="lines">@@ -1866,7 +1461,8 @@
</span><span class="cx">                                         i++;
</span><span class="cx">                                     }
</span><span class="cx">                                     return rv;
</span><del>-                                }];
</del><ins>+                                },
+                               ];
</ins><span class="cx"> 
</span><span class="cx">         log.appendChild(render(summary_template, {num_tests:tests.length}, output_document));
</span><span class="cx"> 
</span><span class="lines">@@ -1876,8 +1472,7 @@
</span><span class="cx">                     on_event(element, &quot;click&quot;,
</span><span class="cx">                              function(e)
</span><span class="cx">                              {
</span><del>-                                 if (output_document.getElementById(&quot;results&quot;) === null)
-                                 {
</del><ins>+                                 if (output_document.getElementById(&quot;results&quot;) === null) {
</ins><span class="cx">                                      e.preventDefault();
</span><span class="cx">                                      return;
</span><span class="cx">                                  }
</span><span class="lines">@@ -1930,22 +1525,22 @@
</span><span class="cx"> 
</span><span class="cx">         log.appendChild(document.createElementNS(xhtml_ns, &quot;section&quot;));
</span><span class="cx">         var assertions = has_assertions();
</span><del>-        var html = &quot;&lt;h2&gt;Details&lt;/h2&gt;&lt;table id='results' &quot; + (assertions ? &quot;class='assertions'&quot; : &quot;&quot; ) + &quot;&gt;&quot;
-            + &quot;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Result&lt;/th&gt;&lt;th&gt;Test Name&lt;/th&gt;&quot;
-            + (assertions ? &quot;&lt;th&gt;Assertion&lt;/th&gt;&quot; : &quot;&quot;)
-            + &quot;&lt;th&gt;Message&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&quot;
-            + &quot;&lt;tbody&gt;&quot;;
</del><ins>+        var html = &quot;&lt;h2&gt;Details&lt;/h2&gt;&lt;table id='results' &quot; + (assertions ? &quot;class='assertions'&quot; : &quot;&quot; ) + &quot;&gt;&quot; +
+            &quot;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Result&lt;/th&gt;&lt;th&gt;Test Name&lt;/th&gt;&quot; +
+            (assertions ? &quot;&lt;th&gt;Assertion&lt;/th&gt;&quot; : &quot;&quot;) +
+            &quot;&lt;th&gt;Message&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&quot; +
+            &quot;&lt;tbody&gt;&quot;;
</ins><span class="cx">         for (var i = 0; i &lt; tests.length; i++) {
</span><del>-            html += '&lt;tr class=&quot;'
-                + escape_html(status_class(status_text[tests[i].status]))
-                + '&quot;&gt;&lt;td&gt;'
-                + escape_html(status_text[tests[i].status])
-                + &quot;&lt;/td&gt;&lt;td&gt;&quot;
-                + escape_html(tests[i].name)
-                + &quot;&lt;/td&gt;&lt;td&gt;&quot;
-                + (assertions ? escape_html(get_assertion(tests[i])) + &quot;&lt;/td&gt;&lt;td&gt;&quot; : &quot;&quot;)
-                + escape_html(tests[i].message ? tests[i].message : &quot; &quot;)
-                + &quot;&lt;/td&gt;&lt;/tr&gt;&quot;;
</del><ins>+            html += '&lt;tr class=&quot;' +
+                escape_html(status_class(status_text[tests[i].status])) +
+                '&quot;&gt;&lt;td&gt;' +
+                escape_html(status_text[tests[i].status]) +
+                &quot;&lt;/td&gt;&lt;td&gt;&quot; +
+                escape_html(tests[i].name) +
+                &quot;&lt;/td&gt;&lt;td&gt;&quot; +
+                (assertions ? escape_html(get_assertion(tests[i])) + &quot;&lt;/td&gt;&lt;td&gt;&quot; : &quot;&quot;) +
+                escape_html(tests[i].message ? tests[i].message : &quot; &quot;) +
+                &quot;&lt;/td&gt;&lt;/tr&gt;&quot;;
</ins><span class="cx">         }
</span><span class="cx">         html += &quot;&lt;/tbody&gt;&lt;/table&gt;&quot;;
</span><span class="cx">         try {
</span><span class="lines">@@ -1960,7 +1555,7 @@
</span><span class="cx"> 
</span><span class="cx">     var output = new Output();
</span><span class="cx">     add_start_callback(function (properties) {output.init(properties);});
</span><del>-    add_result_callback(function (test) {output.show_status(tests);});
</del><ins>+    add_result_callback(function () {output.show_status();});
</ins><span class="cx">     add_completion_callback(function (tests, harness_status) {output.show_results(tests, harness_status);});
</span><span class="cx"> 
</span><span class="cx">     /*
</span><span class="lines">@@ -2005,154 +1600,126 @@
</span><span class="cx">     {
</span><span class="cx">         if (typeof template === &quot;function&quot;) {
</span><span class="cx">             var replacement = template(substitutions);
</span><del>-            if (replacement)
-            {
-                var rv = substitute(replacement, substitutions);
-                return rv;
-            }
-            else
-            {
</del><ins>+            if (!replacement) {
</ins><span class="cx">                 return null;
</span><span class="cx">             }
</span><ins>+
+            return substitute(replacement, substitutions);
</ins><span class="cx">         }
</span><del>-        else if (is_single_node(template))
-        {
</del><ins>+
+        if (is_single_node(template)) {
</ins><span class="cx">             return substitute_single(template, substitutions);
</span><span class="cx">         }
</span><del>-        else
-        {
-            return filter(map(template, function(x) {
-                                  return substitute(x, substitutions);
-                              }), function(x) {return x !== null;});
-        }
</del><ins>+
+        return filter(map(template, function(x) {
+                              return substitute(x, substitutions);
+                          }), function(x) {return x !== null;});
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     function substitute_single(template, substitutions)
</span><span class="cx">     {
</span><del>-        var substitution_re = /\${([^ }]*)}/g;
</del><ins>+        var substitution_re = /\$\{([^ }]*)\}/g;
</ins><span class="cx"> 
</span><span class="cx">         function do_substitution(input) {
</span><span class="cx">             var components = input.split(substitution_re);
</span><span class="cx">             var rv = [];
</span><del>-            for (var i=0; i&lt;components.length; i+=2)
-            {
</del><ins>+            for (var i = 0; i &lt; components.length; i += 2) {
</ins><span class="cx">                 rv.push(components[i]);
</span><del>-                if (components[i+1])
-                {
-                    rv.push(String(substitutions[components[i+1]]));
</del><ins>+                if (components[i + 1]) {
+                    rv.push(String(substitutions[components[i + 1]]));
</ins><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx">             return rv;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var rv = [];
-        rv.push(do_substitution(String(template[0])).join(&quot;&quot;));
-
-        if (template[0] === &quot;{text}&quot;) {
-            substitute_children(template.slice(1), rv);
-        } else {
-            substitute_attrs(template[1], rv);
-            substitute_children(template.slice(2), rv);
-        }
-
</del><span class="cx">         function substitute_attrs(attrs, rv)
</span><span class="cx">         {
</span><span class="cx">             rv[1] = {};
</span><del>-            for (var name in template[1])
-            {
-                if (attrs.hasOwnProperty(name))
-                {
</del><ins>+            for (var name in template[1]) {
+                if (attrs.hasOwnProperty(name)) {
</ins><span class="cx">                     var new_name = do_substitution(name).join(&quot;&quot;);
</span><span class="cx">                     var new_value = do_substitution(attrs[name]).join(&quot;&quot;);
</span><span class="cx">                     rv[1][new_name] = new_value;
</span><del>-                };
</del><ins>+                }
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function substitute_children(children, rv)
</span><span class="cx">         {
</span><del>-            for (var i=0; i&lt;children.length; i++)
-            {
</del><ins>+            for (var i = 0; i &lt; children.length; i++) {
</ins><span class="cx">                 if (children[i] instanceof Object) {
</span><span class="cx">                     var replacement = substitute(children[i], substitutions);
</span><del>-                    if (replacement !== null)
-                    {
-                        if (is_single_node(replacement))
-                        {
</del><ins>+                    if (replacement !== null) {
+                        if (is_single_node(replacement)) {
</ins><span class="cx">                             rv.push(replacement);
</span><del>-                        }
-                        else
-                        {
</del><ins>+                        } else {
</ins><span class="cx">                             extend(rv, replacement);
</span><span class="cx">                         }
</span><span class="cx">                     }
</span><del>-                }
-                else
-                {
</del><ins>+                } else {
</ins><span class="cx">                     extend(rv, do_substitution(String(children[i])));
</span><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx">             return rv;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        var rv = [];
+        rv.push(do_substitution(String(template[0])).join(&quot;&quot;));
+
+        if (template[0] === &quot;{text}&quot;) {
+            substitute_children(template.slice(1), rv);
+        } else {
+            substitute_attrs(template[1], rv);
+            substitute_children(template.slice(2), rv);
+        }
+
</ins><span class="cx">         return rv;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>- function make_dom_single(template, doc)
- {
-     var output_document = doc || document;
-     if (template[0] === &quot;{text}&quot;)
-     {
-         var element = output_document.createTextNode(&quot;&quot;);
-         for (var i=1; i&lt;template.length; i++)
-         {
-             element.data += template[i];
-         }
-     }
-     else
-     {
-         var element = output_document.createElementNS(xhtml_ns, template[0]);
-         for (var name in template[1]) {
-             if (template[1].hasOwnProperty(name))
-             {
-                 element.setAttribute(name, template[1][name]);
-             }
-         }
-         for (var i=2; i&lt;template.length; i++)
-         {
-             if (template[i] instanceof Object)
-             {
-                 var sub_element = make_dom(template[i]);
-                 element.appendChild(sub_element);
-             }
-             else
-             {
-                 var text_node = output_document.createTextNode(template[i]);
-                 element.appendChild(text_node);
-             }
-         }
-     }
</del><ins>+    function make_dom_single(template, doc)
+    {
+        var output_document = doc || document;
+        var element;
+        if (template[0] === &quot;{text}&quot;) {
+            element = output_document.createTextNode(&quot;&quot;);
+            for (var i = 1; i &lt; template.length; i++) {
+                element.data += template[i];
+            }
+        } else {
+            element = output_document.createElementNS(xhtml_ns, template[0]);
+            for (var name in template[1]) {
+                if (template[1].hasOwnProperty(name)) {
+                    element.setAttribute(name, template[1][name]);
+                }
+            }
+            for (var i = 2; i &lt; template.length; i++) {
+                if (template[i] instanceof Object) {
+                    var sub_element = make_dom(template[i]);
+                    element.appendChild(sub_element);
+                } else {
+                    var text_node = output_document.createTextNode(template[i]);
+                    element.appendChild(text_node);
+                }
+            }
+        }
</ins><span class="cx"> 
</span><del>-     return element;
- }
</del><ins>+        return element;
+    }
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>- function make_dom(template, substitutions, output_document)
</del><ins>+    function make_dom(template, substitutions, output_document)
</ins><span class="cx">     {
</span><del>-        if (is_single_node(template))
-        {
</del><ins>+        if (is_single_node(template)) {
</ins><span class="cx">             return make_dom_single(template, output_document);
</span><span class="cx">         }
</span><del>-        else
-        {
-            return map(template, function(x) {
-                           return make_dom_single(x, output_document);
-                       });
-        }
</del><ins>+
+        return map(template, function(x) {
+                       return make_dom_single(x, output_document);
+                   });
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>- function render(template, substitutions, output_document)
</del><ins>+    function render(template, substitutions, output_document)
</ins><span class="cx">     {
</span><span class="cx">         return make_dom(substitute(template, substitutions), output_document);
</span><span class="cx">     }
</span><span class="lines">@@ -2162,11 +1729,14 @@
</span><span class="cx">      */
</span><span class="cx">     function assert(expected_true, function_name, description, error, substitutions)
</span><span class="cx">     {
</span><del>-        if (expected_true !== true)
-        {
-            throw new AssertionError(make_message(function_name, description,
-                                                  error, substitutions));
</del><ins>+        if (tests.tests.length === 0) {
+            tests.set_file_is_test();
</ins><span class="cx">         }
</span><ins>+        if (expected_true !== true) {
+            var msg = make_message(function_name, description,
+                                   error, substitutions);
+            throw new AssertionError(msg);
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     function AssertionError(message)
</span><span class="lines">@@ -2174,6 +1744,10 @@
</span><span class="cx">         this.message = message;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    AssertionError.prototype.toString = function() {
+        return this.message;
+    };
+
</ins><span class="cx">     function make_message(function_name, description, error, substitutions)
</span><span class="cx">     {
</span><span class="cx">         for (var p in substitutions) {
</span><span class="lines">@@ -2190,10 +1764,8 @@
</span><span class="cx"> 
</span><span class="cx">     function filter(array, callable, thisObj) {
</span><span class="cx">         var rv = [];
</span><del>-        for (var i=0; i&lt;array.length; i++)
-        {
-            if (array.hasOwnProperty(i))
-            {
</del><ins>+        for (var i = 0; i &lt; array.length; i++) {
+            if (array.hasOwnProperty(i)) {
</ins><span class="cx">                 var pass = callable.call(thisObj, array[i], i, array);
</span><span class="cx">                 if (pass) {
</span><span class="cx">                     rv.push(array[i]);
</span><span class="lines">@@ -2207,10 +1779,8 @@
</span><span class="cx">     {
</span><span class="cx">         var rv = [];
</span><span class="cx">         rv.length = array.length;
</span><del>-        for (var i=0; i&lt;array.length; i++)
-        {
-            if (array.hasOwnProperty(i))
-            {
</del><ins>+        for (var i = 0; i &lt; array.length; i++) {
+            if (array.hasOwnProperty(i)) {
</ins><span class="cx">                 rv[i] = callable.call(thisObj, array[i], i, array);
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="lines">@@ -2224,10 +1794,8 @@
</span><span class="cx"> 
</span><span class="cx">     function forEach (array, callback, thisObj)
</span><span class="cx">     {
</span><del>-        for (var i=0; i&lt;array.length; i++)
-        {
-            if (array.hasOwnProperty(i))
-            {
</del><ins>+        for (var i = 0; i &lt; array.length; i++) {
+            if (array.hasOwnProperty(i)) {
</ins><span class="cx">                 callback.call(thisObj, array[i], i, array);
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="lines">@@ -2237,8 +1805,7 @@
</span><span class="cx">     {
</span><span class="cx">         var rv = {};
</span><span class="cx">         var p;
</span><del>-        for (p in a)
-        {
</del><ins>+        for (p in a) {
</ins><span class="cx">             rv[p] = a[p];
</span><span class="cx">         }
</span><span class="cx">         for (p in b) {
</span><span class="lines">@@ -2251,10 +1818,8 @@
</span><span class="cx">     {
</span><span class="cx">         var components = name.split(&quot;.&quot;);
</span><span class="cx">         var target = window;
</span><del>-        for (var i=0; i&lt;components.length - 1; i++)
-        {
-            if (!(components[i] in target))
-            {
</del><ins>+        for (var i = 0; i &lt; components.length - 1; i++) {
+            if (!(components[i] in target)) {
</ins><span class="cx">                 target[components[i]] = {};
</span><span class="cx">             }
</span><span class="cx">             target = target[components[i]];
</span><span class="lines">@@ -2274,8 +1839,7 @@
</span><span class="cx">             var i = 0;
</span><span class="cx">             var so;
</span><span class="cx">             var origins = location.ancestorOrigins;
</span><del>-            while (w != w.parent)
-            {
</del><ins>+            while (w != w.parent) {
</ins><span class="cx">                 w = w.parent;
</span><span class="cx">                 // In WebKit, calls to parent windows' properties that aren't on the same
</span><span class="cx">                 // origin cause an error message to be displayed in the error console but
</span><span class="lines">@@ -2288,19 +1852,16 @@
</span><span class="cx">                 // `location.ancestorOrigins` property which returns an ordered list of
</span><span class="cx">                 // the origins of enclosing windows. See:
</span><span class="cx">                 // http://trac.webkit.org/changeset/113945.
</span><del>-                if(origins) {
</del><ins>+                if (origins) {
</ins><span class="cx">                     so = (location.origin == origins[i]);
</span><del>-                }
-                else
-                {
</del><ins>+                } else {
</ins><span class="cx">                     so = is_same_origin(w);
</span><span class="cx">                 }
</span><span class="cx">                 cache.push([w, so]);
</span><span class="cx">                 i++;
</span><span class="cx">             }
</span><span class="cx">             w = window.opener;
</span><del>-            if(w)
-            {
</del><ins>+            if (w) {
</ins><span class="cx">                 // window.opener isn't included in the `location.ancestorOrigins` prop.
</span><span class="cx">                 // We'll just have to deal with a simple check and an error msg on WebKit
</span><span class="cx">                 // browsers in this case.
</span><span class="lines">@@ -2320,7 +1881,7 @@
</span><span class="cx">         try {
</span><span class="cx">             'random_prop' in w;
</span><span class="cx">             return true;
</span><del>-        } catch(e) {
</del><ins>+        } catch (e) {
</ins><span class="cx">             return false;
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="lines">@@ -2337,27 +1898,24 @@
</span><span class="cx">         // not from the same origin AND post message is not supported in that
</span><span class="cx">         // browser. So just doing an existence test here won't do, you also need
</span><span class="cx">         // to wrap it in a try..cacth block.
</span><del>-        try
-        {
</del><ins>+        try {
</ins><span class="cx">             type = typeof w.postMessage;
</span><del>-            if (type === &quot;function&quot;)
-            {
</del><ins>+            if (type === &quot;function&quot;) {
</ins><span class="cx">                 supports = true;
</span><span class="cx">             }
</span><ins>+
</ins><span class="cx">             // IE8 supports postMessage, but implements it as a host object which
</span><span class="cx">             // returns &quot;object&quot; as its `typeof`.
</span><del>-            else if (type === &quot;object&quot;)
-            {
</del><ins>+            else if (type === &quot;object&quot;) {
</ins><span class="cx">                 supports = true;
</span><span class="cx">             }
</span><ins>+
</ins><span class="cx">             // This is the case where postMessage isn't supported AND accessing a
</span><span class="cx">             // window property across origins does NOT throw (e.g. old Safari browser).
</span><del>-            else
-            {
</del><ins>+            else {
</ins><span class="cx">                 supports = false;
</span><span class="cx">             }
</span><del>-        }
-        catch(e) {
</del><ins>+        } catch (e) {
</ins><span class="cx">             // This is the case where postMessage isn't supported AND accessing a
</span><span class="cx">             // window property across origins throws (e.g. old Firefox browser).
</span><span class="cx">             supports = false;
</span></span></pre>
</div>
</div>

</body>
</html>