Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-8990: Ti functions don't work in event callbacks #66

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions blackberry/tibb/TiRootObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ TiRootObject* TiRootObject::createRootObject()
return obj;
}

int TiRootObject::executeScript(NativeObjectFactory* objectFactory, const char* javaScript)
int TiRootObject::executeScript(NativeObjectFactory* objectFactory, const char* javaScript,
MESSAGELOOPENTRY messageLoopEntry, void* context)
{
HandleScope handleScope;
objectFactory_ = objectFactory;
initializeTiObject(NULL);
globalTemplate_ = ObjectTemplate::New();
globalTemplate_->SetInternalFieldCount(2);
TiV8EventContainerFactory* eventFactory = TiV8EventContainerFactory::createEventContainerFactory(globalTemplate_);
objectFactory->setEventContainerFactory(eventFactory);
onSetGetPropertyCallback(&globalTemplate_);
onSetFunctionCallback(&globalTemplate_);
context_ = Context::New(NULL, globalTemplate_);
context_->Global()->SetHiddenValue(String::New("globalTemplate_"), External::New(&globalTemplate_));
context_->Global()->SetHiddenValue(String::New("context_"), External::New(&context_));
setTiObjectToJsObject(context_->Global(), this);
Context::Scope context_scope(context_);

Expand All @@ -85,7 +86,7 @@ int TiRootObject::executeScript(NativeObjectFactory* objectFactory, const char*
return -1;
}
onStartMessagePump();
return 0;
return (messageLoopEntry)(context);
}

/* Methods defined by Global */
Expand Down
6 changes: 5 additions & 1 deletion blackberry/tibb/TiRootObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ struct FUNCTION_ENTRY;
*
* Root namespace in Titanium
*/

typedef int (*MESSAGELOOPENTRY)(void*);

class TiRootObject : public TiObject
{
public:
static TiRootObject* createRootObject();
int executeScript(NativeObjectFactory* objectFactory, const char* javaScript);
int executeScript(NativeObjectFactory* objectFactory, const char* javaScript,
MESSAGELOOPENTRY messageLoopEntry, void* context);

protected:
virtual ~TiRootObject();
Expand Down
26 changes: 17 additions & 9 deletions blackberry/tibb/TitaniumRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,26 @@ int TitaniumRuntime::internalRun(int argc, char** argv)
TiCascadesApp mainApp;
mainApp.initializeApp();
NativeObjectFactory objFactory(&mainApp);
obj->executeScript(&objFactory, javaScript_);
NativeObject* nativeObject = objFactory.getRootContainer();
mainApp.setScene(nativeObject);
if (nativeObject != NULL)
{
nativeObject->release();
}
// TODO: implement a message pump here
return bb::cascades::Application::exec();
objectFactory_ = &objFactory;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the idea of setting a member variable with a reference to memory on the stack, but since it's a private member and seems to never get referenced after the function ends, it should be ok. If I'm wrong about referencing it later then this needs to be in the heap.

mainApp_ = &mainApp;
int ret = obj->executeScript(&objFactory, javaScript_, messageLoop, this);
// TODO: handle non-zero return code here
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a Jira associated with that TODO? Otherwise what's preventing this from being done as part of this patch? If there's a reason to do it separately, then let's make sure there is a jira tracking that

return ret;
}

void TitaniumRuntime::Log(const char* msg)
{
fprintf(stderr, "%s\n", msg);
}

int TitaniumRuntime::messageLoop(void* context)
{
TitaniumRuntime* self = (TitaniumRuntime*)context;
NativeObject* nativeObject = self->objectFactory_->getRootContainer();
self->mainApp_->setScene(nativeObject);
if (nativeObject != NULL)
{
nativeObject->release();
}
return bb::cascades::Application::exec();
}
6 changes: 6 additions & 0 deletions blackberry/tibb/TitaniumRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* Main runtime startup class
*/

class NativeObjectFactory;
class TiCascadesApp;

class TitaniumRuntime
{
public:
Expand All @@ -28,9 +31,12 @@ class TitaniumRuntime
virtual ~TitaniumRuntime();
int internalRun(int argc, char** argv);
void Log(const char* msg);
static int messageLoop(void* context);

char* javaScript_;
TiObjectScope rootObject_;
NativeObjectFactory* objectFactory_;
TiCascadesApp* mainApp_;
};

#endif /* TITANIUMRUNTIME_H_ */