Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bridge/core/frame/dom_timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ DOMTimer::DOMTimer(ExecutingContext* context, std::shared_ptr<QJSFunction> callb
: context_(context), callback_(std::move(callback)), status_(TimerStatus::kPending), kind_(timer_kind) {}

void DOMTimer::Fire() {
if (status_ == TimerStatus::kTerminated)
return;

if (!callback_->IsFunction(context_->ctx()))
return;

Expand All @@ -35,6 +38,11 @@ void DOMTimer::Fire() {
}
}

void DOMTimer::Terminate() {
callback_ = nullptr;
status_ = TimerStatus::kTerminated;
}

void DOMTimer::setTimerId(int32_t timerId) {
timer_id_ = timerId;
}
Expand Down
5 changes: 4 additions & 1 deletion bridge/core/frame/dom_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace webf {
class DOMTimer {
public:
enum TimerKind { kOnce, kMultiple };
enum TimerStatus { kPending, kExecuting, kFinished, kCanceled };
enum TimerStatus { kPending, kExecuting, kFinished, kCanceled, kTerminated };

static std::shared_ptr<DOMTimer> create(ExecutingContext* context,
const std::shared_ptr<QJSFunction>& callback,
Expand All @@ -24,6 +24,9 @@ class DOMTimer {
// Trigger timer callback.
void Fire();

// Mark this timer is terminated and free the underly callbacks.
void Terminate();

TimerKind kind() const { return kind_; }

[[nodiscard]] int32_t timerId() const { return timer_id_; };
Expand Down
30 changes: 2 additions & 28 deletions bridge/core/frame/dom_timer_coordinator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,6 @@

namespace webf {

static void handleTimerCallback(DOMTimer* timer, const char* errmsg) {
auto* context = timer->context();

if (errmsg != nullptr) {
JSValue exception = JS_ThrowTypeError(timer->context()->ctx(), "%s", errmsg);
context->HandleException(&exception);
return;
}

// Trigger timer callbacks.
timer->Fire();

// Executing pending async jobs.
context->DrainPendingPromiseJobs();
}

static void handleTransientCallback(void* ptr, int32_t context_id, const char* errmsg) {
auto* timer = static_cast<DOMTimer*>(ptr);
auto* context = timer->context();

if (!context->IsContextValid())
return;

handleTimerCallback(timer, errmsg);

context->Timers()->removeTimeoutById(timer->timerId());
}

void DOMTimerCoordinator::installNewTimer(ExecutingContext* context,
int32_t timer_id,
std::shared_ptr<DOMTimer> timer) {
Expand All @@ -51,6 +23,8 @@ void DOMTimerCoordinator::removeTimeoutById(int32_t timer_id) {
if (active_timers_.count(timer_id) == 0)
return;
auto timer = active_timers_[timer_id];
timer->Terminate();
terminated_timers[timer_id] = timer;
active_timers_.erase(timer_id);
}

Expand Down
1 change: 1 addition & 0 deletions bridge/core/frame/dom_timer_coordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DOMTimerCoordinator {

private:
std::unordered_map<int, std::shared_ptr<DOMTimer>> active_timers_;
std::unordered_map<int, std::shared_ptr<DOMTimer>> terminated_timers;
};

} // namespace webf
Expand Down
8 changes: 6 additions & 2 deletions bridge/core/frame/window_or_worker_global_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void handleTransientCallback(void* ptr, int32_t contextId, const char* er
if (!context->IsContextValid())
return;

if (timer->status() == DOMTimer::TimerStatus::kCanceled) {
if (timer->status() == DOMTimer::TimerStatus::kCanceled || timer->status() == DOMTimer::TimerStatus::kTerminated) {
return;
}

Expand All @@ -49,6 +49,10 @@ static void handlePersistentCallback(void* ptr, int32_t contextId, const char* e
if (!context->IsContextValid())
return;

if (timer->status() == DOMTimer::TimerStatus::kTerminated) {
return;
}

if (timer->status() == DOMTimer::TimerStatus::kCanceled) {
context->Timers()->removeTimeoutById(timer->timerId());
return;
Expand Down Expand Up @@ -115,7 +119,7 @@ int WindowOrWorkerGlobalScope::setInterval(ExecutingContext* context,
// Create a timer object to keep track timer callback.
auto timer = DOMTimer::create(context, handler, DOMTimer::TimerKind::kMultiple);

uint32_t timerId =
int32_t timerId =
context->dartMethodPtr()->setInterval(timer.get(), context->contextId(), handlePersistentCallback, timeout);

// Register timerId.
Expand Down
1 change: 1 addition & 0 deletions webf/example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ post_install do |installer|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config_valid_archs(config)
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
end
end
installer.pods_project.save
Expand Down
4 changes: 3 additions & 1 deletion webf/example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -216,6 +216,7 @@
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -230,6 +231,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
2 changes: 2 additions & 0 deletions webf/example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>