Skip to content
This repository has been archived by the owner on Sep 19, 2018. It is now read-only.

Commit

Permalink
Don't error out trying to access cross-origin functions when document…
Browse files Browse the repository at this point in the history
….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.
  • Loading branch information
jgraham committed Apr 9, 2015
1 parent 87c22bb commit c48d50e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions testharness.js
Expand Up @@ -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;
}
}
}
}
Expand Down

0 comments on commit c48d50e

Please sign in to comment.