ios
ios copied to clipboard
crash when overriding native property
here i override a native property.
This makes it crash.
You can reproduce it by the running the demo-vue
here and going into dialogs and clicking on the first button
Using the latest beta, in my case the app doesn't crash but it freezes when clicking on the Alert button. I am getting the following log:
2020-03-20 10:34:47.053793+0200 demovue[17827:1926802] Button touch target does not meet minimum size guidlines of (48, 48). Button: <MDCButton: 0x7faf06c329c0; baseClass = UIButton; frame = (10 460; 394 36); opaque = NO; layer = <MDCShapedShadowLayer: 0x60000276cf00>>, Touch Target: {394, 36}
2020-03-20 10:34:47.191630+0200 demovue[17827:1926802] CONSOLE LOG: onTap alert Button<alert>
2020-03-20 10:34:47.195892+0200 demovue[17827:1926802] CONSOLE LOG: showUIAlertController <MDCAlertControllerImpl: 0x7faf07853200> Page(38)
Other dialogs seem to work fine.
Are you getting some error log or a crash dump?
Yes i am getting those logs too. For me on an ipjome 6 simulator running ios 12 it does a black screen right away. Buy i think it is the same for you. If it freezes i think it will eventually crash. I actually debugged this and got the breakpoint on the native call that was trying to acces the native property i am overriding. Let me know hiw i can help
Can you try overriding the native property like this:
set preferredContentSize(x) {
let proto = MDCAlertControllerImpl.prototype;
Object.getOwnPropertyDescriptor(proto, "preferredContentSize").set.call(this, x);
}
I suspect that the issue might be related to the this.super
usage causing a StackOverflow.
As we discussed on stack the override you mentionned did not work
@darind any chance you could look at this? My material components can't work without this
@farfromrefug, sorry for the late reply. Can you try to replicate this issue in a simple javascript snippet? For example when I tried extending the following class I was able to successfully marshal the value between js and native:
const MDCAlertControllerImpl = UIViewController.extend({
get preferredContentSize() {
const superResult = this.super.preferredContentSize;
return superResult;
},
set preferredContentSize(x) {
this.super.preferredContentSize = x;
}
});
I am then able to instantiate and use this class:
var instance = new MDCAlertControllerImpl();
instance.preferredContentSize = CGSizeMake(173, 245);
Foo.test(instance);
where I have defined the custom Foo
native class:
@interface Foo : NSObject
+(void)test:(UIViewController*)o;
@end
@implementation Foo
+(void)test:(UIViewController*)o {
CGSize sz = [o preferredContentSize];
NSLog(@"%fx%f", sz.width, sz.height);
}
@end
This prints the expected 173.000000x245.000000
message to the console.
@darind thanks for your answer. Won't be able to do it in the next 3 weeks. When I ll come back I ll test it again but I think the demo vue of my nativescript-material-components shows it in the dialog section. If not it must have been fixed
@darind @NathanWalker that bug is still present. Just tried it again and it is still crashing.
tested with 7.0.0-beta.3-v8-2020-07-01-222820-05
Again the demo-vue app crashes in the dialogs sample while clicking on the first button.
Can it be related to the super class MDCAlertController
?
To add to this, with the migration to n 7 i made some more tests.
If i change that class to es6 with @NativeClass
i get a different error
====== Assertion failed ======
Native stack trace:
1 0x10f257ceb tns::Assert(bool, v8::Isolate*) + 119
2 0x10f1c7079 tns::ArgConverter::Invoke(v8::Local<v8::Context>, objc_class*, v8::Local<v8::Object>, tns::V8Args&, tns::MethodMeta const*, bool) + 95
3 0x10f21f83a 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 0x10f21f4a1 tns::MetadataBuilder::PropertySetterCallback(v8::FunctionCallbackInfo<v8::Value> const&) + 249
5 0x10f38f22c v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) + 620
6 0x10f38e6dc 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 0x10f38e084 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>) + 692
8 0x10f73018f v8::internal::Object::SetPropertyWithAccessor(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::Maybe<v8::internal::ShouldThrow>) + 511
9 0x10f7353b6 v8::internal::Object::SetPropertyInternal(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::StoreOrigin, bool*) + 358
10 0x10f735196 v8::internal::Object::SetProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::StoreOrigin, v8::Maybe<v8::internal::ShouldThrow>) + 54
11 0x10f59601d v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::StoreOrigin) + 1053
12 0x10f59b2dd v8::internal::Runtime_StoreIC_Miss(int, unsigned long*, v8::internal::Isolate*) + 413
13 0x10fc26c39 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit + 57
JavaScript stack trace:
at set (file:///app/bundle.js:2320:45)
at MDCAlertControllerImpl.viewDidLoad (file:///app/bundle.js:2491:34)
at showUIAlertController (file: app/src/dialogs.ios.ts:716:27
Which seems to come from that line https://github.com/NativeScript/ns-v8ios-runtime/blob/59ae25d79497a73b86b7a35ec4ad0b4f3507b4f2/NativeScript/runtime/ArgConverter.mm#L29 or maybe this one (the stack does not tell me really) https://github.com/NativeScript/ns-v8ios-runtime/blob/59ae25d79497a73b86b7a35ec4ad0b4f3507b4f2/NativeScript/runtime/ArgConverter.mm#L45
Also .extend
does work with the older runtime but es6 class transformer to es5 with @NativeClass
does not either