Exemplo n.º 1
0
void TiObject::getPropertyNames(TiExcState* exec, PropertyNameArray& propertyNames)
{
    getOwnPropertyNames(exec, propertyNames);

    if (prototype().isNull())
        return;

    TiObject* prototype = asObject(this->prototype());
    while(1) {
        if (prototype->structure()->typeInfo().overridesGetPropertyNames()) {
            prototype->getPropertyNames(exec, propertyNames);
            break;
        }
        prototype->getOwnPropertyNames(exec, propertyNames);
        TiValue nextProto = prototype->prototype();
        if (nextProto.isNull())
            break;
        prototype = asObject(nextProto);
    }
}
Exemplo n.º 2
0
bool TiString::getOwnPropertySlot(TiExcState* exec, const Identifier& propertyName, PropertySlot& slot)
{
    // The semantics here are really getPropertySlot, not getOwnPropertySlot.
    // This function should only be called by TiValue::get.
    if (getStringPropertySlot(exec, propertyName, slot))
        return true;
    if (propertyName == exec->propertyNames().underscoreProto) {
        slot.setValue(exec->lexicalGlobalObject()->stringPrototype());
        return true;
    }
    slot.setBase(this);
    TiObject* object;
    for (TiValue prototype = exec->lexicalGlobalObject()->stringPrototype(); !prototype.isNull(); prototype = object->prototype()) {
        object = asObject(prototype);
        if (object->getOwnPropertySlot(exec, propertyName, slot))
            return true;
    }
    slot.setUndefined();
    return true;
}
int NativeImageViewObject::setImage(TiObject* obj)
{
	Handle<Value> img = obj->getValue();
	imageView_->resetImage();
    if (img->IsString()) {
        QString imagePath = V8ValueToQString(obj->getValue());
        if(imagePath.startsWith("http://") || imagePath.startsWith("https://"))
        {
        	ImageLoader::loadImage(imageView_, QUrl(imagePath));
            return NATIVE_ERROR_OK;
        }
        if(!QFile(imagePath).exists())
        {
        	imagePath = getResourcePath(imagePath);
        }
        imageView_->setImage(QUrl(imagePath));
    } else {
        TiObject* obj = TiObject::getTiObjectFromJsObject(img);
        // Ok, this is the old blob object, so get it, use it, and return.
        if (obj != NULL && strcmp(obj->getName(), "Blob") == 0)
        {
			TiBlobObject* blob = static_cast<TiBlobObject*>(obj);
			Image image(blob->data());
			imageView_->setImage(image);
		    return NATIVE_ERROR_OK;
        }
        // This might be the new blob object
        Handle<External> proxyObject = Handle<External>::Cast(img->ToObject()->GetHiddenValue(String::New("proxy")));

        // But return if it's not
        if(proxyObject.IsEmpty())
    		return NATIVE_ERROR_OK;

    	Ti::TiBlob* blob = static_cast<Ti::TiBlob*>(proxyObject->Value());
		Image image(blob->getData());
		imageView_->setImage(image);

    }
    return NATIVE_ERROR_OK;
}
Exemplo n.º 4
0
EncodedTiValue JSC_HOST_CALL errorProtoFuncToString(TiExcState* exec)
{
    TiObject* thisObj = exec->hostThisValue().toThisObject(exec);

    StringRecursionChecker checker(exec, thisObj);
    if (EncodedTiValue earlyReturnValue = checker.earlyReturnValue())
        return earlyReturnValue;

    TiValue name = thisObj->get(exec, exec->propertyNames().name);
    TiValue message = thisObj->get(exec, exec->propertyNames().message);

    // Mozilla-compatible format.

    if (!name.isUndefined()) {
        if (!message.isUndefined())
            return TiValue::encode(jsMakeNontrivialString(exec, name.toString(exec), ": ", message.toString(exec)));
        return TiValue::encode(jsNontrivialString(exec, name.toString(exec)));
    }
    if (!message.isUndefined())
        return TiValue::encode(jsMakeNontrivialString(exec, "Error: ", message.toString(exec)));
    return TiValue::encode(jsNontrivialString(exec, "Error"));
}
int NativeScrollViewObject::initialize()
{

	contentViewProxy_ = new NativeScrollViewContentObject(tiObject_, this);
	contentView_ = (bb::cascades::Container*)contentViewProxy_->getNativeHandle();


	scrollView_ = bb::cascades::ScrollView::create();
	nativeContentView_ = bb::cascades::Container::create();

	setControl(scrollView_);

	addChildImpl(contentViewProxy_);

	nativeContentView_->add(contentView_);
    scrollView_->setContent(nativeContentView_);

    scrollViewProperties_ = scrollView_->scrollViewProperties();

    ScrollViewEventHandler *eventHandler_ = new ScrollViewEventHandler(this);

    bb::cascades::LayoutUpdateHandler::create(nativeContentView_).onLayoutFrameChanged(eventHandler_, SLOT(onContainerLayoutChange(QRectF)));


 	TiObject height;
	height.setValue(String::New("UI.SIZE"));
	contentViewProxy_->setHeight(&height);

	TiObject width;
	width.setValue(String::New("UI.SIZE"));
	contentViewProxy_->setWidth(&width);


    contentSize_ = QSize(0,0);
    scrollViewSize_ = QSize(0,0);

    return NATIVE_ERROR_OK;
}
Exemplo n.º 6
0
GlobalObject::GlobalObject(const Vector<UString>& arguments)
    : TiGlobalObject()
{
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "debug"), functionDebug));
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "print"), functionPrint));
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "quit"), functionQuit));
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "gc"), functionGC));
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "version"), functionVersion));
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "run"), functionRun));
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "load"), functionLoad));
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "checkSyntax"), functionCheckSyntax));
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 0, Identifier(globalExec(), "readline"), functionReadline));

#if ENABLE(SAMPLING_FLAGS)
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "setSamplingFlags"), functionSetSamplingFlags));
    putDirectFunction(globalExec(), new (globalExec()) NativeFunctionWrapper(globalExec(), prototypeFunctionStructure(), 1, Identifier(globalExec(), "clearSamplingFlags"), functionClearSamplingFlags));
#endif

    TiObject* array = constructEmptyArray(globalExec());
    for (size_t i = 0; i < arguments.size(); ++i)
        array->put(globalExec(), i, jsString(globalExec(), arguments[i]));
    putDirect(Identifier(globalExec(), "arguments"), array);
}
Exemplo n.º 7
0
VALUE_MODIFY TiObject::_valueModify(int propertyNumber, TiObject* value, void* context)
{
    TiObject* self = static_cast<TiObject*>(context);
    NativeObject* object = self->getNativeObject();
    if (object == NULL)
    {
        return VALUE_MODIFY_NOT_SUPPORTED;
    }
    VALUE_MODIFY modify = VALUE_MODIFY_ALLOW;
    switch (object->setPropertyValue(propertyNumber, value))
    {
    case NATIVE_ERROR_OK:
        modify = VALUE_MODIFY_ALLOW;
        break;
    case NATIVE_ERROR_NOTSUPPORTED:
        modify = VALUE_MODIFY_ALLOW; //VALUE_MODIFY_NOT_SUPPORTED;
        break;
    default:
        modify = VALUE_MODIFY_INVALID;
        break;
    }
    object->release();
    return modify;
}
Handle<Value> TiUIBase::_animate(void* userContext, TiObject*, const Arguments& args)
{
    HandleScope handleScope;

    TiUIBase* self = static_cast<TiUIBase*>(userContext);
    NativeControlObject *native = static_cast<NativeControlObject*>(self->getNativeObject());
    TiObject* tiObject = TiObject::getTiObjectFromJsObject(args[0]);

    if(!tiObject) {
        Local<Object> jsObject = Local<Object>::Cast(args[0]);
        if(args.Length() > 1 && args[1]->IsFunction()) {
        	Handle<Function> callback = Handle<Function>::Cast(args[1]);
        	Handle<Object> source = Handle<Object>::Cast(self->getValue());
            TiV8Event* event = TiV8Event::createEvent("complete", callback, source);
        	native->animate(jsObject, event);
        } else {
            native->animate(jsObject);
        }
    } else {
        native->animate(tiObject->getNativeObject());
    }

    return Undefined();
}
Handle<Value> TiUITab::_open(void* userContext, TiObject*, const Arguments& args)
{
    HandleScope handleScope;
    if ((args.Length() > 0) && (args[0]->IsObject()))
    {
        TiObject* addObj = getTiObjectFromJsObject(args[0]);
        if ((addObj == NULL) || (!addObj->isUIObject()))
        {
            return Undefined();
        }
        TiUIBase* uiObj = (TiUIBase*) addObj;
        NativeObject* win = uiObj->getNativeObject();
        TiUITab* obj = (TiUITab*) userContext;
        NativeObject* tab = obj->getNativeObject();
        tab->openWindowOnTab(win);
        tab->release();
        win->release();
    }
    else
    {
        return ThrowException(String::New(Native::Msg::Expected_argument_of_type_object_or_external));
    }
    return Undefined();
}
Exemplo n.º 10
0
TiObject* Error::create(TiExcState* exec, ErrorType type, const UString& message, int lineNumber, intptr_t sourceID, const UString& sourceURL)
{
    TiObject* constructor;
    const char* name;
    switch (type) {
    case EvalError:
        constructor = exec->lexicalGlobalObject()->evalErrorConstructor();
        name = "Evaluation error";
        break;
    case RangeError:
        constructor = exec->lexicalGlobalObject()->rangeErrorConstructor();
        name = "Range error";
        break;
    case ReferenceError:
        constructor = exec->lexicalGlobalObject()->referenceErrorConstructor();
        name = "Reference error";
        break;
    case SyntaxError:
        constructor = exec->lexicalGlobalObject()->syntaxErrorConstructor();
        name = "Syntax error";
        break;
    case TypeError:
        constructor = exec->lexicalGlobalObject()->typeErrorConstructor();
        name = "Type error";
        break;
    case URIError:
        constructor = exec->lexicalGlobalObject()->URIErrorConstructor();
        name = "URI error";
        break;
    default:
        constructor = exec->lexicalGlobalObject()->errorConstructor();
        name = "Error";
        break;
    }

    MarkedArgumentBuffer args;
    if (message.isEmpty())
        args.append(jsString(exec, name));
    else
        args.append(jsString(exec, message));
    ConstructData constructData;
    ConstructType constructType = constructor->getConstructData(constructData);
    TiObject* error = construct(exec, constructor, constructType, constructData, args);

    if (lineNumber != -1)
        error->putWithAttributes(exec, Identifier(exec, "line"), jsNumber(exec, lineNumber), ReadOnly | DontDelete);
    if (sourceID != -1)
        error->putWithAttributes(exec, Identifier(exec, "sourceId"), jsNumber(exec, sourceID), ReadOnly | DontDelete);
    if (!sourceURL.isNull())
        error->putWithAttributes(exec, Identifier(exec, "sourceURL"), jsString(exec, sourceURL), ReadOnly | DontDelete);

    return error;
}
Exemplo n.º 11
0
static void JSObjectWeakCallBack(v8::Persistent<Value> object, void* parameter)
{
	TiObject* thisObject = static_cast<TiObject*>(parameter);
	thisObject->setNativeObject(NULL);
	thisObject->release();
}
Handle<Value> TiUIBase::_remove(void* userContext, TiObject*, const Arguments& args)
{
    HandleScope handleScope;
    // JavaScript usage:
    //
    // arg[0] = Titanium.UI.View
    //
    if (args.Length() < 1)
    {
        return ThrowException(String::New(Ti::Msg::Missing_argument));
    }
    if (!args[0]->IsObject())
    {
        return ThrowException(String::New(Ti::Msg::Invalid_remove_argument));
    }

    TiUIBase* obj = (TiUIBase*) userContext;
    TiObject* removeObject = TiObject::getTiObjectFromJsObject(args[0]);
    if (removeObject == NULL)
    {
        return ThrowException(String::New(Ti::Msg::Invalid_remove_argument));
    }
    NativeObject* parentControl = obj->getNativeObject();
    if (parentControl == NULL)
    {
        return ThrowException(String::New(Ti::Msg::INTERNAL__Missing_native_object));
    }
    vector<ObjectEntry>::const_iterator it;
    bool foundChild = false;
    for (it = obj->childControls_.begin(); it != obj->childControls_.end(); it++)
    {
        if ((*it).isSameInstance(removeObject))
        {
            NativeObject* childControl = (*it)->getNativeObject();
            if (childControl == NULL)
            {
                parentControl->release();
                return ThrowException(String::New(Ti::Msg::INTERNAL__Missing_native_object));
            }
            parentControl->removeChildNativeObject(childControl);
            int len = obj->jsChildren_->Length();
            for(int i = 0; i < len; i++)
            {
            	if(obj->jsChildren_->Get(i) == removeObject->getValue())
            	{
                    obj->jsChildren_->Delete(i);
                    break;
            	}
            }
            childControl->release();
            foundChild = true;
            break;
        }
    }
    parentControl->release();
    if (!foundChild)
    {
        TI_WARNING(Ti::Msg::Remove_child_warning);
    }
    return Undefined();
}
Exemplo n.º 13
0
// ECMA 8.6.2.2
void TiObject::put(TiExcState* exec, const Identifier& propertyName, TiValue value, PutPropertySlot& slot)
{
    ASSERT(value);
    ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));

    if (propertyName == exec->propertyNames().underscoreProto) {
        // Setting __proto__ to a non-object, non-null value is silently ignored to match Mozilla.
        if (!value.isObject() && !value.isNull())
            return;

        TiValue nextPrototypeValue = value;
        while (nextPrototypeValue && nextPrototypeValue.isObject()) {
            TiObject* nextPrototype = asObject(nextPrototypeValue)->unwrappedObject();
            if (nextPrototype == this) {
                throwError(exec, GeneralError, "cyclic __proto__ value");
                return;
            }
            nextPrototypeValue = nextPrototype->prototype();
        }

        setPrototype(value);
        return;
    }

    // Check if there are any setters or getters in the prototype chain
    TiValue prototype;
    for (TiObject* obj = this; !obj->structure()->hasGetterSetterProperties(); obj = asObject(prototype)) {
        prototype = obj->prototype();
        if (prototype.isNull()) {
            putDirectInternal(exec->globalData(), propertyName, value, 0, true, slot);
            return;
        }
    }
    
    unsigned attributes;
    TiCell* specificValue;
    if ((m_structure->get(propertyName, attributes, specificValue) != WTI::notFound) && attributes & ReadOnly)
        return;

    for (TiObject* obj = this; ; obj = asObject(prototype)) {
        if (TiValue gs = obj->getDirect(propertyName)) {
            if (gs.isGetterSetter()) {
                TiObject* setterFunc = asGetterSetter(gs)->setter();        
                if (!setterFunc) {
                    throwSetterError(exec);
                    return;
                }
                
                CallData callData;
                CallType callType = setterFunc->getCallData(callData);
                MarkedArgumentBuffer args;
                args.append(value);
                call(exec, setterFunc, callType, callData, this, args);
                return;
            }

            // If there's an existing property on the object or one of its 
            // prototypes it should be replaced, so break here.
            break;
        }

        prototype = obj->prototype();
        if (prototype.isNull())
            break;
    }

    putDirectInternal(exec->globalData(), propertyName, value, 0, true, slot);
    return;
}