-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the entry global. #14840
Merged
Merged
Implement the entry global. #14840
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::bindings::trace::JSTraceable; | ||
use dom::globalscope::GlobalScope; | ||
use js::jsapi::JSTracer; | ||
use std::cell::RefCell; | ||
|
||
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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: could you make that a static method on
AutoEntryScript
? Less things to import that way.