Skip to content

Commit

Permalink
Merge pull request #51 from jpl-mac/timob-8783
Browse files Browse the repository at this point in the history
TIMOB-8783 BlackBerry: Implement Global APIs Part 1
  • Loading branch information
jpl-mac committed May 15, 2012
2 parents bfe52af + 7021daa commit 864d83c
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ xcuserdata
*.LOCAL.*
*.REMOTE.*
*.o
x86
arm
51 changes: 51 additions & 0 deletions blackberry/tibb/TiJSONObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#include "TiJSONObject.h"

#include "TiGenericFunctionObject.h"


TiJSONObject::TiJSONObject(NativeObjectFactory* objectFactory)
: TiObject("JSON")
{
objectFactory_ = objectFactory;
}

TiJSONObject::~TiJSONObject()
{
}

void TiJSONObject::addObjectToParent(TiObject* parent, NativeObjectFactory* objectFactory)
{
TiJSONObject* obj = new TiJSONObject(objectFactory);
parent->addMember(obj);
obj->release();
}

void TiJSONObject::onCreateStaticMembers()
{
TiGenericFunctionObject::addGenericFunctionToParent(this, "parse", this, _parse);
TiGenericFunctionObject::addGenericFunctionToParent(this, "stringify", this, _stringify);
}

bool TiJSONObject::canAddMembers() const
{
return false;
}

Handle<Value> TiJSONObject::_parse(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: Implement
return Undefined();
}

Handle<Value> TiJSONObject::_stringify(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: Implement
return Undefined();
}
43 changes: 43 additions & 0 deletions blackberry/tibb/TiJSONObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#ifndef TIJSONOBJECT_H_
#define TIJSONOBJECT_H_

#include "TiObject.h"


/*
* TiJSONObject
*
* JSON namespace
*/
class TiJSONObject : public TiObject
{
public:
static void addObjectToParent(TiObject* parent, NativeObjectFactory* objectFactory);

protected:
virtual ~TiJSONObject();
virtual void onCreateStaticMembers();
virtual bool canAddMembers() const;

private:
explicit TiJSONObject();
explicit TiJSONObject(NativeObjectFactory* objectFactory);

/* Not copiable; Not assignable */
TiJSONObject(const TiJSONObject&);
TiJSONObject& operator=(const TiJSONObject&);

static Handle<Value> _parse(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _stringify(void* userContext, TiObject* caller, const Arguments& args);

NativeObjectFactory* objectFactory_;
};

#endif /* TIJSONOBJECT_H_ */
71 changes: 71 additions & 0 deletions blackberry/tibb/TiRootObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/

#include "TiRootObject.h"

#include "TiGenericFunctionObject.h"
#include "TiJSONObject.h"
#include "TiStringObject.h"
#include "TiTitaniumObject.h"
#include "TiV8EventContainerFactory.h"

Expand All @@ -28,6 +32,18 @@ void TiRootObject::onCreateStaticMembers()
TiObject* ti = TiTitaniumObject::createObject(objectFactory_);
addMember(ti);
addMember(ti, "Ti");

TiStringObject::addObjectToParent(this, objectFactory_);
TiJSONObject::addObjectToParent(this, objectFactory_);
TiGenericFunctionObject::addGenericFunctionToParent(this, "L", this, _L); // TODO: use the same object as Ti.Locale.getString
TiGenericFunctionObject::addGenericFunctionToParent(this, "alert", this, _alert);
TiGenericFunctionObject::addGenericFunctionToParent(this, "clearInterval", this, _clearInterval);
TiGenericFunctionObject::addGenericFunctionToParent(this, "clearTimeout", this, _clearTimeout);
TiGenericFunctionObject::addGenericFunctionToParent(this, "decodeURIComponent", this, _decodeURIComponent);
TiGenericFunctionObject::addGenericFunctionToParent(this, "encodeURIComponent", this, _encodeURIComponent);
TiGenericFunctionObject::addGenericFunctionToParent(this, "require", this, _require);
TiGenericFunctionObject::addGenericFunctionToParent(this, "setInterval", this, _setInterval);
TiGenericFunctionObject::addGenericFunctionToParent(this, "setTimeout", this, _setTimeout);
}

TiRootObject* TiRootObject::createRootObject()
Expand Down Expand Up @@ -72,3 +88,58 @@ int TiRootObject::executeScript(NativeObjectFactory* objectFactory, const char*
return 0;
}

/* Methods defined by Global */
Handle<Value> TiRootObject::_L(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: finish this
return Undefined();
}

Handle<Value> TiRootObject::_alert(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: finish this
return Undefined();
}

Handle<Value> TiRootObject::_clearInterval(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: finish this
return Undefined();
}

Handle<Value> TiRootObject::_clearTimeout(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: finish this
return Undefined();
}

Handle<Value> TiRootObject::_decodeURIComponent(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: finish this
return Undefined();
}

Handle<Value> TiRootObject::_encodeURIComponent(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: finish this
return Undefined();
}

Handle<Value> TiRootObject::_require(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: finish this
return Undefined();
}

Handle<Value> TiRootObject::_setInterval(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: finish this
return Undefined();
}

Handle<Value> TiRootObject::_setTimeout(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: finish this
return Undefined();
}

10 changes: 10 additions & 0 deletions blackberry/tibb/TiRootObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class TiRootObject : public TiObject
private:
TiRootObject();

static Handle<Value> _L(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _alert(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _clearInterval(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _clearTimeout(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _decodeURIComponent(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _encodeURIComponent(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _require(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _setInterval(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _setTimeout(void* userContext, TiObject* caller, const Arguments& args);

Persistent<Context> context_;
Handle<ObjectTemplate> globalTemplate_;
NativeObjectFactory* objectFactory_;
Expand Down
72 changes: 72 additions & 0 deletions blackberry/tibb/TiStringObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#include "TiStringObject.h"

#include "TiGenericFunctionObject.h"


TiStringObject::TiStringObject(NativeObjectFactory* objectFactory)
: TiObject("String")
{
objectFactory_ = objectFactory;
}

TiStringObject::~TiStringObject()
{
}

void TiStringObject::addObjectToParent(TiObject* parent, NativeObjectFactory* objectFactory)
{
TiStringObject* obj = new TiStringObject(objectFactory);
parent->addMember(obj);
obj->release();
}

void TiStringObject::onCreateStaticMembers()
{
TiGenericFunctionObject::addGenericFunctionToParent(this, "format", this, _format);
TiGenericFunctionObject::addGenericFunctionToParent(this, "formatCurrency", this, _formatCurrency);
TiGenericFunctionObject::addGenericFunctionToParent(this, "formatDate", this, _formatDate);
TiGenericFunctionObject::addGenericFunctionToParent(this, "formatDecimal", this, _formatDecimal);
TiGenericFunctionObject::addGenericFunctionToParent(this, "formatTime", this, _formatTime);
}

bool TiStringObject::canAddMembers() const
{
return false;
}

Handle<Value> TiStringObject::_format(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: Implement
return Undefined();
}

Handle<Value> TiStringObject::_formatCurrency(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: Implement
return Undefined();
}

Handle<Value> TiStringObject::_formatDate(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: Implement
return Undefined();
}

Handle<Value> TiStringObject::_formatDecimal(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: Implement
return Undefined();
}

Handle<Value> TiStringObject::_formatTime(void* userContext, TiObject* caller, const Arguments& args)
{
// TODO: Implement
return Undefined();
}
46 changes: 46 additions & 0 deletions blackberry/tibb/TiStringObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#ifndef TISTRINGOBJECT_H_
#define TISTRINGOBJECT_H_

#include "TiObject.h"


/*
* TiStringObject
*
* String namespace
*/
class TiStringObject : public TiObject
{
public:
static void addObjectToParent(TiObject* parent, NativeObjectFactory* objectFactory);

protected:
virtual ~TiStringObject();
virtual void onCreateStaticMembers();
virtual bool canAddMembers() const;

private:
explicit TiStringObject();
explicit TiStringObject(NativeObjectFactory* objectFactory);

/* Not copiable; Not assignable */
TiStringObject(const TiStringObject&);
TiStringObject& operator=(const TiStringObject&);

static Handle<Value> _format(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _formatCurrency(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _formatDate(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _formatDecimal(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _formatTime(void* userContext, TiObject* caller, const Arguments& args);

NativeObjectFactory* objectFactory_;
};

#endif /* TISTRINGOBJECT_H_ */
1 change: 0 additions & 1 deletion blackberry/tibb/TiUIObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "TiObject.h"

class TiCascadesApp;

/*
* TiUIObject
Expand Down

0 comments on commit 864d83c

Please sign in to comment.