示例#1
0
UString JSObject::toString(ExecState* exec) const
{
    JSValue primitive = toPrimitive(exec, PreferString);
    if (exec->hadException())
        return "";
    return primitive.toString(exec);
}
示例#2
0
double JSObject::toNumber(ExecState* exec) const
{
    JSValue primitive = toPrimitive(exec, PreferNumber);
    if (exec->hadException()) // should be picked up soon in Nodes.cpp
        return 0.0;
    return primitive.toNumber(exec);
}
示例#3
0
UString JSObject::toString(ExecState *exec) const
{
  JSValue *prim = toPrimitive(exec,StringType);
  if (exec->hadException()) // should be picked up soon in nodes.cpp
    return UString(UString::empty);
  return prim->toString(exec);
}
示例#4
0
double JSObject::toNumber(ExecState *exec) const
{
  JSValue *prim = toPrimitive(exec,NumberType);
  if (exec->hadException()) // should be picked up soon in nodes.cpp
    return 0.0;
  return prim->toNumber(exec);
}
bool UserObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
{
    if (!fJSUserObject)
        return false;

    CFStringRef cfPropName = IdentifierToCFString(propertyName);
    JSUserObject *jsResult = fJSUserObject->CopyProperty(cfPropName);
    ReleaseCFType(cfPropName);
    if (jsResult) {
        slot.setCustom(this, userObjectGetter);
        jsResult->Release();
        return true;
    } else {
        JSValue *kjsValue = toPrimitive(exec);
        if (kjsValue->type() != NullType && kjsValue->type() != UndefinedType) {
            JSObject *kjsObject = kjsValue->toObject(exec);
            if (kjsObject->getPropertySlot(exec, propertyName, slot))
                return true;
        }
    }
    return JSObject::getOwnPropertySlot(exec, propertyName, slot);
}
示例#6
0
bool compare::relation(var& x, var& y) {

  // 1. If the LeftFirst flag is true, then
  // 1. Let px be the result of calling ToPrimitive(x, hint Number).
  // 2. Let py be the result of calling ToPrimitive(y, hint Number).
  // 2. Else the order of evaluation needs to be reversed to preserve left to right evaluation
  // 1. Let py be the result of calling ToPrimitive(y, hint Number).
  // 2. Let px be the result of calling ToPrimitive(x, hint Number).

  // NOTE: The order of evaluation shouldn't matter in this case; don't use LeftFirst.

  var px = toPrimitive(x);
  var py = toPrimitive(y);

  // 3. If it is not the case that both Type(px) is String and Type(py) is String, then
  if (!(px.isString() && py.isString())) {

    // 1. Let nx be the result of calling ToNumber(px). 
    //    Because px and py are primitive values evaluation order is not important.
    number nx = px;

    // 2. Let ny be the result of calling ToNumber(py).
    number ny = py;

    // 3. If nx is NaN, return undefined.
    // 4. If ny is NaN, return undefined.

    // TODO: NaN checks?

    // 5. If nx and ny are the same Number value, return false.
    if (nx == ny)
      return false;

    // 6. If nx is +0 and ny is −0, return false.
    if (nx == +0 && ny == -0)
      return false;

    // 7. If nx is −0 and ny is +0, return false.
    if (nx == -0 && ny == +0)
      return false;

    // 8. If nx is +∞, return false.
    // 9. If ny is +∞, return true.
    // 10. If ny is −∞, return false.
    // 11. If nx is −∞, return true.

    // TODO: infinity checks?

    // 12. If the mathematical value of nx is less than the mathematical value of ny 
    //     —note that these mathematical values are both finite and not both zero—return true. Otherwise, return false.

    return nx < ny;

  } else {
    // 4. Else, both px and py are Strings
    // 1. If py is a prefix of px, return false. (A String value p is a prefix of String value q ifq can be the result of concatenating p and some other String r. Note that any String is a prefix of itself, because r may be the empty String.)
    // 2. If px is a prefix of py, return true.
    // 3. Let k be the smallest nonnegative integer such that the character at position kwithin px is different from the character at position k within py. (There must be such a k, for neither String is a prefix of the other.)
    // 4. Let m be the integer that is the code unit value for the character at position kwithin px.
    // 5. Let n be the integer that is the code unit value for the character at position kwithin py.
    // 6. If m < n, return true. Otherwise, return false.

    // NOTE: Should be close enough to std::string behavior.

    return (string) px < (string) py;

  }
}
示例#7
0
DataInformation* toDataInformation(const QScriptValue& value, const ParserInfo& oldInfo)
{
    if (!value.isValid())
    {
        oldInfo.error() << "invalid value passed!";
        return 0;
    }
    ParserInfo info(oldInfo);
    QString nameOverride = value.property(PROPERTY_NAME).toString();
    if (!nameOverride.isEmpty())
        info.name = nameOverride;

    //check function array and date, since they are objects too
    if (value.isRegExp())
    {
        //apparently regexp is a function
        info.error() << "Cannot convert a RegExp object to DataInformation!";
        return 0;
    }
    if (value.isFunction())
    {
        info.error() << "Cannot convert a Function object to DataInformation!";
        return 0;
    }
    if (value.isArray())
    {
        info.error() << "Cannot convert a Array object to DataInformation!";
        return 0;
    }
    if (value.isDate())
    {
        info.error() << "Cannot convert a Date object to DataInformation!";
        return 0;
    }
    if (value.isError())
    {
        info.error() << "Cannot convert a Error object to DataInformation!";
        return 0;
    }
    //variant and qobject are also object types, however they cannot appear from user code, no need to check

    //if it is a string, we convert to primitive type, if not it has to be an object
    if (value.isString())
        return toPrimitive(value, info); //a type string is also okay

    if (!value.isObject())
    {
        if (value.isBool())
            info.error() << "Cannot convert Boolean to DataInformation!";
        else if (value.isNull())
            info.error() << "Cannot convert null to DataInformation!";
        else if (value.isUndefined())
            info.error() << "Cannot convert undefined to DataInformation!";
        else if (value.isNumber())
            info.error() << "Cannot convert Number to DataInformation!";
        else
            info.error() << "Cannot convert object of unknown type to DataInformation!";

        return 0; //no point trying to convert
    }

    QString type = value.property(PROPERTY_INTERNAL_TYPE).toString();
    if (type.isEmpty())
    {
        info.error() << "Cannot convert object since type of object could not be determined!";
        return 0;
    }
    DataInformation* returnVal = 0;

    if (type == TYPE_ARRAY)
        returnVal = toArray(value, info);

    else if (type == TYPE_STRUCT)
        returnVal = toStruct(value, info);

    else if (type == TYPE_UNION)
        returnVal = toUnion(value, info);

    else if (type == TYPE_BITFIELD)
        returnVal = toBitfield(value, info);

    else if (type == TYPE_ENUM)
        returnVal = toEnum(value, false, info);

    else if (type == TYPE_FLAGS)
        returnVal = toEnum(value, true, info);

    else if (type == TYPE_STRING)
        returnVal = toString(value, info);

    else if (type == TYPE_POINTER)
        returnVal = toPointer(value, info);

    else if (type == TYPE_TAGGED_UNION)
        returnVal = toTaggedUnion(value, info);

    else if (type == TYPE_PRIMITIVE)
        returnVal = toPrimitive(value, info);

    else
        info.error() << "Unknown type:" << type;

    if (returnVal)
    {
        CommonParsedData cpd(info);
        QString byteOrderStr = value.property(PROPERTY_BYTEORDER).toString();
        if (!byteOrderStr.isEmpty())
            cpd.endianess = ParserUtils::byteOrderFromString(byteOrderStr,
                    LoggerWithContext(info.logger, info.context()));
        cpd.updateFunc = value.property(PROPERTY_UPDATE_FUNC);
        cpd.validationFunc = value.property(PROPERTY_VALIDATION_FUNC);
        cpd.toStringFunc = value.property(PROPERTY_TO_STRING_FUNC);
        cpd.customTypeName = value.property(PROPERTY_CUSTOM_TYPE_NAME).toString();
        if (!DataInformationFactory::commonInitialization(returnVal, cpd))
        {
            delete returnVal; //error message has already been logged
            return 0;
        }
    }
    return returnVal;
}