Skip to content

Commit

Permalink
chore(Gameraww): Fix crash on startup
Browse files Browse the repository at this point in the history
* Override `prefersStatusBarHidden` property with a JS property instead of a function
* Improve error handling and throw an exception when property is being overridden with a function
* Add unit tests for thrown exceptions when a property is being wrongly overridden
  • Loading branch information
mbektchiev committed Aug 8, 2019
1 parent 41bd890 commit 86fff68
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/Gameraww/app/DetailViewController.js
Expand Up @@ -26,7 +26,7 @@ var JSDetailViewController = UIViewController.extend({
this.toggleTopBarVisibility();
},

prefersStatusBarHidden: function () {
get prefersStatusBarHidden() {
var navigationController = this.navigationController;
var navigationBarHidden = navigationController.navigationBarHidden;
return navigationBarHidden;
Expand Down
17 changes: 16 additions & 1 deletion src/NativeScript/ObjC/ObjCMethodCallback.mm
Expand Up @@ -53,7 +53,22 @@ void overrideObjcMethodCall(ExecState* execState, Class klass, JSCell* method, O

void overrideObjcMethodCalls(ExecState* execState, JSObject* object, PropertyName propertyName, JSCell* method, const Metadata::BaseClassMeta* meta, Metadata::MemberType memberType, Class klass,
std::vector<const Metadata::ProtocolMeta*>* protocols) {
ObjCMethodWrapper* wrapper = jsDynamicCast<ObjCMethodWrapper*>(execState->vm(), object->get(execState, propertyName));
JSValue methodValue = jsUndefined();
PropertySlot slot(object, PropertySlot::InternalMethodType::Get);
if (object->getPropertySlot(execState, propertyName, slot)) {
if (slot.isAccessor()) {
JSC::VM& vm = execState->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
WTF::String message = WTF::String::format("Cannot override native property \"%s\" with a function, define it as a JS property instead.",
propertyName.publicName()->utf8().data());
throwException(execState, throwScope, JSC::createError(execState, message));
return;
}

methodValue = slot.getValue(execState, propertyName);
}

ObjCMethodWrapper* wrapper = jsDynamicCast<ObjCMethodWrapper*>(execState->vm(), methodValue);
Strong<ObjCMethodWrapper> strongWrapper;
if (!wrapper) {
MembersCollection methodMetas;
Expand Down
11 changes: 11 additions & 0 deletions tests/TestRunner/app/Inheritance/InheritanceTests.js
Expand Up @@ -1620,6 +1620,17 @@ describe(module.id, function () {
TNSClearOutput();
});

it('PropertyOverrides: errors', function () {
expect(() => TNSIDerivedInterface.extend({
get derivedImplementedOptionalProperty() {
}
})).toThrowError('Property "derivedImplementedOptionalProperty" requires a setter function.');
expect(() => TNSIDerivedInterface.extend({
derivedImplementedOptionalProperty: function() {
}
})).toThrowError('Cannot override native property "derivedImplementedOptionalProperty" with a function, define it as a JS property instead.');
});

it('ConstructorOverrideAndVirtualCall: prototype', function () {
var JSObject = TNSIConstructorVirtualCalls.extend({
initWithXAndY: function initWithXAndY(x, y) {
Expand Down

0 comments on commit 86fff68

Please sign in to comment.