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

(-)file_not_specified_in_diff (-7 / +137 lines)
Line  Link Here
0
-- a/Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h
0
++ b/Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h
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 147-153 public: Link Here
147
    
148
    
148
    JSValue getIndexQuickly(unsigned i) const
149
    JSValue getIndexQuickly(unsigned i) const
149
    {
150
    {
151
#if CPU(BIG_ENDIAN)
152
        switch (Adaptor::typeValue) {
153
        case TypeFloat32:
154
        case TypeFloat64:
155
            return Adaptor::toJSValue(getIndexQuicklyAsNativeValue(i));
156
        default:
157
            // typed array views are commonly expected to be little endian views of the underlying data
158
            return Adaptor::toJSValue(flipBytes(getIndexQuicklyAsNativeValue(i)));
159
        }
160
#else
150
        return Adaptor::toJSValue(getIndexQuicklyAsNativeValue(i));
161
        return Adaptor::toJSValue(getIndexQuicklyAsNativeValue(i));
162
#endif
151
    }
163
    }
152
    
164
    
153
    void setIndexQuicklyToNativeValue(unsigned i, typename Adaptor::Type value)
165
    void setIndexQuicklyToNativeValue(unsigned i, typename Adaptor::Type value)
Lines 164-170 public: Link Here
164
    void setIndexQuickly(unsigned i, JSValue value)
176
    void setIndexQuickly(unsigned i, JSValue value)
165
    {
177
    {
166
        ASSERT(!value.isObject());
178
        ASSERT(!value.isObject());
179
#if CPU(BIG_ENDIAN)
180
        switch (Adaptor::typeValue) {
181
        case TypeFloat32:
182
        case TypeFloat64:
183
            setIndexQuicklyToNativeValue(i, toNativeFromValue<Adaptor>(value));
184
            break;
185
        default:
186
            // typed array views are commonly expected to be little endian views of the underlying data
187
            setIndexQuicklyToNativeValue(i, flipBytes(toNativeFromValue<Adaptor>(value)));
188
            break;
189
        }
190
#else
167
        setIndexQuicklyToNativeValue(i, toNativeFromValue<Adaptor>(value));
191
        setIndexQuicklyToNativeValue(i, toNativeFromValue<Adaptor>(value));
192
#endif
168
    }
193
    }
169
    
194
    
170
    bool setIndex(JSGlobalObject* globalObject, unsigned i, JSValue jsValue)
195
    bool setIndex(JSGlobalObject* globalObject, unsigned i, JSValue jsValue)
Lines 183-195 public: Link Here
183
        if (i >= m_length)
208
        if (i >= m_length)
184
            return false;
209
            return false;
185
210
211
#if CPU(BIG_ENDIAN)
212
        switch (Adaptor::typeValue) {
213
        case TypeFloat32:
214
        case TypeFloat64:
215
            setIndexQuicklyToNativeValue(i, value);
216
            break;
217
        default:
218
            // typed array views are commonly expected to be little endian views of the underlying data
219
            setIndexQuicklyToNativeValue(i, flipBytes(value));
220
            break;
221
        }
222
#else
186
        setIndexQuicklyToNativeValue(i, value);
223
        setIndexQuicklyToNativeValue(i, value);
224
#endif
187
        return true;
225
        return true;
188
    }
226
    }
189
227
190
    static ElementType toAdaptorNativeFromValue(JSGlobalObject* globalObject, JSValue jsValue) { return toNativeFromValue<Adaptor>(globalObject, jsValue); }
228
    static ElementType toAdaptorNativeFromValue(JSGlobalObject* globalObject, JSValue jsValue)
229
    {
230
#if CPU(BIG_ENDIAN)
231
        switch (Adaptor::typeValue) {
232
        case TypeFloat32:
233
        case TypeFloat64:
234
            return toNativeFromValue<Adaptor>(globalObject, jsValue);
235
        default:
236
            // typed array views are commonly expected to be little endian views of the underlying data
237
            return flipBytes(toNativeFromValue<Adaptor>(globalObject, jsValue));
238
        }
239
#else
240
        return toNativeFromValue<Adaptor>(globalObject, jsValue);
241
#endif
242
    }
191
243
192
    static Optional<ElementType> toAdaptorNativeFromValueWithoutCoercion(JSValue jsValue) { return toNativeFromValueWithoutCoercion<Adaptor>(jsValue); }
244
    static Optional<ElementType> toAdaptorNativeFromValueWithoutCoercion(JSValue jsValue)
245
    {
246
#if CPU(BIG_ENDIAN)
247
        switch (Adaptor::typeValue) {
248
        case TypeFloat32:
249
        case TypeFloat64:
250
            return toNativeFromValueWithoutCoercion<Adaptor>(jsValue);
251
        default:
252
            // typed array views are commonly expected to be little endian views of the underlying data
253
            return flipBytes(toNativeFromValueWithoutCoercion<Adaptor>(jsValue));
254
        }
255
#else
256
        return toNativeFromValueWithoutCoercion<Adaptor>(jsValue);
257
#endif
258
    }
193
259
194
    void sort()
260
    void sort()
195
    {
261
    {
196
-- a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h
262
++ b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h
Lines 209-217 EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncIncludes(VM& vm, JSGl Link Here
209
    scope.assertNoException();
209
    scope.assertNoException();
210
    RELEASE_ASSERT(!thisObject->isNeutered());
210
    RELEASE_ASSERT(!thisObject->isNeutered());
211
211
212
    if (std::isnan(static_cast<double>(*targetOption))) {
212
    double targetOptionLittleEndianAsDouble;
213
#if CPU(BIG_ENDIAN)
214
    switch (ViewClass::TypedArrayStorageType) {
215
    case TypeFloat32:
216
    case TypeFloat64:
217
        targetOptionLittleEndianAsDouble = static_cast<double>(*targetOption);
218
    default:
219
        // typed array views are commonly expected to be little endian views of the underlying data
220
        targetOptionLittleEndianAsDouble = static_cast<double>(flipBytes(*targetOption));
221
    }
222
#else
223
    targetOptionLittleEndianAsDouble = static_cast<double>(*targetOption);
224
#endif
225
226
    if (std::isnan(targetOptionLittleEndianAsDouble)) {
213
        for (; index < length; ++index) {
227
        for (; index < length; ++index) {
214
            if (std::isnan(static_cast<double>(array[index])))
228
            double arrayElementLittleEndianAsDouble;
229
#if CPU(BIG_ENDIAN)
230
            switch (ViewClass::TypedArrayStorageType) {
231
            case TypeFloat32:
232
            case TypeFloat64:
233
                arrayElementLittleEndianAsDouble = static_cast<double>(array[index]);
234
            default:
235
                // typed array views are commonly expected to be little endian views of the underlying data
236
                arrayElementLittleEndianAsDouble = static_cast<double>(flipBytes(array[index]));
237
            }
238
#else
239
            arrayElementLittleEndianAsDouble = static_cast<double>(array[index]);
240
#endif
241
            if (std::isnan(arrayElementLittleEndianAsDouble))
215
                return JSValue::encode(jsBoolean(true));
242
                return JSValue::encode(jsBoolean(true));
216
        }
243
        }
217
    } else {
244
    } else {
218
-- a/Source/WTF/wtf/FlipBytes.h
245
++ b/Source/WTF/wtf/FlipBytes.h
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