Emails js_to_Emails(const JSObject& object) { std::vector<std::string> home; if (object.HasProperty("home")) { const auto js_home_object = static_cast<JSObject>(object.GetProperty("home")); if (js_home_object.IsArray()) { home = static_cast<std::vector<std::string>>(static_cast<JSArray>(js_home_object)); } } std::vector<std::string> work; if (object.HasProperty("work")) { const auto js_work_object = static_cast<JSObject>(object.GetProperty("work")); if (js_work_object.IsArray()) { work = static_cast<std::vector<std::string>>(static_cast<JSArray>(js_work_object)); } } std::vector<std::string> other; if (object.HasProperty("other")) { const auto js_other_object = static_cast<JSObject>(object.GetProperty("other")); if (js_other_object.IsArray()) { other = static_cast<std::vector<std::string>>(static_cast<JSArray>(js_other_object)); } } Emails emails { home, work, other }; return emails; };
TITANIUM_FUNCTION(SocketModule, createUDP) { TITANIUM_LOG_DEBUG("SocketModule::createUDP: "); ENSURE_OPTIONAL_OBJECT_AT_INDEX(parameters, 0); JSValue Titanium_property = get_context().get_global_object().GetProperty("Titanium"); TITANIUM_ASSERT(Titanium_property.IsObject()); // precondition JSObject Titanium = static_cast<JSObject>(Titanium_property); JSValue Network_property = Titanium.GetProperty("Network"); TITANIUM_ASSERT(Network_property.IsObject()); // precondition JSObject Network = static_cast<JSObject>(Network_property); JSValue Socket_property = Network.GetProperty("Socket"); TITANIUM_ASSERT(Socket_property.IsObject()); // precondition JSObject Socket = static_cast<JSObject>(Socket_property); JSValue UDP_property = Socket.GetProperty("UDP"); TITANIUM_ASSERT(UDP_property.IsObject()); // precondition JSObject UDP = static_cast<JSObject>(UDP_property); auto udp = UDP.CallAsConstructor(); applyProperties(parameters, udp); return udp; }
AcceptDict js_to_AcceptDict(const JSObject& object) { const auto timeout = std::chrono::milliseconds(static_cast<std::chrono::milliseconds::rep>( static_cast<std::uint32_t>(object.GetProperty("timeout")))); AcceptDict config { object.GetProperty("error"), timeout }; return config; };
GradientColorRef js_to_GradientColorRef(const JSObject& object) { GradientColorRef colorRef; if (object.HasProperty("color")) { colorRef.color = static_cast<std::string>(object.GetProperty("color")); } if (object.HasProperty("offset")) { colorRef.offset = static_cast<double>(object.GetProperty("offset")); } return colorRef; }
MapRegionTypev2 js_to_MapRegionTypev2(const JSObject& object) { MapRegionTypev2 value { 0, 0, 0, 0, 0, 0, 0 }; if (object.HasProperty("bearing")) { value.bearing = static_cast<double>(object.GetProperty("bearing")); } if (object.HasProperty("latitude")) { value.latitude = static_cast<double>(object.GetProperty("latitude")); } if (object.HasProperty("latitudeDelta")) { value.latitudeDelta = static_cast<double>(object.GetProperty("latitudeDelta")); } if (object.HasProperty("longitude")) { value.longitude = static_cast<double>(object.GetProperty("longitude")); } if (object.HasProperty("longitudeDelta")) { value.longitudeDelta = static_cast<double>(object.GetProperty("longitudeDelta")); } if (object.HasProperty("tilt")) { value.tilt = static_cast<double>(object.GetProperty("tilt")); } if (object.HasProperty("zoom")) { value.zoom = static_cast<uint32_t>(object.GetProperty("zoom")); } return value; };
TITANIUM_FUNCTION(UIModule, create2DMatrix) { ENSURE_OPTIONAL_OBJECT_AT_INDEX(parameters, 0); // FIXME Macros didn't work because identifiers can't start with digits! JSValue Titanium_property = this_object.get_context().get_global_object().GetProperty("Titanium"); TITANIUM_ASSERT(Titanium_property.IsObject()); JSObject Titanium = static_cast<JSObject>(Titanium_property); JSValue UI_property = Titanium.GetProperty("UI"); TITANIUM_ASSERT(UI_property.IsObject()); JSObject UI = static_cast<JSObject>(UI_property); JSValue TwoDMatrix_property = UI.GetProperty("2DMatrix"); TITANIUM_ASSERT(TwoDMatrix_property.IsObject()); JSObject TwoDMatrix = static_cast<JSObject>(TwoDMatrix_property); auto TwoDMatrix_obj = TwoDMatrix.CallAsConstructor(parameters); Titanium::Module::applyProperties(parameters, TwoDMatrix_obj); return TwoDMatrix_obj; }
//==================================================================== //==================================================================== void CBaseHTML::SetProperty( const char *pKeyname, JSValue pValue, JSObject pObject ) { JSValue pOldValue = pObject.GetProperty( WSLit(pKeyname) ); //if ( FStrEq(ToString(pOldValue.ToString()).c_str(), ToString(pValue.ToString()).c_str()) ) //return; pObject.SetProperty( WSLit(pKeyname), pValue ); }
RouteDescription js_to_RouteDescription(const JSObject& object) { RouteDescription config; const auto inputs_property = object.GetProperty("inputs"); ENSURE_ARRAY(inputs_property, js_inputs); const auto inputs = static_cast<std::vector<JSValue>>(js_inputs); for (const auto v : inputs) { config.inputs.push_back(static_cast<AudioSessionPort>(static_cast<std::uint32_t>(v))); } const auto outputs_property = object.GetProperty("outputs"); ENSURE_ARRAY(outputs_property, js_outputs); const auto outputs = static_cast<std::vector<JSValue>>(js_outputs); for (const auto v : outputs) { config.outputs.push_back(static_cast<AudioSessionPort>(static_cast<std::uint32_t>(v))); } return config; };
PushNotificationConfig js_to_PushNotificationConfig(const JSObject& object) { std::vector<Network::TYPE> types; const auto js_types_property = object.GetProperty("types"); if (js_types_property.IsObject()) { const auto js_types_object = static_cast<JSObject>(js_types_property); if (js_types_object.IsArray()) { const auto js_types = static_cast<std::vector<JSValue>>(static_cast<JSArray>(js_types_object)); for (const auto t : js_types) { types.push_back(Titanium::Network::Constants::to_TYPE(static_cast<std::underlying_type<Network::TYPE>::type>(t))); } } } PushNotificationConfig config { object.GetProperty("callback"), object.GetProperty("error"), object.GetProperty("success"), types }; return config; };
JSValue GlobalObject::requireBuiltinModule(const JSContext& js_context, const std::string& moduleId) { if (moduleId == "ti.map") { JSValue Titanium_property = js_context.get_global_object().GetProperty("Titanium"); TITANIUM_ASSERT(Titanium_property.IsObject()); // precondition JSObject Titanium = static_cast<JSObject>(Titanium_property); JSValue Map_property = Titanium.GetProperty("Map"); TITANIUM_ASSERT(Map_property.IsObject()); // precondition return Map_property; } return js_context.CreateUndefined(); }
void JSClass::ConstructorInitializeCallback(const JSContext& js_context, JSObject& this_object) const { if (!this_object.HasProperty("prototype")) { auto js_object = js_context.CreateObject(); this_object.SetProperty("prototype", js_object); } auto proto_object = static_cast<JSObject>(this_object.GetProperty("prototype")); for (const auto v : prototype_functions_map__) { // // NOTE: On HAL, there's no difference between object "static" property and prototype property // so add it to both // this_object.SetProperty(v.first, JSObjectMakeFunctionWithCallback(js_context, v.first, v.second)); proto_object.SetProperty(v.first, JSObjectMakeFunctionWithCallback(js_context, v.first, v.second)); } }
CameraMediaItemType js_to_CameraMediaItemType(const JSObject& object) { CameraMediaItemType config; config.code = static_cast<std::int32_t>(object.GetProperty("code")); if (object.HasProperty("cropRect")) { config.cropRect = Titanium::UI::js_to_Dimension(static_cast<JSObject>(object.GetProperty("cropRect"))); } if (object.HasProperty("error")) { config.error = static_cast<std::string>(object.GetProperty("error")); } const auto js_media = object.GetProperty("media"); ENSURE_MODULE_OBJECT(js_media, media, Titanium::Blob); config.media = media; config.mediaType = static_cast<MediaType>(static_cast<std::uint32_t>(object.GetProperty("mediaType"))); config.success = static_cast<bool>(object.GetProperty("success")); return config; };
Gradient js_to_Gradient(const JSObject& object) { Gradient gradient; if (object.HasProperty("backfillEnd")) { gradient.backfillEnd = static_cast<bool>(object.GetProperty("backfillEnd")); } if (object.HasProperty("backfillStart")) { gradient.backfillStart = static_cast<bool>(object.GetProperty("backfillStart")); } if (object.HasProperty("endRadius")) { gradient.endRadius = static_cast<double>(object.GetProperty("endRadius")); } if (object.HasProperty("startRadius")) { gradient.startRadius = static_cast<double>(object.GetProperty("startRadius")); } if (object.HasProperty("endPoint")) { auto end_property = object.GetProperty("endPoint"); if (end_property.IsObject()) { gradient.endPoint = js_to_Point(static_cast<JSObject>(end_property)); } else { TITANIUM_LOG_WARN("js_to_Gradient: Invalid endPoint"); } } if (object.HasProperty("startPoint")) { auto start_property = object.GetProperty("startPoint"); if (start_property.IsObject()) { gradient.startPoint = js_to_Point(static_cast<JSObject>(start_property)); } else { TITANIUM_LOG_WARN("js_to_Gradient: Invalid startPoint"); } } if (object.HasProperty("type")) { auto type_property = object.GetProperty("type"); if (type_property.IsNumber()) { gradient.type = Constants::to_GRADIENT_TYPE(static_cast<std::underlying_type<GRADIENT_TYPE>::type>(type_property)); } else { gradient.type = Constants::to_GRADIENT_TYPE(static_cast<std::string>(type_property)); } } if (object.HasProperty("color")) { auto color_property = object.GetProperty("color"); if (color_property.IsString()) { gradient.color.push_back(js_to_GradientColorRef(static_cast<std::string>(color_property))); } else if (color_property.IsObject()) { auto js_color = static_cast<JSObject>(color_property); if (js_color.IsArray()) { const auto length = static_cast<uint32_t>(js_color.GetProperty("length")); for (uint32_t i = 0; i < length; i++) { auto item = js_color.GetProperty(i); TITANIUM_ASSERT(item.IsObject()); if (item.IsObject()) { gradient.color.push_back(js_to_GradientColorRef(static_cast<JSObject>(item))); } else { TITANIUM_LOG_WARN("js_to_Gradient: Invalid GradientColorRef"); } } } else { gradient.color.push_back(js_to_GradientColorRef(static_cast<std::string>(color_property))); } } } return gradient; };
ShowContactsParams js_to_ShowContactsParams(const JSObject& object) { auto animated = true; if (object.HasProperty("animated")) { animated = static_cast<bool>(object.GetProperty("animated")); } std::vector<std::string> fields; if (object.HasProperty("fields")) { const auto js_fields_object = static_cast<JSObject>(object.GetProperty("fields")); if (js_fields_object.IsArray()) { const auto js_fields = static_cast<std::vector<JSValue>>(static_cast<JSArray>(js_fields_object)); for (const auto f : js_fields) { fields.push_back(static_cast<std::string>(f)); } } } const auto cancel_property = object.GetProperty("cancel"); const auto oncancel = [cancel_property]() { if (cancel_property.IsObject()) { auto func = static_cast<JSObject>(cancel_property); if (func.IsFunction()) { const std::vector<JSValue> args = {}; func(args, func); } } }; const auto selectedPerson_property = object.GetProperty("selectedPerson"); const auto onselectedPerson = [selectedPerson_property](const std::shared_ptr<Person>& e) { if (selectedPerson_property.IsObject()) { auto func = static_cast<JSObject>(selectedPerson_property); if (func.IsFunction()) { auto obj = func.get_context().CreateObject(); obj.SetProperty("person", e->get_object()); const std::vector<JSValue> args = { static_cast<JSValue>(obj) }; func(args, func); } } }; const auto selectedProperty_property = object.GetProperty("selectedProperty"); const auto onselectedProperty = [selectedProperty_property](const std::shared_ptr<Person>& e) { if (selectedProperty_property.IsObject()) { auto func = static_cast<JSObject>(selectedProperty_property); if (func.IsFunction()) { auto obj = func.get_context().CreateObject(); obj.SetProperty("person", e->get_object()); const std::vector<JSValue> args = { static_cast<JSValue>(obj) }; func(args, func); } } }; ShowContactsParamsCallbacks callbacks { cancel_property, selectedPerson_property, selectedProperty_property, oncancel, onselectedPerson, onselectedProperty }; ShowContactsParams config { animated, fields, callbacks }; return config; };