Ignore:
Timestamp:
Jun 9, 2022, 12:05:16 PM (3 years ago)
Author:
[email protected]
Message:

jsc's settimeout should properly handle a delay
https://bugs.webkit.org/show_bug.cgi?id=240467

Reviewed by Yusuke Suzuki.

This patch makes it so that we properly handle a timeout passed to the JSC CLI setTimeout API. Previously we would just run the callback on the next runloop tick regardless of the passed value.

  • Source/JavaScriptCore/jsc.cpp:

(JSC_DEFINE_HOST_FUNCTION):

Canonical link: https://commits.webkit.org/251434@main

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jsc.cpp

    r295270 r295428  
    25262526        return throwVMTypeError(globalObject, scope, "First argument is not a JS function"_s);
    25272527
    2528     // FIXME: We don't look at the timeout parameter because we don't have a schedule work later API.
    25292528    auto ticket = vm.deferredWorkTimer->addPendingWork(vm, callback, { });
    2530     vm.deferredWorkTimer->scheduleWorkSoon(ticket, [callback](DeferredWorkTimer::Ticket) {
    2531         JSGlobalObject* globalObject = callback->globalObject();
    2532         MarkedArgumentBuffer args;
    2533         call(globalObject, callback, jsUndefined(), args, "You shouldn't see this..."_s);
    2534     });
     2529    auto dispatch = [callback, ticket] {
     2530        callback->vm().deferredWorkTimer->scheduleWorkSoon(ticket, [callback](DeferredWorkTimer::Ticket) {
     2531            JSGlobalObject* globalObject = callback->globalObject();
     2532            MarkedArgumentBuffer args;
     2533            call(globalObject, callback, jsUndefined(), args, "You shouldn't see this..."_s);
     2534        });
     2535    };
     2536
     2537    JSValue timeout = callFrame->argument(1);
     2538    if (timeout.isNumber() && timeout.asNumber())
     2539        RunLoop::current().dispatchAfter(Seconds::fromMilliseconds(timeout.asNumber()), WTFMove(dispatch));
     2540    else
     2541        dispatch();
     2542
    25352543    return JSValue::encode(jsUndefined());
    25362544}
Note: See TracChangeset for help on using the changeset viewer.