Skip to content
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

HTML: document.open() and global variables #10815

Merged
merged 6 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// In an earlier version of the HTML Standard, document open steps created a
// new JavaScript realm and migrated the existing objects to use the new realm.
// Test that this no longer happens.

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
// Ensure a load event gets dispatched to unblock testharness
t.add_cleanup(() => frame.remove());
frame.src = "resources/global-variables-frame.html";
frame.onload = t.step_func_done(() => {
assert_equals(frame.contentWindow.hey, "You", "precondition");
frame.contentDocument.open();
assert_equals(frame.contentWindow.hey, "You", "actual check");
});
}, "Obtaining a variable from a global whose document had open() invoked");

function testIdentity(desc, frameToObject, frameToConstructor) {
async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
// Ensure a load event gets dispatched to unblock testharness
t.add_cleanup(() => frame.remove());
frame.src = "/common/blank.html";
frame.onload = t.step_func_done(() => {
const obj = frameToObject(frame);
frame.contentDocument.open();
assert_equals(frameToObject(frame), obj);
});
}, `${desc} maintains object identity through open()`);

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
// Ensure a load event gets dispatched to unblock testharness
t.add_cleanup(() => frame.remove());
frame.src = "/common/blank.html";
frame.onload = t.step_func_done(() => {
const obj = frameToObject(frame);
const origProto = Object.getPrototypeOf(obj);
const origCtor = frameToConstructor(frame);
const sym = Symbol();
obj[sym] = "foo";
frame.contentDocument.open();
assert_equals(frameToObject(frame)[sym], "foo");
assert_true(frameToObject(frame) instanceof origCtor);
assert_equals(Object.getPrototypeOf(frameToObject(frame)), origProto);
assert_equals(frameToConstructor(frame), origCtor);
});
}, `${desc} maintains its prototype and properties through open()`);
}

testIdentity("Document", frame => frame.contentDocument, frame => frame.contentWindow.Document);
testIdentity("WindowProxy", frame => frame.contentWindow, frame => frame.contentWindow.Window);
testIdentity("Location", frame => frame.contentWindow.location, frame => frame.contentWindow.Location);
testIdentity("Navigator", frame => frame.contentWindow.navigator, frame => frame.contentWindow.Navigator);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something a bit special about Location as well, see whatwg/html#2545. Are there any tests for Location that would make sense here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!doctype html>
<script>
hey = "You";
</script>