예제 #1
0
static inline void putByVal(ExecState* exec, JSValue baseValue, uint32_t index, JSValue value)
{
    JSGlobalData* globalData = &exec->globalData();

    if (isJSArray(baseValue)) {
        JSArray* array = asArray(baseValue);
        if (array->canSetIndex(index)) {
            array->setIndex(*globalData, index, value);
            return;
        }

        JSArray::putByIndex(array, exec, index, value, strict);
        return;
    }

    if (isJSByteArray(baseValue) && asByteArray(baseValue)->canAccessIndex(index)) {
        JSByteArray* byteArray = asByteArray(baseValue);
        // FIXME: the JITstub used to relink this to an optimized form!
        if (value.isInt32()) {
            byteArray->setIndex(index, value.asInt32());
            return;
        }

        if (value.isNumber()) {
            byteArray->setIndex(index, value.asNumber());
            return;
        }
    }

    baseValue.putByIndex(exec, index, value, strict);
}
예제 #2
0
ALWAYS_INLINE static void operationPutByValInternal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
{
    JSGlobalData* globalData = &exec->globalData();

    JSValue baseValue = JSValue::decode(encodedBase);
    JSValue property = JSValue::decode(encodedProperty);
    JSValue value = JSValue::decode(encodedValue);

    if (LIKELY(property.isUInt32())) {
        uint32_t i = property.asUInt32();

        if (isJSArray(globalData, baseValue)) {
            JSArray* jsArray = asArray(baseValue);
            if (jsArray->canSetIndex(i)) {
                jsArray->setIndex(*globalData, i, value);
                return;
            }

            jsArray->JSArray::put(exec, i, value);
            return;
        }

        if (isJSByteArray(globalData, baseValue) && asByteArray(baseValue)->canAccessIndex(i)) {
            JSByteArray* jsByteArray = asByteArray(baseValue);
            // FIXME: the JITstub used to relink this to an optimized form!
            if (value.isInt32()) {
                jsByteArray->setIndex(i, value.asInt32());
                return;
            }

            double dValue = 0;
            if (value.getNumber(dValue)) {
                jsByteArray->setIndex(i, dValue);
                return;
            }
        }

        baseValue.put(exec, i, value);
        return;
    }

    // Don't put to an object if toString throws an exception.
    Identifier ident(exec, property.toString(exec));
    if (!globalData->exception) {
        PutPropertySlot slot(strict);
        baseValue.put(exec, ident, value, slot);
    }
}