NativeScript / android

NativeScript for Android using v8
https://docs.nativescript.org/guide/android-marshalling
Apache License 2.0
519 stars 135 forks source link

Remove weak callback from __postFrameCallback cache #1755

Closed ptomato closed 1 year ago

ptomato commented 1 year ago

Description

In preparation for upgrading V8 to 11.x, we need to remove uses of kFinalizer weak callbacks because V8 no longer supports them. One was used to clean up the cache entries for __postFrameCallback() callbacks, but that isn't necessary; we can just do the cleanup after the callback runs.

Also fixes a bug where sometimes a frame callback never got called.

Includes various cleanups in CallbackHanders.cpp and CallbackHanders.h, as well as a few misc commits left over from some of the upgrade work I did in February (the first 3 commits in the stack).

Does your pull request have unit tests?

__postFrameCallback() doesn't have a unit test. (If one is needed, let me know and I can write one.)

I tested this by adding the following snippet to the test-app:

--- a/test-app/app/src/main/assets/app/MyActivity.js
+++ b/test-app/app/src/main/assets/app/MyActivity.js
@@ -56,6 +56,13 @@ var MyActivity = (function (_super) {
                        onClick: function () {
                                button.setBackgroundColor(colors[taps % colors.length]);
                                taps++;
+                               textView.setText('Waiting for frame callback...');
+                               __postFrameCallback(() => {
+                                   textView.setText(`Message after one second: ${new Date()}`);
+                               }, 1000 /* ms */);
+                               __runOnMainThread(() => {
+                                   button.setText(`Hit me ${5 - taps} more times`);
+                               });
                        },
                })
         );