Bypass css text (#2811)

* [DOM mocks] enable setting element.style

* Use the style setter directly
This commit is contained in:
Pierre-Yves Gérardy 2023-01-17 15:04:19 +01:00 committed by GitHub
parent 645cf663b2
commit c1fc1de772
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 13 deletions

View file

@ -800,10 +800,10 @@ module.exports = function($window) {
// Styles are equivalent, do nothing. // Styles are equivalent, do nothing.
} else if (style == null) { } else if (style == null) {
// New style is missing, just clear it. // New style is missing, just clear it.
element.style.cssText = "" element.style = ""
} else if (typeof style !== "object") { } else if (typeof style !== "object") {
// New style is a string, let engine deal with patching. // New style is a string, let engine deal with patching.
element.style.cssText = style element.style = style
} else if (old == null || typeof old !== "object") { } else if (old == null || typeof old !== "object") {
// `old` is missing or a string, `style` is an object. // `old` is missing or a string, `style` is an object.
element.style.cssText = "" element.style.cssText = ""

View file

@ -346,9 +346,8 @@ module.exports = function(options) {
get style() { get style() {
return style return style
}, },
set style(_){ set style(value){
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#Setting_style this.style.cssText = value
throw new Error("setting element.style is not portable")
}, },
get className() { get className() {
return this.attributes["class"] ? this.attributes["class"].value : "" return this.attributes["class"] ? this.attributes["class"].value : ""

View file

@ -665,16 +665,13 @@ o.spec("domMock", function() {
o(div.style.background).equals("url('/*foo*/')") o(div.style.background).equals("url('/*foo*/')")
}) })
o("setting style throws", function () { o("setting style updates style.cssText", function () {
var div = $document.createElement("div") var div = $document.createElement("div")
var err = false div.style = "background: red;"
try {
div.style = "" o(div.style.background).equals("red")
} catch (e) { o(div.style.cssText).equals("background: red;")
err = e
}
o(err instanceof Error).equals(true)
}) })
}) })
o.spec("events", function() { o.spec("events", function() {