Closed Bug 1622184 Opened 5 years ago Closed 5 years ago

Mark ready and finished promise rejections as handled

Categories

(Core :: DOM: Animation, task, P3)

task

Tracking

()

RESOLVED FIXED
mozilla76
Tracking Status
firefox76 --- fixed

People

(Reporter: birtles, Assigned: birtles)

References

Details

Attachments

(3 files)

Assignee: nobody → brian
Status: NEW → ASSIGNED
Flags: needinfo?(arai.unmht)

IMO, public JSAPI that receives JSContext + GC things (JSObject) should do:

  • assert GC isn't performed (AssertHeapIsIdle() call)
  • assert it's in the correct thread (CHECK_THREAD(cx) call)
  • assert the GC thing is in the same compartment as JSContext (cx->check(...) call)
  • handle cross-compartment wrapper (unwrap it, and enter the realm)

Example code that does the above:
https://searchfox.org/mozilla-central/rev/f36cb2af46edd2659f446b7acdb2154e230ee445/js/src/jsapi.cpp#3887-3906

Especially the last one is important.
otherwise as<PromiseObject>() cast fails and it results in sec-bug.
I've filed bug 1622329, in case promiseObj() can return non-PromiseObject.
if it's always PromiseObject, the assertion in the current patch should be sufficient.

About others above, Given cx->check isn't no-op on nightly opt build [1][2],
it's better adding it only to public JSAPI, and keep the private function as is.
we usually prepare 2 functions, public one (JS namespace) and private one (js namespace),
public one for extra check and type conversion, and private one for actual implementation.

// in jsapi.h
JS::Foo([parameters with public type]) {
  // some extra check, and type conversion
  js::Foo([parameters with private type])
}

// in internal file
js::Foo([parameters with private type]) {
  // actual implementation here
}

Here, public API receives with JS::HandleObject, and private function can receive JS::Handle<PromiseObject*>.

js::SetSettledPromiseIsHandled can be moved to js/src/builtin/Promise-inl.h (doesn't exist yet), so that it can still be an inline function.

Then, about SetSettledPromiseIsHandled method, I think it should be DOM promise's method instead of Animation.
So that it already has global and corresponding JSContext, and no need to allocate AutoJSAPI again.
https://searchfox.org/mozilla-central/rev/f36cb2af46edd2659f446b7acdb2154e230ee445/dom/promise/Promise.h#317-318

[1] https://searchfox.org/mozilla-central/rev/f36cb2af46edd2659f446b7acdb2154e230ee445/js/src/vm/JSContext-inl.h#206-213
[2] https://searchfox.org/mozilla-central/rev/f36cb2af46edd2659f446b7acdb2154e230ee445/js/src/util/DiagnosticAssertions.h#16-18

Flags: needinfo?(arai.unmht)

Arai-san, thank you so much!
Unfortunately today I didn't have time to incorporate this feedback but it is very helpful. Hopefully I will get to it later in the week. Thank you again!

Pushed by bbirtles.birchill@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7c1a4d74cc7a Add tests that when the Animation.ready and Animation.finished promises are resolved they are marked as handled; r=boris https://hg.mozilla.org/integration/autoland/rev/14521d59a4cf Add a public method to mark a settled Promise as handled; r=arai https://hg.mozilla.org/integration/autoland/rev/bd0f43a21b36 Mark Animation.finished and Animation.ready as handled when they are rejected; r=boris
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/22314 for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla76
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: