Пример #1
0
bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot)
{
    // This is not a general purpose implementation of getOwnPropertySlot.
    // It should only be called by JSValue::get.
    // It calls getPropertySlot, not getOwnPropertySlot.
    JSObject* object = toObject(exec);
    slot.setBase(object);
    if (!object->getPropertySlot(exec, identifier, slot))
        slot.setUndefined();
    return true;
}
Пример #2
0
bool Dictionary::hasProperty(const String& key) const
{
    v8::Local<v8::Object> object;
    if (!toObject(object))
        return false;

    ASSERT(m_isolate);
    ASSERT(m_isolate == v8::Isolate::GetCurrent());
    ASSERT(m_exceptionState);
    v8::Local<v8::String> v8Key = v8String(m_isolate, key);
    return v8CallBoolean(object->Has(v8Context(), v8Key));
}
Пример #3
0
QString HttpDaemon::Private::findHandler(QString const &filename) const
{
  QFileInfo fileInfo(filename);
  auto suffix = fileInfo.suffix();
  auto handle = serverSettings.object().value(settings_handler);
  auto handleObj = handle.toObject();
  for (auto k : handleObj.keys()) {
    if (handleObj.value(k).toArray().contains(suffix))
      return k;
  }
  return QString();
}
Пример #4
0
QString HttpDaemon::Private::findType(QString const &filename) const
{
  QFileInfo fileInfo(filename);
  auto suffix = fileInfo.suffix();
  auto types = serverSettings.object().value(settings_types);
  auto typesObj = types.toObject();
  for (auto k : typesObj.keys()) {
    if (typesObj.value(k).toArray().contains(suffix))
      return k;
  }
  return QString();
}
Пример #5
0
bool Dictionary::getInternal(const v8::Local<v8::Value>& key,
                             v8::Local<v8::Value>& result) const {
  v8::Local<v8::Object> object;
  if (!toObject(object))
    return false;

  DCHECK(m_isolate);
  DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent());
  if (!v8CallBoolean(object->Has(v8Context(), key)))
    return false;
  return object->Get(v8Context(), key).ToLocal(&result);
}
Пример #6
0
void StringManager::readFromData(QJsonObject& out ,EdgableItems*,QGraphicsScene* scene)
{
    /*settings.beginGroup("StringManager");
    m_availableLang = settings.value("Availablelang");
    m_currentLang = settings.value("currentlang");*/
    /*out >> m_availableLang;
    QMap<QString,QString> lang;
    out >> lang;
    m_currentLang.unite(lang);*/

   // qDebug()<< m_currentLang.size() << m_availableLang.size();

    QJsonObject stringManager = out["stringManager"].toObject();

    QJsonArray array = stringManager["curretLang"].toArray();
    for(auto it = array.begin(); it != array.end();++it)
    {
        QJsonObject duo = it->toObject();
        QString key = duo["key"].toString();
        QString val = duo["value"].toString();
        m_currentLang.insert(key,val);
    }

    QJsonArray array2 = stringManager["availLang"].toArray();
    for(auto it = array2.begin(); it != array2.end();++it)
    {
        QJsonArray array3 = it->toArray();
        QMap<QString, QString> map;
        for(auto it = array3.begin(); it != array3.end();++it)
        {
            QJsonObject duo = it->toObject();
            QString key = duo["key"].toString();
            QString val = duo["value"].toString();

            map.insert(key,val);
        }
        m_availableLang.append(map);

    }
}
Пример #7
0
Py::Object toObject
    (
    const svn_wc_entry_t &svn_entry,
    SvnPool &pool,
    const DictWrapper &wrapper_entry
    )
{
    Py::Dict entry;

    entry[ str_checksum ] = utf8_string_or_none( svn_entry.checksum );
    entry[ str_commit_author ] = utf8_string_or_none( svn_entry.cmt_author );
    entry[ str_commit_revision ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, svn_entry.cmt_rev ) );
    entry[ str_commit_time ] = toObject( svn_entry.cmt_date );
    entry[ str_conflict_new ] = path_string_or_none( svn_entry.conflict_new, pool );
    entry[ str_conflict_old ] = path_string_or_none( svn_entry.conflict_old, pool );
    entry[ str_conflict_work ] = path_string_or_none( svn_entry.conflict_wrk, pool );
    entry[ str_copy_from_revision ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, svn_entry.copyfrom_rev ) );
    entry[ str_copy_from_url ] = utf8_string_or_none( svn_entry.copyfrom_url );
    entry[ str_is_absent ] = Py::Int( svn_entry.absent );
    entry[ str_is_copied ] = Py::Int( svn_entry.copied );
    entry[ str_is_deleted ] = Py::Int( svn_entry.deleted );
    entry[ str_kind ] = toEnumValue( svn_entry.kind );
    entry[ str_name ] = path_string_or_none( svn_entry.name, pool );
    entry[ str_properties_time ] = toObject( svn_entry.prop_time );
    entry[ str_property_reject_file ] = path_string_or_none( svn_entry.prejfile, pool );
    entry[ str_repos ] = utf8_string_or_none( svn_entry.repos );
    entry[ str_revision ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, svn_entry.revision ) );
    entry[ str_schedule ] = toEnumValue( svn_entry.schedule );
    entry[ str_text_time ] = toObject( svn_entry.text_time );
    entry[ str_url ] = utf8_string_or_none( svn_entry.url );
    entry[ str_uuid ] = utf8_string_or_none( svn_entry.uuid );
#if defined( PYSVN_HAS_CLIENT_STATUS2 )
    entry[ str_lock_token ] = utf8_string_or_none( svn_entry.lock_token );
    entry[ str_lock_owner ] = utf8_string_or_none( svn_entry.lock_owner );
    entry[ str_lock_comment ] = utf8_string_or_none( svn_entry.lock_comment );
    entry[ str_lock_creation_date ] = toObject( svn_entry.lock_creation_date );
#endif

    return wrapper_entry.wrapDict( entry );
}
Пример #8
0
static Variant HHVM_METHOD(Yaf_Controller_Abstract, redirect,  
        const String& location)
{
    auto tmp = this_->o_realProp(YAF_CONTROLLER_PROPERTY_NAME_RESPONSE, 
            ObjectData::RealPropUnchecked, "Yaf_Controller_Abstract");
    if (tmp->isNull()) {
        return false;
    }

    auto response = tmp->toObject();
    (void)yaf_response_set_redirect(response, location);
    return true;
}
Пример #9
0
std::vector<CSSEnvironment>
CRestWorker::get_environments(int& http_code,
                              int& err_code,
                              int& network_error) {
  std::vector<CSSEnvironment> lst_res;
  QJsonDocument doc = get_request_json_document("environments", http_code, err_code, network_error);  
  QJsonArray arr = doc.array();
  for (auto i = arr.begin(); i != arr.end(); ++i) {
    if (i->isNull() || !i->isObject()) continue;
    lst_res.push_back(CSSEnvironment(i->toObject()));
  }
  return lst_res;
}
Пример #10
0
bool Dictionary::getKey(const String& key, v8::Local<v8::Value>& value) const
{
    v8::Local<v8::Object> object;
    if (!toObject(object))
        return false;

    ASSERT(m_isolate);
    ASSERT(m_isolate == v8::Isolate::GetCurrent());
    ASSERT(m_exceptionState);
    v8::Local<v8::String> v8Key = v8String(m_isolate, key);
    if (!v8CallBoolean(object->Has(v8Context(), v8Key)))
        return false;
    return object->Get(v8Context(), v8Key).ToLocal(&value);
}
Пример #11
0
void Project::fromJSON(const QJsonObject& project)
{
    mEventTypes.clear();

    mName = project["name"].toString();
    if (!project["lastOpenedTimeline"].toString().isEmpty())
        mLastOpenedTimeline = QDir(root()).filePath(project["lastOpenedTimeline"].toString());

    const QJsonArray& eventTypes = project["eventTypes"].toArray();
    for (auto it = eventTypes.begin(); it != eventTypes.end(); it++) {
        auto eventType = std::make_shared<EventType>();
        eventType->fromJSON(it->toObject());
        mEventTypes.push_back(eventType);
    }
}
Пример #12
0
RenderableProceduralItem::ProceduralInfo::ProceduralInfo(EntityItem* entity) : _entity(entity) {
    QJsonObject userData;
    {
        const QString& userDataJson = entity->getUserData();
        if (userDataJson.isEmpty()) {
            return;
        }
        QJsonParseError parseError;
        auto doc = QJsonDocument::fromJson(userDataJson.toUtf8(), &parseError);
        if (parseError.error != QJsonParseError::NoError) {
            return;
        }
        userData = doc.object();
    }

    // Example
    //{
    //    "ProceduralEntity": {
    //        "shaderUrl": "file:///C:/Users/bdavis/Git/hifi/examples/shaders/test.fs",
    //        "color" : "#FFFFFF"
    //    }
    //}

    auto proceduralData = userData[PROCEDURAL_USER_DATA_KEY];
    if (proceduralData.isNull()) {
        return;
    }
    auto proceduralDataObject = proceduralData.toObject();
    QString shaderUrl = proceduralDataObject["shaderUrl"].toString();
    _shaderUrl = QUrl(shaderUrl);
    if (!_shaderUrl.isValid()) {
        qWarning() << "Invalid shader URL: " << shaderUrl;
        return;
    }

    if (_shaderUrl.isLocalFile()) {
        _shaderPath = _shaderUrl.toLocalFile();
        qDebug() << "Shader path: " << _shaderPath;
        if (!QFile(_shaderPath).exists()) {
            return;
        }
    } else {
        qDebug() << "Shader url: " << _shaderUrl;
        _networkShader = ShaderCache::instance().getShader(_shaderUrl);
    }

    _enabled = true;
}
Пример #13
0
// extern (used by Global.cpp)
void
color_class_init(as_object& where, const ObjectURI& uri)
{
    as_object* cl = registerBuiltinClass(where, color_ctor,
            attachColorInterface, 0, uri);

    as_object* proto = toObject(
        getMember(*cl, NSV::PROP_PROTOTYPE), getVM(where));

    if (!proto) return;

    const int protect = as_object::DefaultFlags | PropFlags::readOnly;
    proto->set_member_flags(NSV::PROP_uuPROTOuu, protect); 
    proto->set_member_flags(NSV::PROP_CONSTRUCTOR, protect); 

}
Пример #14
0
bool Parameters::Deserialize(const QJsonObject &obj )
{
    Reset();
    bool ret = test::CommonParameters::Deserialize( obj );
    auto val = obj.value("hydro");
    if ( val.isObject() )
    {
        QJsonObject obj = val.toObject();
        mGsType = obj.value("GsType").toString();
        mVoltage =  obj.value("Voltage").toInt();
        mVoltageRange =  obj.value("VoltageRange").toDouble();
        mLost = obj.value("Lost").toDouble();
        mVoltageType = static_cast<VOLTAGE_TYPE>( obj.value("VoltageType").toInt() );
        mMaxWorkPressure  =  obj.value("MaxWorkPressure").toDouble();
        mMinTestPressure  =  obj.value("MinTestPressure").toDouble();
        mHermPressure =  obj.value("HermPressure").toDouble();
        mTestControlPressure =  obj.value("TestControlPressure").toDouble();
        mHermSignal  =  static_cast<CONTROL_SIGNAL>( obj.value("HermSignal").toDouble() );
        mPABTSignal  =  static_cast<CONTROL_SIGNAL>( obj.value("PABTSignal").toInt() );
        mPBATSignal  =  static_cast<CONTROL_SIGNAL>( obj.value("PBATSignal").toInt() );
        mActuationOnTime  =  obj.value("ActuationOnTime").toDouble();
        mActuationOffTime  =  obj.value("ActuationOffTime").toDouble();

        mOnDD1A     = obj.value("OnDD1A").toBool();
        mOnDD2A     = obj.value("OnDD2A").toBool();;
        mOnDD3A     = obj.value("OnDD3A").toBool();;
        mOffDD1A    = obj.value("OffDD1A").toBool();;
        mOffDD2A    = obj.value("OffDD2A").toBool();;
        mOffDD3A    = obj.value("OffDD3A").toBool();;
        mOnDD1B     = obj.value("OnDD1B").toBool();;
        mOnDD2B     = obj.value("OnDD2B").toBool();;
        mOnDD3B     = obj.value("OnDD3B").toBool();;
        mOffDD1B    = obj.value("OffDD1B").toBool();;
        mOffDD2B    = obj.value("OffDD2B").toBool();;
        mOffDD3B    = obj.value("OffDD3B").toBool();;

        mOnDynamic_1 = static_cast<DYNAMIC>( obj.value("OnDynamic_1").toInt() );
        mOffDynamic_1 = static_cast<DYNAMIC>( obj.value("OffDynamic_1").toInt() );
        mOnDynamic_2 = static_cast<DYNAMIC>( obj.value("OnDynamic_2").toInt() );
        mOffDynamic_2 = static_cast<DYNAMIC>( obj.value("OffDynamic_2").toInt() );
        ret = true;
    }
    else
        ret = false;

    return ret;
}
Пример #15
0
void MindMap::readFromData(QJsonObject& obj)
{
     clear();

    QJsonArray rootListJson = obj["roots"].toArray();

    for(auto it = rootListJson.begin(); it!=rootListJson.end(); ++it)
    {
        QJsonObject root = it->toObject();
        Node* node=new Node();
        addItem(node);
        node->readFromData(root);

        node->setPos(node->getX(),node->getY());
        m_roots.append(node);
    }
}
Пример #16
0
/// Construct an Array.
//
/// This uses the _global Array class to initialize the "constructor" and
/// "__proto__" properties. If Array.prototype is undefined, those properties
/// are not added.
as_object*
Global_as::createArray()
{
    as_object* array = new as_object(*this);

    as_value ctor = getMember(*this, NSV::CLASS_ARRAY);
    as_object* obj = toObject(ctor, gnash::getVM(*this));
    if (obj) {
        as_value proto;
        if (obj->get_member(NSV::PROP_PROTOTYPE, &proto)) {
            array->init_member(NSV::PROP_CONSTRUCTOR, ctor);
            array->set_prototype(getMember(*obj, NSV::PROP_PROTOTYPE));
        }
    }

    array->init_member(NSV::PROP_LENGTH, 0.0);
    array->setArray();
    return array;
}
Пример #17
0
bool Dictionary::getPropertyNames(Vector<String>& names) const {
  v8::Local<v8::Object> object;
  if (!toObject(object))
    return false;

  v8::Local<v8::Array> properties;
  if (!object->GetPropertyNames(v8Context()).ToLocal(&properties))
    return false;
  for (uint32_t i = 0; i < properties->Length(); ++i) {
    v8::Local<v8::String> key;
    if (!propertyKey(v8Context(), properties, i, key))
      continue;
    if (!v8CallBoolean(object->Has(v8Context(), key)))
      continue;
    TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false);
    names.append(stringKey);
  }

  return true;
}
Пример #18
0
JSValue* JSValue::getByIndex(ExecState* exec, unsigned propertyName) const
{
    switch (type()) {
    case StringType: {
        UString s = static_cast<const StringImp*>(asCell())->value();
        if (propertyName < static_cast<unsigned>(s.size())) {
            return jsString(s.substr(propertyName, 1));
        }
        // fall through
    }
    default: {
        JSObject* obj = toObject(exec);
        PropertySlot slot;
        if (obj->getPropertySlot(exec, propertyName, slot))
            return slot.getValue(exec, obj, propertyName);

        return jsUndefined();
    }
    }
}
Пример #19
0
static Variant HHVM_METHOD(Closure, call,
                           const Variant& newthis,
                           const Array& params) {
  if (newthis.isNull() || !newthis.isObject()) {
    raise_warning(
      "Closure::call() expects parameter 1 to be object, %s given",
      getDataTypeString(newthis.getType()).c_str()
    );
    return init_null_variant;
  }

  // So, with bind/bindTo, if we are trying to bind an instance to a static
  // closure, we just raise a warning and continue on. However, with call
  // we are supposed to just return null (according to the PHP 7 implementation)
  // Here is that speciality check, then. Do it here so we don't have to go
  // through the rigormorale of binding if this is the case.
  if (this_->getVMClass()->getCachedInvoke()->isStatic()) {
    raise_warning("Cannot bind an instance to a static closure");
    return init_null_variant;
  }

  auto bound = HHVM_MN(Closure, bindto)(this_, newthis, newthis);
  // If something went wrong in the binding (warning, for example), then
  // we can get an empty object back. And an empty object is null by
  // default. Return null if that is the case.
  if (bound.isNull()) {
    return init_null_variant;
  }

  // Could call vm_user_func(bound, params) here which goes through a
  // whole decode function process to get a Func*. But we know this
  // is a closure, and we can get a Func* via getInvokeFunc(), so just
  // bypass all that decode process to save time.
  return Variant::attach(
    g_context->invokeFunc(c_Closure::fromObject(this_)->getInvokeFunc(),
                          params, bound.toObject().get(),
                          nullptr, nullptr, nullptr,
                          ExecutionContext::InvokeCuf,
                          false, false)
  );
}
Пример #20
0
ZVariant ZVariant::operator[](const ZVariant &value) const
{
    switch (m_data->type) {
    case List: {
        bool ok = false;

        const ZVariant &val = toList().value(value.toInt(&ok));

        if(!ok)
            return ZVariant();
        else
            return val;
    }
    case Tuple: {
        bool ok;

        const ZVariant &val = *toTuple().value(value.toInt(&ok));

        if(!ok)
            return ZVariant();
        else
            return val;
    }
    case String: {
        bool ok;

        int index = value.toInt(&ok);
        const QString &str = toString();

        if(!ok || index >= str.size())
            return QString();
        else
            return QString(str.at(index));
    }
    case Function:
    case Object:
        return toObject()->property(value.toString().toLatin1().constData());
    default:
        return Undefined;
    }
}
Пример #21
0
RMProject::RMProject(const QJsonValueRef& json, RedMineManager* manager, QObject* parent): 
    QObject(parent),
    m_manager(manager)
{
    assert(json.isObject());
    
    QJsonObject obj = json.toObject();
    
    m_id = obj.value("id").toDouble();
    m_createdOn = jsonDate(obj.value("created_on").toString());
    m_updatedOn = jsonDate(obj.value("updated_on").toString());
    m_identifier = obj.value("identifier").toString();
    m_name = obj.value("name").toString();
    m_description = obj.value("description").toString();
    
    auto parentProj = obj.value("parent");
    if (parentProj.isObject())
    {
        m_parentProjectId = parentProj.toObject().value("id").toDouble();
    }
}
Пример #22
0
bool ZVariant::toBool() const
{
    switch(m_data->type) {
    case Int:
        return m_data->variant.toInt();
    case Double:
        return (int)m_data->variant.toDouble();
    case Bool:
        return m_data->variant.toBool();
    case String:
        return !m_data->variant.toString().isEmpty();
    case Object:
    case Function:
        return (bool)toObject();
    case Undefined:
        return false;
    default: break;
    }

    return m_data->variant.toBool();
}
Пример #23
0
std::vector<CRHInfo>
CRestWorker::get_ssh_containers(int &http_code,
                                int &err_code,
                                int &network_error) {
  QJsonDocument doc = get_request_json_document("containers", http_code, err_code, network_error);
  if (err_code != 0) return std::vector<CRHInfo>();

  if (!doc.isArray()) {
    err_code = RE_NOT_JSON_OBJECT;
    return std::vector<CRHInfo>();
  }

  std::vector<CRHInfo> lst_res;
  QJsonArray arr = doc.array();

  for (auto i = arr.begin(); i != arr.end(); ++i) {
    if (i->isNull() || !i->isObject()) continue;
    lst_res.push_back(CRHInfo(i->toObject()));
  }
  return lst_res;
}
Пример #24
0
bool Parser::parseStations(QByteArray &data, QMap<QString,QString> &stations)
{
    CreateJsonFileForTest(data,"test_StationReply.json");

    QJsonDocument responce;
    responce = QJsonDocument::fromJson(data);
    if (responce.isObject()) {
        QJsonObject jsonobject = responce.object();
         QJsonArray jsonStations = jsonobject["value"].toArray();
         QJsonObject station;
         for(auto it2 = jsonStations.begin();it2 != jsonStations.end();++it2)
         {
             station = it2->toObject();
             stations.insert(station["title"].toString(), station["station_id"].toString());
             //stations.insert(station["title"].toString(), QString::number(station["station_id"].toInt()));
            // qDebug()<<"-- :  "<< station["title"].toString()<<" "<<station["station_id"].toString();
         }
        return true;
    }
    return false;
}
Пример #25
0
void HeadData::fromJson(const QJsonObject& json) {
    if (json.contains(JSON_AVATAR_HEAD_BLENDSHAPE_COEFFICIENTS)) {
        auto jsonValue = json[JSON_AVATAR_HEAD_BLENDSHAPE_COEFFICIENTS];
        if (jsonValue.isArray()) {
            QVector<float> blendshapeCoefficients;
            QJsonArray blendshapeCoefficientsJson = jsonValue.toArray();
            for (const auto& blendshapeCoefficient : blendshapeCoefficientsJson) {
                blendshapeCoefficients.push_back((float)blendshapeCoefficient.toDouble());
                setBlendshapeCoefficients(blendshapeCoefficients);
            }
        } else if (jsonValue.isObject()) {
            QJsonObject blendshapeCoefficientsJson = jsonValue.toObject();
            for (const QString& name : blendshapeCoefficientsJson.keys()) {
                float value = (float)blendshapeCoefficientsJson[name].toDouble();
                setBlendshape(name, value);
            }
        } else {
            qWarning() << "Unable to deserialize head json: " << jsonValue;
        }
    }

    if (json.contains(JSON_AVATAR_HEAD_ROTATION)) {
        setOrientation(quatFromJsonValue(json[JSON_AVATAR_HEAD_ROTATION]));
    }
    if (json.contains(JSON_AVATAR_HEAD_LEAN_FORWARD)) {
        setLeanForward((float)json[JSON_AVATAR_HEAD_LEAN_FORWARD].toDouble());
    }
    if (json.contains(JSON_AVATAR_HEAD_LEAN_SIDEWAYS)) {
        setLeanSideways((float)json[JSON_AVATAR_HEAD_LEAN_SIDEWAYS].toDouble());
    }

    if (json.contains(JSON_AVATAR_HEAD_LOOKAT)) {
        auto relativeLookAt = vec3FromJsonValue(json[JSON_AVATAR_HEAD_LOOKAT]);
        if (glm::length2(relativeLookAt) > 0.01f) {
            setLookAtPosition((_owningAvatar->getOrientation() * relativeLookAt) + _owningAvatar->getPosition());
        }
    }
}
Пример #26
0
void LoginDialog::signupFailed(QNetworkReply& reply) {

    // parse the returned JSON to see what the problem was
    auto jsonResponse = QJsonDocument::fromJson(reply.readAll());

    static const QString RESPONSE_DATA_KEY = "data";

    auto dataJsonValue = jsonResponse.object()[RESPONSE_DATA_KEY];

    if (dataJsonValue.isObject()) {
        auto dataObject = dataJsonValue.toObject();

        static const QString EMAIL_DATA_KEY = "email";
        static const QString USERNAME_DATA_KEY = "username";
        static const QString PASSWORD_DATA_KEY = "password";

        QStringList errorStringList;

        if (dataObject.contains(EMAIL_DATA_KEY)) {
            errorStringList.append(QString("Email %1.").arg(errorStringFromAPIObject(dataObject[EMAIL_DATA_KEY])));
        }

        if (dataObject.contains(USERNAME_DATA_KEY)) {
            errorStringList.append(QString("Username %1.").arg(errorStringFromAPIObject(dataObject[USERNAME_DATA_KEY])));
        }

        if (dataObject.contains(PASSWORD_DATA_KEY)) {
            errorStringList.append(QString("Password %1.").arg(errorStringFromAPIObject(dataObject[PASSWORD_DATA_KEY])));
        }

        emit handleSignupFailed(errorStringList.join('\n'));
    } else {
        static const QString DEFAULT_SIGN_UP_FAILURE_MESSAGE = "There was an unknown error while creating your account. Please try again later.";
        emit handleSignupFailed(DEFAULT_SIGN_UP_FAILURE_MESSAGE);
    }


}
Пример #27
0
//=================================================================================
ModifyObjectCmd::ModifyObjectCmd(QJsonObject oldData, QJsonObject newData, ObjectItem* item, Modifications mod, QUndoCommand* parent)
    : QUndoCommand(parent),
      m_oldData(oldData),
      m_newData(oldData), // Set newData to oldData for the time being, update it later with the newData
      m_item(item),
      m_mod(mod)
{
    // Overwrite the old data with the new data if available
    for (auto it = newData.constBegin(); it != newData.constEnd(); ++it)
    {
        if (it->isDouble()) m_newData[it.key()] = it->toDouble(); // This includes integers
        else if (it->isObject()) m_newData[it.key()] = it->toObject();
        else if (it->isArray()) m_newData[it.key()] = it->toArray();
        else if (it->isString()) m_newData[it.key()] = it->toString();
        else if (it->isBool()) m_newData[it.key()] = it->toBool();
    }

    // Set the type of modification for the data
    m_oldData["modifications"] = static_cast<int>(mod);
    m_newData["modifications"] = static_cast<int>(mod);

    setText(QObject::tr(qPrintable("Modify " + newData["type"].toString() + " " + newData["name"].toString())));
}
Пример #28
0
UString UserObjectImp::toString(ExecState *exec) const
{
    UString result;
    JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec), exec);
    CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : 0;
    if (cfValue)
    {
        CFTypeID cfType = CFGetTypeID(cfValue);
        if (cfValue == GetCFNull())
        {
            //
        }
        else if (cfType == CFBooleanGetTypeID())
        {
            if (cfValue == kCFBooleanTrue)
            {
                result = "true";
            }
            else
            {
                result = "false";
            }
        }
        else if (cfType == CFStringGetTypeID())
        {
            result = CFStringToUString((CFStringRef)cfValue);
        }
        else if (cfType == CFNumberGetTypeID())
        {
            if (cfValue == kCFNumberNaN)
            {
                result = "Nan";
            }
            else if (CFNumberCompare(kCFNumberPositiveInfinity, (CFNumberRef)cfValue, 0) == 0)
            {
                result = "Infinity";
            }
            else if (CFNumberCompare(kCFNumberNegativeInfinity, (CFNumberRef)cfValue, 0) == 0)
            {
                result = "-Infinity";
            }
            else
            {
                CFStringRef cfNumStr;
                double d = 0;
                CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d);
                if (CFNumberIsFloatType((CFNumberRef)cfValue))
                {
                    cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%f"), d);
                }
                else
                {
                    cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%.0f"), d);
                }
                result = CFStringToUString(cfNumStr);
                ReleaseCFType(cfNumStr);
            }
        }
        else if (cfType == CFArrayGetTypeID())
        {
            //
        }
        else if (cfType == CFDictionaryGetTypeID())
        {
            //
        }
        else if (cfType == CFSetGetTypeID())
        {
            //
        }
        else if (cfType == CFURLGetTypeID())
        {
            CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue);
            if (absURL)
            {
                CFStringRef cfStr = CFURLGetString(absURL);
                if (cfStr)
                {
                    result = CFStringToUString(cfStr);
                }
                ReleaseCFType(absURL);
            }
        }
    }
    ReleaseCFType(cfValue);
    if (jsObjPtr) jsObjPtr->Release();
    return result;
}
Пример #29
0
bool UserObjectImp::toBoolean(ExecState *exec) const
{
    bool result = false;
    JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec), exec);
    CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : 0;
    if (cfValue)
    {
        CFTypeID cfType = CFGetTypeID(cfValue);  // toPrimitive
        if (cfValue == GetCFNull())
        {
            //
        }
        else if (cfType == CFBooleanGetTypeID())
        {
            if (cfValue == kCFBooleanTrue)
            {
                result = true;
            }
        }
        else if (cfType == CFStringGetTypeID())
        {
            if (CFStringGetLength((CFStringRef)cfValue))
            {
                result = true;
            }
        }
        else if (cfType == CFNumberGetTypeID())
        {
            if (cfValue != kCFNumberNaN)
            {
                double d;
                if (CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d))
                {
                    if (d != 0)
                    {
                        result = true;
                    }
                }
            }
        }
        else if (cfType == CFArrayGetTypeID())
        {
            if (CFArrayGetCount((CFArrayRef)cfValue))
            {
                result = true;
            }
        }
        else if (cfType == CFDictionaryGetTypeID())
        {
            if (CFDictionaryGetCount((CFDictionaryRef)cfValue))
            {
                result = true;
            }
        }
        else if (cfType == CFSetGetTypeID())
        {
            if (CFSetGetCount((CFSetRef)cfValue))
            {
                result = true;
            }
        }
        else if (cfType == CFURLGetTypeID())
        {
            CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue);
            if (absURL)
            {
                CFStringRef cfStr = CFURLGetString(absURL);
                if (cfStr && CFStringGetLength(cfStr))
                {
                    result = true;
                }
                ReleaseCFType(absURL);
            }
        }
    }
    if (jsObjPtr) jsObjPtr->Release();
    ReleaseCFType(cfValue);
    return result;
}
Пример #30
0
AJObject* AJCell::toThisObject(ExecState* exec) const
{
    return toObject(exec);
}