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

Verify+copy JS behaviour when script tags are fighting #12

Open
daurnimator opened this issue Aug 3, 2017 · 5 comments
Open

Verify+copy JS behaviour when script tags are fighting #12

daurnimator opened this issue Aug 3, 2017 · 5 comments

Comments

@daurnimator
Copy link
Member

daurnimator commented Aug 3, 2017

e.g. Two script tags are added to document, they both contain code to remove the other. Do both run?

<script id="a">
console.log("A")
var b = document.getElementById("b");
b.parentNode.removeChild(b);
</script>
<script id="b">
console.log("B")
var a = document.getElementById("a");
a.parentNode.removeChild(a);
</script>

Need to check on load and after document ready.

@daurnimator
Copy link
Member Author

daurnimator commented Aug 20, 2017

I checked in firefox: both scripts are run. B cannot get it's own element via the DOM: it is available via document.currentScript, but does not show in document.getElementById.

@daurnimator
Copy link
Member Author

daurnimator commented Mar 25, 2018

<script>
var da = document.createElement("script")
da.id="da"
da.textContent = `
console.log("da", document.getElementById("da"))
var b = document.getElementById("db");
b.parentNode.removeChild(b);
`
var db = document.createElement("script")
db.id="db"
db.textContent = `
console.log("db", document.getElementById("db"))
var a = document.getElementById("da");
a.parentNode.removeChild(a);
`
setTimeout(function() {
	document.body.appendChild(da)
	document.body.appendChild(db)
}, 5)
</script>

In Chrome and Firefox: b in da is null.

@daurnimator
Copy link
Member Author

In Chrome and Firefox: b in da is null.

This is currently not the same as fengari where we run the scripts after they're in the document.

<script>
var da = document.createElement("script")
da.id="da"
da.type = "application/lua"
da.textContent = `
local console = require "js".global.console
local document = require "js".global.document
console:log("da", document:getElementById("da"))
local b = document:getElementById("db");
b.parentNode:removeChild(b);
`
var db = document.createElement("script")
db.id="db"
db.type = "application/lua"
db.textContent = `
local console = require "js".global.console
local document = require "js".global.document
console:log("db", document:getElementById("db"))
local a = document:getElementById("da");
a.parentNode:removeChild(a);
`
setTimeout(function() {
	document.body.appendChild(da)
	document.body.appendChild(db)
}, 5)
</script>

@ashwalk33r
Copy link

Whats the expected behaviour? Whats the problem/enchancement proposed here?

@daurnimator
Copy link
Member Author

Whats the expected behaviour?

I don't know: need to audit what all the browsers do.

Whats the problem/enchancement proposed here?

To make sure that the way we load lua script tags matches exactly how JS tags are loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants