ios icon indicating copy to clipboard operation
ios copied to clipboard

function callback method argument crash with nativescript-plugin-firebase

Open NathanWalker opened this issue 4 years ago • 2 comments

Native stack trace:
1          0x10f9f4d6b tns::Assert(bool, v8::Isolate*) + 119
2          0x10f9607f9 tns::ArgConverter::Invoke(v8::Local<v8::Context>, objc_class*, v8::Local<v8::Object>, tns::V8Args&, tns::MethodMeta const*, bool) + 95
3          0x10f9ba9c0 tns::MetadataBuilder::InvokeMethod(v8::Local<v8::Context>, tns::MethodMeta const*, v8::Local<v8::Object>, tns::V8Args&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool) + 76
4          0x10f9ba513 tns::MetadataBuilder::PropertyGetterCallback(v8::FunctionCallbackInfo<v8::Value> const&) + 245
5          0x10fb2b3dc v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) + 620
6          0x10fb2a88c v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) + 556
7          0x10fb2a23a v8::internal::Builtins::InvokeApiFunction(v8::internal::Isolate*, bool, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*, v8::internal::Handle<v8::internal::HeapObject>) + 762
8          0x10feb1c92 v8::internal::Object::GetPropertyWithAccessor(v8::internal::LookupIterator*) + 466
9          0x10feb13eb v8::internal::Object::GetProperty(v8::internal::LookupIterator*, bool) + 139
10         0x10fd28f05 v8::internal::LoadIC::Load(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, bool) + 1605
11         0x10fd3195e v8::internal::Runtime_LoadNoFeedbackIC_Miss(int, unsigned long*, v8::internal::Isolate*) + 286
12         0x1103b7619 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit + 57
JavaScript stack trace:
at <anonymous> (file: node_modules/nativescript-plugin-firebase/firebase.ios.js:837:0)
at push.../node_modules/nativescript-plugin-firebase/firebase.js.GIDSignInDelegateImpl.signInDidSignInForUserWithError (file: node_modules/nativescript-plugin-firebase/firebase.ios.js:2175:0)

repro:

Just login via google with firebase plugin.

This works fine with JavaScriptCore ios-runtime.

NathanWalker avatar May 03 '20 03:05 NathanWalker

This is the compiled js from the plugin regarding the problem area with GIDSignInDelegateImpl:

var GIDSignInDelegateImpl = (function (_super) {
    __extends(GIDSignInDelegateImpl, _super);
    function GIDSignInDelegateImpl() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    GIDSignInDelegateImpl.new = function () {
        if (GIDSignInDelegateImpl.ObjCProtocols.length === 0 && typeof (GIDSignInDelegate) !== "undefined") {
            GIDSignInDelegateImpl.ObjCProtocols.push(GIDSignInDelegate);
        }
        return _super.new.call(this);
    };
    GIDSignInDelegateImpl.prototype.initWithCallback = function (callback) {
        this.callback = callback;
        return this;
    };
    GIDSignInDelegateImpl.prototype.signInDidSignInForUserWithError = function (signIn, user, error) {
        this.callback(user, error);
    };
    GIDSignInDelegateImpl.ObjCProtocols = [];
    return GIDSignInDelegateImpl;
}(NSObject));

NathanWalker avatar May 03 '20 03:05 NathanWalker

After debugging we have discovered that the issue is related to a javascript variable in the plugin that is used after being garbage collected: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/src/firebase.ios.ts#L745

The fAuth is a local variable that gets initialized to store a native counterpart is then used inside the GidSignInDelegate callback: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/src/firebase.ios.ts#L984

To prevent this issue we need to fix the scope of this variable to ensure that it will not be eligible for GC before the delegate callback is invoked by some native code.

darind avatar May 06 '20 06:05 darind