Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 775791 | Differences between
and this patch

Collapse All | Expand All

(-)Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h (-2 / +68 lines)
Lines 28-33 Link Here
28
#include "JSArrayBufferView.h"
28
#include "JSArrayBufferView.h"
29
#include "ThrowScope.h"
29
#include "ThrowScope.h"
30
#include "ToNativeFromValue.h"
30
#include "ToNativeFromValue.h"
31
#include <wtf/FlipBytes.h>
31
32
32
namespace JSC {
33
namespace JSC {
33
34
Lines 146-152 public: Link Here
146
    
147
    
147
    JSValue getIndexQuickly(unsigned i) const
148
    JSValue getIndexQuickly(unsigned i) const
148
    {
149
    {
150
#if CPU(BIG_ENDIAN)
151
        switch (Adaptor::typeValue) {
152
        case TypeFloat32:
153
        case TypeFloat64:
154
            return Adaptor::toJSValue(nullptr, getIndexQuicklyAsNativeValue(i));
155
        default:
156
            // typed array views are commonly expected to be little endian views of the underlying data
157
            return Adaptor::toJSValue(nullptr, flipBytes(getIndexQuicklyAsNativeValue(i)));
158
        }
159
#else
149
        return Adaptor::toJSValue(nullptr, getIndexQuicklyAsNativeValue(i));
160
        return Adaptor::toJSValue(nullptr, getIndexQuicklyAsNativeValue(i));
161
#endif
150
    }
162
    }
151
    
163
    
152
    void setIndexQuicklyToNativeValue(unsigned i, typename Adaptor::Type value)
164
    void setIndexQuicklyToNativeValue(unsigned i, typename Adaptor::Type value)
Lines 158-164 public: Link Here
158
    void setIndexQuickly(unsigned i, JSValue value)
170
    void setIndexQuickly(unsigned i, JSValue value)
159
    {
171
    {
160
        ASSERT(!value.isObject());
172
        ASSERT(!value.isObject());
173
#if CPU(BIG_ENDIAN)
174
        switch (Adaptor::typeValue) {
175
        case TypeFloat32:
176
        case TypeFloat64:
177
            setIndexQuicklyToNativeValue(i, toNativeFromValue<Adaptor>(value));
178
            break;
179
        default:
180
            // typed array views are commonly expected to be little endian views of the underlying data
181
            setIndexQuicklyToNativeValue(i, flipBytes(toNativeFromValue<Adaptor>(value)));
182
            break;
183
        }
184
#else
161
        setIndexQuicklyToNativeValue(i, toNativeFromValue<Adaptor>(value));
185
        setIndexQuicklyToNativeValue(i, toNativeFromValue<Adaptor>(value));
186
#endif
162
    }
187
    }
163
    
188
    
164
    bool setIndex(JSGlobalObject* globalObject, unsigned i, JSValue jsValue)
189
    bool setIndex(JSGlobalObject* globalObject, unsigned i, JSValue jsValue)
Lines 172-184 public: Link Here
172
        if (isDetached() || i >= m_length)
197
        if (isDetached() || i >= m_length)
173
            return false;
198
            return false;
174
199
200
#if CPU(BIG_ENDIAN)
201
        switch (Adaptor::typeValue) {
202
        case TypeFloat32:
203
        case TypeFloat64:
204
            setIndexQuicklyToNativeValue(i, value);
205
            break;
206
        default:
207
            // typed array views are commonly expected to be little endian views of the underlying data
208
            setIndexQuicklyToNativeValue(i, flipBytes(value));
209
            break;
210
        }
211
#else
175
        setIndexQuicklyToNativeValue(i, value);
212
        setIndexQuicklyToNativeValue(i, value);
213
#endif
176
        return true;
214
        return true;
177
    }
215
    }
178
216
179
    static ElementType toAdaptorNativeFromValue(JSGlobalObject* globalObject, JSValue jsValue) { return toNativeFromValue<Adaptor>(globalObject, jsValue); }
217
    static ElementType toAdaptorNativeFromValue(JSGlobalObject* globalObject, JSValue jsValue)
218
    {
219
#if CPU(BIG_ENDIAN)
220
        switch (Adaptor::typeValue) {
221
        case TypeFloat32:
222
        case TypeFloat64:
223
            return toNativeFromValue<Adaptor>(globalObject, jsValue);
224
        default:
225
            // typed array views are commonly expected to be little endian views of the underlying data
226
            return flipBytes(toNativeFromValue<Adaptor>(globalObject, jsValue));
227
        }
228
#else
229
        return toNativeFromValue<Adaptor>(globalObject, jsValue);
230
#endif
231
    }
180
232
181
    static Optional<ElementType> toAdaptorNativeFromValueWithoutCoercion(JSValue jsValue) { return toNativeFromValueWithoutCoercion<Adaptor>(jsValue); }
233
    static Optional<ElementType> toAdaptorNativeFromValueWithoutCoercion(JSValue jsValue)
234
    {
235
#if CPU(BIG_ENDIAN)
236
        switch (Adaptor::typeValue) {
237
        case TypeFloat32:
238
        case TypeFloat64:
239
            return toNativeFromValueWithoutCoercion<Adaptor>(jsValue);
240
        default:
241
            // typed array views are commonly expected to be little endian views of the underlying data
242
            return flipBytes(toNativeFromValueWithoutCoercion<Adaptor>(jsValue));
243
        }
244
#else
245
        return toNativeFromValueWithoutCoercion<Adaptor>(jsValue);
246
#endif
247
    }
182
248
183
    void sort()
249
    void sort()
184
    {
250
    {
(-)Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h (-2 / +29 lines)
Lines 208-216 ALWAYS_INLINE EncodedJSValue genericTypedArrayViewProtoFuncIncludes(VM& vm, JSGl Link Here
208
    scope.assertNoException();
208
    scope.assertNoException();
209
    RELEASE_ASSERT(!thisObject->isDetached());
209
    RELEASE_ASSERT(!thisObject->isDetached());
210
210
211
    if (std::isnan(static_cast<double>(*targetOption))) {
211
    double targetOptionLittleEndianAsDouble;
212
#if CPU(BIG_ENDIAN)
213
    switch (ViewClass::TypedArrayStorageType) {
214
    case TypeFloat32:
215
    case TypeFloat64:
216
        targetOptionLittleEndianAsDouble = static_cast<double>(*targetOption);
217
    default:
218
        // typed array views are commonly expected to be little endian views of the underlying data
219
        targetOptionLittleEndianAsDouble = static_cast<double>(flipBytes(*targetOption));
220
    }
221
#else
222
    targetOptionLittleEndianAsDouble = static_cast<double>(*targetOption);
223
#endif
224
225
    if (std::isnan(targetOptionLittleEndianAsDouble)) {
212
        for (; index < length; ++index) {
226
        for (; index < length; ++index) {
213
            if (std::isnan(static_cast<double>(array[index])))
227
            double arrayElementLittleEndianAsDouble;
228
#if CPU(BIG_ENDIAN)
229
            switch (ViewClass::TypedArrayStorageType) {
230
            case TypeFloat32:
231
            case TypeFloat64:
232
                arrayElementLittleEndianAsDouble = static_cast<double>(array[index]);
233
            default:
234
                // typed array views are commonly expected to be little endian views of the underlying data
235
                arrayElementLittleEndianAsDouble = static_cast<double>(flipBytes(array[index]));
236
            }
237
#else
238
            arrayElementLittleEndianAsDouble = static_cast<double>(array[index]);
239
#endif
240
            if (std::isnan(arrayElementLittleEndianAsDouble))
214
                return JSValue::encode(jsBoolean(true));
241
                return JSValue::encode(jsBoolean(true));
215
        }
242
        }
216
    } else {
243
    } else {
(-)Source/WTF/wtf/FlipBytes.h (+37 lines)
Lines 24-29 Link Here
24
 */
24
 */
25
25
26
#pragma once
26
#pragma once
27
#include "Optional.h"
27
28
28
namespace WTF {
29
namespace WTF {
29
30
Lines 98-103 inline T flipBytes(T value) Link Here
98
    return T();
99
    return T();
99
}
100
}
100
101
102
template<typename T>
103
inline T flipBytes(WTF::Optional<T> value)
104
{
105
    if (sizeof(*value) == 1)
106
        return *value;
107
    if (sizeof(*value) == 2) {
108
        union {
109
            T original;
110
            uint16_t word;
111
        } u;
112
        u.original = *value;
113
        u.word = flipBytes(u.word);
114
        return u.original;
115
    }
116
    if (sizeof(*value) == 4) {
117
        union {
118
            T original;
119
            uint32_t word;
120
        } u;
121
        u.original = *value;
122
        u.word = flipBytes(u.word);
123
        return u.original;
124
    }
125
    if (sizeof(*value) == 8) {
126
        union {
127
            T original;
128
            uint64_t word;
129
        } u;
130
        u.original = *value;
131
        u.word = flipBytes(u.word);
132
        return u.original;
133
    }
134
    RELEASE_ASSERT_NOT_REACHED();
135
    return T();
136
}
137
101
template<typename T>
138
template<typename T>
102
inline T flipBytesIfLittleEndian(T value, bool littleEndian)
139
inline T flipBytesIfLittleEndian(T value, bool littleEndian)
103
{
140
{

Return to bug 775791