Files
react-native/ReactCommon
Xuan Huang 7310847758 Perform Engine Microtasks in JSIExecutor
Summary:
Changelog: [Internal]

This diff introduce a helper `performMicrotaskCheckpoint` to
repetitively invoke `jsi::Runtime::drainMicrotasks` to exhaust
the microtasks queue provided by JS VMs. Please refer to `jsi.h`
for more details about the behavior of the API.

Conceptually, the checkpoint needs to be performed whenever the
JS stack is considered empty. In practice, we can just make a
call whenever RN is returned from C++->JS calls.

In the current RN, this happened in JSIExecutor:
- `::callFunction` => `callFunctionReturnFlushedQueue_-> call`
- `::invokeCallback` => `invokeCallbackAndReturnFlushedQueue_-> call`
- `::flush` => `flushedQueue_->call`

Each of them invoke a bound method on the JS bridge object. Note
that `setImmediate` callbacks are executed before they returned.
This means immmediates are invoked before engine microtasks. This
is okay because the priority between `setImmediate` and engine
"microtask" are not defined. (`setImmediate` is non-standard and RN
already treat `setImmediate` in a similar priority as microtask
for the existing Promise polyfill.)

Reviewed By: RSNara

Differential Revision: D27729702

fbshipit-source-id: b64b3705d2ff5100075d860c89f03a847369b7ac
2021-04-23 02:43:06 -07:00
..
2021-04-01 04:50:59 -07:00
2021-04-23 02:43:06 -07:00
2020-05-15 21:55:52 -07:00
2021-04-22 09:50:23 -07:00