From c48d50e0b61727d382c83b2a859ff66c27c984bb Mon Sep 17 00:00:00 2001 From: James Graham Date: Thu, 9 Apr 2015 23:36:52 +0100 Subject: [PATCH] Don't error out trying to access cross-origin functions when document.domain got set. Setting document.domain changes the origin of the current document to be different to the origin it had before. This invalidates the cache of origins, so in this case we need to catch the error and make sure we don't try to call a cross-origin function. --- testharness.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/testharness.js b/testharness.js index 7480103..ad671ab 100644 --- a/testharness.js +++ b/testharness.js @@ -71,13 +71,22 @@ policies and contribution forms [3]. WindowTestEnvironment.prototype._dispatch = function(selector, callback_args, message_arg) { this._forEach_windows( - function(w, is_same_origin) { - if (is_same_origin && selector in w) { + function(w, same_origin) { + if (same_origin) { try { - w[selector].apply(undefined, callback_args); - } catch (e) { - if (debug) { - throw e; + var has_selector = selector in w; + } catch(e) { + // If document.domain was set at some point same_origin can be + // wrong and the above will fail. + has_selector = false; + } + if (has_selector) { + try { + w[selector].apply(undefined, callback_args); + } catch (e) { + if (debug) { + throw e; + } } } }