Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Side by Side Diff: Source/WebCore/bindings/js/JSArrayBufferViewHelper.h

Issue 7523024: Merge 91803 - Float32Array(ArrayBuffer, index, length) constructor working incorrectly. (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/835/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // Template function used by XXXArrayConstructors. 86 // Template function used by XXXArrayConstructors.
87 // If this returns 0, it will already have thrown a JavaScript exception. 87 // If this returns 0, it will already have thrown a JavaScript exception.
88 template<class C, typename T> 88 template<class C, typename T>
89 PassRefPtr<C> constructArrayBufferViewWithArrayBufferArgument(JSC::ExecState* ex ec) 89 PassRefPtr<C> constructArrayBufferViewWithArrayBufferArgument(JSC::ExecState* ex ec)
90 { 90 {
91 RefPtr<ArrayBuffer> buffer = toArrayBuffer(exec->argument(0)); 91 RefPtr<ArrayBuffer> buffer = toArrayBuffer(exec->argument(0));
92 if (!buffer) 92 if (!buffer)
93 return 0; 93 return 0;
94 94
95 unsigned offset = (exec->argumentCount() > 1) ? exec->argument(1).toUInt32(e xec) : 0; 95 unsigned offset = (exec->argumentCount() > 1) ? exec->argument(1).toUInt32(e xec) : 0;
96 if ((buffer->byteLength() - offset) % sizeof(T)) 96 unsigned int length = 0;
97 throwError(exec, createRangeError(exec, "ArrayBuffer length minus the by teOffset is not a multiple of the element size."));
98 unsigned int length = (buffer->byteLength() - offset) / sizeof(T);
99 if (exec->argumentCount() > 2) 97 if (exec->argumentCount() > 2)
100 length = exec->argument(2).toUInt32(exec); 98 length = exec->argument(2).toUInt32(exec);
99 else {
100 if ((buffer->byteLength() - offset) % sizeof(T)) {
101 throwError(exec, createRangeError(exec, "ArrayBuffer length minus th e byteOffset is not a multiple of the element size."));
102 return 0;
103 }
104 length = (buffer->byteLength() - offset) / sizeof(T);
105 }
101 RefPtr<C> array = C::create(buffer, offset, length); 106 RefPtr<C> array = C::create(buffer, offset, length);
102 if (!array) 107 if (!array)
103 setDOMException(exec, INDEX_SIZE_ERR); 108 setDOMException(exec, INDEX_SIZE_ERR);
104 return array; 109 return array;
105 } 110 }
106 111
107 template<class C, typename T> 112 template<class C, typename T>
108 PassRefPtr<C> constructArrayBufferView(JSC::ExecState* exec) 113 PassRefPtr<C> constructArrayBufferView(JSC::ExecState* exec)
109 { 114 {
110 // There are 3 constructors: 115 // There are 3 constructors:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), object)) 171 if (JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), object))
167 return wrapper; 172 return wrapper;
168 173
169 exec->heap()->reportExtraMemoryCost(object->byteLength()); 174 exec->heap()->reportExtraMemoryCost(object->byteLength());
170 return createWrapper<JSType>(exec, globalObject, object); 175 return createWrapper<JSType>(exec, globalObject, object);
171 } 176 }
172 177
173 } // namespace WebCore 178 } // namespace WebCore
174 179
175 #endif // JSArrayBufferViewHelper_h 180 #endif // JSArrayBufferViewHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698