Repository navigation
script: Create a FontFace's promise when it's first used - #50064
rogerkorantenng wants to merge 1 commit into
Conversation
|
This approach looks fine to me, but I am interested in what @jdm and @mrobinson think. |
| [Exposed=(Window,Worker), Pref="dom_fontface_enabled"] | ||
| interface FontFace { | ||
| constructor(CSSOMString family, (CSSOMString or BufferSource) source, | ||
| [Throws] constructor(CSSOMString family, (CSSOMString or BufferSource) source, |
There was a problem hiding this comment.
This does not throw in the specification, so is it right to modify the WebIDL to cause it to throw...
There was a problem hiding this comment.
Good point. I looked at how Gecko and Blink handle this, and neither creates the promise in the constructor. They create it the first time loaded or load() is used, then resolve or reject it based on the current status. I'll do the same here and drop [Throws] from the constructor, so it matches the spec.
There was a problem hiding this comment.
Would you be willing to come to my office hours next week to discuss this?
There was a problem hiding this comment.
Throws is not part of WebIDL and our own custom thing afaik
There was a problem hiding this comment.
Would you be willing to come to my office hours next week to discuss this?
@mrobinson Thank you, I am really looking forward to it! I am not free next week, but I will be available the week after this week (from 30 November). Please tell me the day and time that suits you. I am in Accra, which is UTC+0.
There was a problem hiding this comment.
You can find the office hours and days at #general > Office Hours @ 💬
Creating a FontFace close to the recursion limit crashed Servo, because Promise::new asserts when SpiderMonkey can't create the promise. Like Gecko and Blink, the [[FontStatusPromise]] is now created the first time loaded or load() needs it, so the constructor can't fail, as the spec says. If the font has already loaded or failed by then, the promise is settled straight away. Creating it uses a new Promise::try_new, which returns an error instead of asserting. Promise-returning members turn that error into a rejected promise, so script sees a rejected promise instead of a crash. Promise::new works the same as before. This also fixes two css-font-loading tests that used to end with an unhandled rejection from a FontFace that was never used. Fixes servo#50063 Signed-off-by: rogerkorantenng <[email protected]>
5db3088 to
d981f0d
Compare
| if obj.is_null() { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Let's instead make create_js_promise return Result<(), Error>, return Err(Error::JSFailed) here, and then the caller can just do: Promise::create_js_promise(cx, obj.handle_mut())?; and move the assert into the caller.
| [Exposed=(Window,Worker), Pref="dom_fontface_enabled"] | ||
| interface FontFace { | ||
| constructor(CSSOMString family, (CSSOMString or BufferSource) source, | ||
| [Throws] constructor(CSSOMString family, (CSSOMString or BufferSource) source, |
There was a problem hiding this comment.
You can find the office hours and days at #general > Office Hours @ 💬
Creating a FontFace close to the recursion limit crashed Servo, because Promise::new asserts when SpiderMonkey can't create the promise.
My first version made the constructor throw, but the spec's constructor never throws. Gecko and Blink don't create the [[FontStatusPromise]] in the constructor at all. They create it the first time loaded or load() needs it, so I've done the same here. If the font has already loaded or failed by then, the new promise is settled right away.
The promise is created with a new Promise::try_new. loaded and load() return promises, so if creating it fails, the bindings hand script a rejected promise instead of crashing.
Testing: the new crash test (fontface-too-much-recursion-crash.html) crashes on main and passes with this change, and the repro from #50063 passed 60 runs in a row. Two css-font-loading tests used to end in ERROR because of an unhandled rejection from a FontFace nobody used. They're OK now, same as in Chrome and Firefox. Tidy, clippy, crown and the script unit tests pass too.
Fixes: #50063