Add JSI test for queueMicrotask and drainMicrotasks (#43309)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43309

Changelog: [internal]

X-link: https://github.com/facebook/hermes/pull/1336

Add JSI test verifying the behavior of `queueMicrotask` and `drainMicrotasks` in the runtimes that support them.

Reviewed By: neildhar

Differential Revision: D54484771

fbshipit-source-id: e8c0c8e05215d59a0a8c86161452642c41bcdbd7
This commit is contained in:
Rubén Norte
2024-03-05 04:10:44 -08:00
committed by Facebook GitHub Bot
parent 244fe286a0
commit 74595907a2
@@ -1358,6 +1358,38 @@ TEST_P(JSITest, JSErrorTest) {
JSIException);
}
TEST_P(JSITest, MicrotasksTest) {
try {
rt.global().setProperty(rt, "globalValue", String::createFromAscii(rt, ""));
auto microtask1 =
function("function microtask1() { globalValue += 'hello'; }");
auto microtask2 =
function("function microtask2() { globalValue += ' world' }");
rt.queueMicrotask(microtask1);
rt.queueMicrotask(microtask2);
EXPECT_EQ(
rt.global().getProperty(rt, "globalValue").asString(rt).utf8(rt), "");
rt.drainMicrotasks();
EXPECT_EQ(
rt.global().getProperty(rt, "globalValue").asString(rt).utf8(rt),
"hello world");
// Microtasks shouldn't run again
rt.drainMicrotasks();
EXPECT_EQ(
rt.global().getProperty(rt, "globalValue").asString(rt).utf8(rt),
"hello world");
} catch (const JSINativeException& ex) {
// queueMicrotask() is unimplemented by some runtimes, ignore such failures.
}
}
//----------------------------------------------------------------------
// Test that multiple levels of delegation in DecoratedHostObjects works.