Ejemplo n.º 1
0
nsresult
KeyPath::ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue,
                            Key& aKey, ExtractOrCreateKeyCallback aCallback,
                            void* aClosure) const
{
    NS_ASSERTION(IsString(), "This doesn't make sense!");

    JS::Rooted<JS::Value> value(aCx);

    aKey.Unset();

    nsresult rv = GetJSValFromKeyPathString(aCx, aValue, mStrings[0],
                                            value.address(),
                                            CreateProperties, aCallback,
                                            aClosure);
    if (NS_FAILED(rv)) {
        return rv;
    }

    if (NS_FAILED(aKey.AppendItem(aCx, false, value))) {
        NS_ASSERTION(aKey.IsUnset(), "Should be unset");
        return value.isUndefined() ? NS_OK : NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
    }

    aKey.FinishArray();

    return NS_OK;
}
Ejemplo n.º 2
0
nsresult
KeyPath::ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const
{
    uint32_t len = mStrings.Length();
    JS::Rooted<JS::Value> value(aCx);

    aKey.Unset();

    for (uint32_t i = 0; i < len; ++i) {
        nsresult rv = GetJSValFromKeyPathString(aCx, aValue, mStrings[i],
                                                value.address(),
                                                DoNotCreateProperties, nullptr,
                                                nullptr);
        if (NS_FAILED(rv)) {
            return rv;
        }

        if (NS_FAILED(aKey.AppendItem(aCx, IsArray() && i == 0, value))) {
            NS_ASSERTION(aKey.IsUnset(), "Encoding error should unset");
            return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
        }
    }

    aKey.FinishArray();

    return NS_OK;
}