Handle<Value> TiUIBase::_add(void* userContext, TiObject*, const Arguments& args) { HandleScope handleScope; TiUIBase* obj = (TiUIBase*) userContext; if ((args.Length() > 0) && (args[0]->IsObject())) { TiObject* addObj = getTiObjectFromJsObject(args[0]); if ((addObj == NULL) || (!addObj->isUIObject())) { return ThrowException(String::New(Ti::Msg::Invalid_add_argument)); } TiUIBase* uiObj = (TiUIBase*) addObj; NativeObject* childNO = uiObj->getNativeObject(); if (childNO == NULL) { return ThrowException(String::New(Ti::Msg::Invalid_add_argument)); } NativeObject* parentNO = obj->getNativeObject(); if (N_SUCCEEDED(parentNO->addChildNativeObject(childNO))) { ObjectEntry entry = addObj; obj->childControls_.push_back(entry); obj->jsChildren_->Set(obj->jsChildren_->Length(), addObj->getValue()); } childNO->release(); parentNO->release(); } else { // TODO: expand this exception } return Undefined(); }
Handle<Value> TiUIBase::_show(void* userContext, TiObject*, const Arguments&) { TiUIBase* obj = (TiUIBase*) userContext; NativeObject* no = obj->getNativeObject(); no->setVisibility(true); return Undefined(); }
void TiUITableViewRow::initializeTiObject(TiObject* parentContext) { if (isInitialized()) return; TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_TABLE_VIEW_ROW, this); setNativeObject(obj); obj->release(); }
Handle<Value> TiUIBase::_finishLayout(void* userContext, TiObject*, const Arguments&) { TiUIBase* obj = (TiUIBase*) userContext; NativeObject* no = obj->getNativeObject(); no->finishLayout(); return Undefined(); }
bool WatchpointMap::triggerWatchpoint(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp) { Map::Ptr p = map.lookup(WatchKey(obj, id)); if (!p || p->value().held) return true; AutoEntryHolder holder(cx, map, p); /* Copy the entry, since GC would invalidate p. */ JSWatchPointHandler handler = p->value().handler; RootedObject closure(cx, p->value().closure); /* Determine the property's old value. */ Value old; old.setUndefined(); if (obj->isNative()) { NativeObject* nobj = &obj->as<NativeObject>(); if (Shape* shape = nobj->lookup(cx, id)) { if (shape->hasSlot()) old = nobj->getSlot(shape->slot()); } } // Read barrier to prevent an incorrectly gray closure from escaping the // watchpoint. See the comment before UnmarkGrayChildren in gc/Marking.cpp JS::ExposeObjectToActiveJS(closure); /* Call the handler. */ return handler(cx, obj, id, old, vp.address(), closure); }
void TiObject::onSetupEvents() { NativeObject* nativeObject = getNativeObject(); if (nativeObject != NULL) { nativeObject->completeInitialization(); nativeObject->release(); } }
void TiMapView::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_MAPVIEW, this); setNativeObject(obj); obj->release(); } }
void TiUIImageButton::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_IMAGE_BUTTON, this); setNativeObject(obj); obj->release(); } }
void TiAnnotationObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_ANNOTATION, this); setNativeObject(obj); obj->release(); } }
void TiVideoPlayerObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_VIDEOPLAYER, this); setNativeObject(obj); obj->release(); } }
void TiHTTPClientObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiProxy::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_HTTPCLIENT, this); setNativeObject(obj); obj->release(); } }
void TiAudioRecorderObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_AUDIORECORDER, this); setNativeObject(obj); obj->release(); } }
void TiGeolocation::initializeTiObject(TiObject* parentContext) { if (isInitialized()) { return; } TiProxy::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_GEOLOCATION, this); setNativeObject(obj); obj->release(); }
void TiUIAlertDialog::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiProxy::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_ALERTDIALOG, this); setNativeObject(obj); obj->release(); } }
void TiAccelerometer::initializeTiObject(TiObject* parentContext) { if (isInitialized()) { return; } TiProxy::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_ACCELEROMETER, this); setNativeObject(obj); obj->release(); }
void TiTCPSocketObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiIOStreamObject::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_TCPSOCKET, this); setNativeObject(obj); obj->release(); } }
void TiUITextArea::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_TEXT_AREA, this); setNativeObject(obj); obj->release(); } }
Handle<Value> TiObject::_getValue(int propertyNumber, void* context) { TiObject* self = static_cast<TiObject*>(context); NativeObject* object = self->getNativeObject(); TiObject value; if (object != NULL) { object->getPropertyValue(propertyNumber, &value); } return value.getValue(); }
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(); }
Handle<Value> TiUIBase::_getValue(int propertyNumber, void* context) { TiUIBase* self = (TiUIBase*) context; NativeObject* object = self->getNativeObject(); TiObject value; if (object != NULL) { object->getPropertyValue(propertyNumber, &value); } return value.getValue(); }
/* static */ NativeObject * js::ForOfPIC::createForOfPICObject(JSContext *cx, Handle<GlobalObject*> global) { assertSameCompartment(cx, global); NativeObject *obj = NewNativeObjectWithGivenProto(cx, &ForOfPIC::jsclass, nullptr, global); if (!obj) return nullptr; ForOfPIC::Chain *chain = cx->new_<ForOfPIC::Chain>(); if (!chain) return nullptr; obj->setPrivate(chain); return obj; }
void TiUIBase::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiProxy::initializeTiObject(parentContext); /* Don't create a native view object for derived classes */ if (string("View") == getName()) { NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_VIEW, this); setNativeObject(obj); obj->release(); } } }
bool RegExpObjectBuilder::getOrCreate() { if (reobj_) return true; // Note: RegExp objects are always allocated in the tenured heap. This is // not strictly required, but simplifies embedding them in jitcode. NativeObject *obj = NewNativeBuiltinClassInstance(cx, &RegExpObject::class_, TenuredObject); if (!obj) return false; obj->initPrivate(nullptr); reobj_ = &obj->as<RegExpObject>(); return true; }
Handle<Value> TiUITableView::_scrollToIndex(void* userContext, TiObject*, const Arguments& args) { HandleScope handleScope; TiUITableView* obj = (TiUITableView*) userContext; NativeObject* no = obj->getNativeObject(); if (args[0]->IsNumber()) { Local<Integer> index = args[0]->ToInteger(); no->scrollToIndex(index->Value()); } else { TI_DEBUG(Ti::Msg::INTERNAL__args0_is_not_a_number); } return Undefined(); }
bool RegExpObjectBuilder::getOrCreateClone(HandleTypeObject type) { MOZ_ASSERT(!reobj_); MOZ_ASSERT(type->clasp() == &RegExpObject::class_); JSObject *parent = type->proto().toObject()->getParent(); // Note: RegExp objects are always allocated in the tenured heap. This is // not strictly required, but simplifies embedding them in jitcode. NativeObject *clone = NewNativeObjectWithType(cx->asJSContext(), type, parent, TenuredObject); if (!clone) return false; clone->initPrivate(nullptr); reobj_ = &clone->as<RegExpObject>(); return true; }
/* static */ GlobalObject::DebuggerVector* GlobalObject::getOrCreateDebuggers(JSContext* cx, Handle<GlobalObject*> global) { assertSameCompartment(cx, global); DebuggerVector* debuggers = global->getDebuggers(); if (debuggers) return debuggers; NativeObject* obj = NewNativeObjectWithGivenProto(cx, &GlobalDebuggees_class, nullptr); if (!obj) return nullptr; debuggers = cx->new_<DebuggerVector>(); if (!debuggers) return nullptr; obj->setPrivate(debuggers); global->setReservedSlot(DEBUGGERS, ObjectValue(*obj)); return debuggers; }
Handle<Value> TiProxy::_fireEvent(void* userContext, TiObject*, const Arguments& args) { if (args.Length() < 1) { return Undefined(); } const TiProxy* obj = (TiProxy*) userContext; if(QString(obj->getName()) == "App") { Local<Object> eventParams = Object::New(); if(args.Length() > 1) { eventParams->Set(String::New("data"), args[1]->ToObject()); } else { eventParams->Set(String::New("data"), Object::New()); } eventParams->Set(String::New("id"), args[0]->ToString()); Local<String> event = JSON::Stringify(eventParams); QString eventString = titanium::V8ValueToQString(event); QList<TiUIWebView*> webViews = TiUIWebView::getWebViews(); for(int i = 0, len = webViews.length(); i < len; i++) { webViews.at(i)->getNativeWebView()->postMessage(eventString); } } NativeObject* no = obj->getNativeObject(); if (!no) return Undefined(); const String::Utf8Value name(args[0]->ToString()); if (args.Length() >= 2) { const TiObject event("", args[1]); no->fireEvent(*name, &event); } else { no->fireEvent(*name, NULL); } no->release(); return Undefined(); }
void TiProxy::setParametersFromObject(void* userContext, Local<Object> obj) { HandleScope handleScope; Handle<Value> value; Handle<Value> controlValue = getValue(); if (!controlValue->IsObject()) { return; } Handle<Array> propNames = obj->GetPropertyNames(); uint32_t props = propNames->Length(); Local<Value> propValue; for (uint32_t i = 0; i < props; i++) { Handle<String> propString = Handle<String>::Cast(propNames->Get(Integer::New(i))); String::Utf8Value propNameUTF(propString); Local<Value> propValue = obj->Get(propString); TiObject* foundProp = onLookupMember(*propNameUTF); if (foundProp != NULL) { TiObject* addObj = getTiObjectFromJsObject(propValue); if (addObj) { TiProxy* obj = (TiProxy*) userContext; TiProxy* uiObj = (TiProxy*) addObj; NativeObject* childNO = uiObj->getNativeObject(); NativeObject* parentNO = obj->getNativeObject(); parentNO->addChildNativeObject(childNO); parentNO->release(); } else { foundProp->setValue(propValue); } } else { // Set any custom properties onto the JS object. getValue()->ToObject()->ForceSet(propString, propValue); } } }
void TiProxy::onAddEventListener(const char* eventName, Handle<Function> eventFunction) { NativeObject* no = getNativeObject(); if (no == NULL) { // To support events we need to create a native proxy // instance here if no native object has been set yet. no = new NativeProxyObject(this); setNativeObject(no); } Handle<Object> source = Handle<Object>::Cast(getValue()); TiV8Event* event = TiV8Event::createEvent(eventName, eventFunction, source); no->setEventHandler(eventName, event); no->release(); no = NULL; int id = event->getId(); eventFunction->SetHiddenValue(String::New("POINTER"), External::New(event)); eventFunction->SetHiddenValue(String::New("OWNER"), External::New(this)); eventFunction->SetHiddenValue(String::New("ID"), Integer::New(id)); }
JS::ForceLexicalInitialization(JSContext *cx, HandleObject obj) { AssertHeapIsIdle(); CHECK_REQUEST(cx); assertSameCompartment(cx, obj); bool initializedAny = false; NativeObject* nobj = &obj->as<NativeObject>(); for (Shape::Range<NoGC> r(nobj->lastProperty()); !r.empty(); r.popFront()) { Shape* s = &r.front(); Value v = nobj->getSlot(s->slot()); if (s->isDataProperty() && v.isMagic() && v.whyMagic() == JS_UNINITIALIZED_LEXICAL) { nobj->setSlot(s->slot(), UndefinedValue()); initializedAny = true; } } return initializedAny; }