Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial fix for #10963.
- Loading branch information
Showing
15 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
use dom::bindings::js::{JS, Root}; | ||
use dom::globalscope::GlobalScope; | ||
use std::cell::RefCell; | ||
use js::jsapi::JSTracer; | ||
use dom::bindings::trace::JSTraceable; | ||
|
||
thread_local!(static STACK: RefCell<Vec<StackEntry>> = RefCell::new(Vec::new())); | ||
|
||
#[allow(unrooted_must_root)] | ||
#[derive(JSTraceable)] | ||
struct StackEntry { | ||
global: JS<GlobalScope>, | ||
} | ||
|
||
/// Traces the script settings stack. | ||
pub unsafe fn trace(tracer: *mut JSTracer) { | ||
STACK.with(|stack| { | ||
stack.borrow().trace(tracer); | ||
}) | ||
} | ||
|
||
/// RAII struct that pushes and pops entries from the script settings stack. | ||
pub struct AutoEntryScript { | ||
global: *const GlobalScope, | ||
} | ||
|
||
impl AutoEntryScript { | ||
/// https://html.spec.whatwg.org/multipage/#prepare-to-run-script | ||
pub fn new(global: &GlobalScope) -> Self { | ||
STACK.with(|stack| { | ||
trace!("Prepare to run script with {:p}", global); | ||
let mut stack = stack.borrow_mut(); | ||
stack.push(StackEntry { | ||
global: JS::from_ref(global), | ||
}); | ||
AutoEntryScript { | ||
global: global as *const _, | ||
} | ||
}) | ||
} | ||
} | ||
|
||
impl Drop for AutoEntryScript { | ||
/// https://html.spec.whatwg.org/multipage/#clean-up-after-running-script | ||
fn drop(&mut self) { | ||
STACK.with(|stack| { | ||
let mut stack = stack.borrow_mut(); | ||
let entry = stack.pop().unwrap(); | ||
assert_eq!(&*entry.global as *const GlobalScope, | ||
self.global, | ||
"Dropped AutoEntryScript out of order."); | ||
trace!("Clean up after running script with {:p}", self.global); | ||
}) | ||
} | ||
} | ||
|
||
/// Returns the ["entry"] global object. | ||
/// | ||
/// ["entry"]: https://html.spec.whatwg.org/multipage/#entry | ||
pub fn entry_global() -> Root<GlobalScope> { | ||
STACK.with(|stack| { | ||
stack.borrow() | ||
.last() | ||
.map(|entry| Root::from_ref(&*entry.global)) | ||
}).unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[entry.html] | ||
type: testharness | ||
prefs: [dom.testbinding.enabled:true] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[entry.worker.html] | ||
type: testharness | ||
prefs: [dom.testbinding.enabled:true] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!DOCTYPE html> | ||
<title>Empty page</title> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Entry page</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
var entry_test = async_test("Entry global"); | ||
var loaded = function() { | ||
entry_test.step(function() { | ||
var entry = document.querySelector("#incumbent").contentWindow.get_entry(); | ||
assert_equals(entry, window); | ||
}); | ||
entry_test.done(); | ||
} | ||
</script> | ||
<iframe id="incumbent" src="incumbent.html" onload="loaded()"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
importScripts("/resources/testharness.js"); | ||
|
||
test(function() { | ||
var entry = (new TestBinding()).entryGlobal(); | ||
assert_equals(entry, self); | ||
}); | ||
|
||
|
||
done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<title>Incumbent page</title> | ||
|
||
<iframe src="empty.html" id="current"></iframe> | ||
<iframe src="empty.html" id="relevant"></iframe> | ||
<script> | ||
function get_entry() { | ||
var current = document.querySelector("#current").contentWindow; | ||
var relevant = document.querySelector("#relevant").contentWindow; | ||
|
||
return current.TestBinding.prototype.entryGlobal.call(new relevant.TestBinding()); | ||
} | ||
</script> |