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

Side by Side Diff: Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h

Issue 10543046: Merge 118955 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1132/
Patch Set: Created 8 years, 6 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, 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 33
34 #include <wtf/ArrayBuffer.h> 34 #include <wtf/ArrayBuffer.h>
35 #include "ExceptionCode.h" 35 #include "ExceptionCode.h"
36 36
37 #include "V8ArrayBuffer.h" 37 #include "V8ArrayBuffer.h"
38 #include "V8Binding.h" 38 #include "V8Binding.h"
39 #include "V8Proxy.h" 39 #include "V8Proxy.h"
40 40
41 namespace WebCore { 41 namespace WebCore {
42 42
43 43 // Copy the elements from the source array to the typed destination array.
44 // Check if the JavaScript 'set' method was already installed 44 // Returns true if it succeeded, otherwise returns false.
45 // on the prototype of the given typed array. 45 bool copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcAr ray, uint32_t length, uint32_t offset);
46 bool fastSetInstalled(v8::Handle<v8::Object> array);
47
48 // Install the JavaScript 'set' method on the prototype of
49 // the given typed array.
50 void installFastSet(v8::Handle<v8::Object> array);
51
52 // Copy the elements from the source array to the typed destination array by
53 // invoking the 'set' method of the destination array in JS.
54 void copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcAr ray, uint32_t offset);
55 46
56 47
57 // Template function used by the ArrayBufferView*Constructor callbacks. 48 // Template function used by the ArrayBufferView*Constructor callbacks.
58 template<class ArrayClass, class ElementType> 49 template<class ArrayClass, class ElementType>
59 v8::Handle<v8::Value> constructWebGLArrayWithArrayBufferArgument(const v8::Argum ents& args, WrapperTypeInfo* type, v8::ExternalArrayType arrayType, bool hasInde xer) 50 v8::Handle<v8::Value> constructWebGLArrayWithArrayBufferArgument(const v8::Argum ents& args, WrapperTypeInfo* type, v8::ExternalArrayType arrayType, bool hasInde xer)
60 { 51 {
61 ArrayBuffer* buf = V8ArrayBuffer::toNative(args[0]->ToObject()); 52 ArrayBuffer* buf = V8ArrayBuffer::toNative(args[0]->ToObject());
62 if (!buf) 53 if (!buf)
63 return throwError("Could not convert argument 0 to a ArrayBuffer"); 54 return throwError("Could not convert argument 0 to a ArrayBuffer");
64 bool ok; 55 bool ok;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 if (doInstantiation) 160 if (doInstantiation)
170 array = ArrayClass::create(len); 161 array = ArrayClass::create(len);
171 if (!array.get()) 162 if (!array.get())
172 return throwError("ArrayBufferView size is not a small enough positive i nteger.", V8Proxy::RangeError); 163 return throwError("ArrayBufferView size is not a small enough positive i nteger.", V8Proxy::RangeError);
173 164
174 165
175 // Transform the holder into a wrapper object for the array. 166 // Transform the holder into a wrapper object for the array.
176 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); 167 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get());
177 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddr ess(), arrayType, array.get()->length()); 168 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddr ess(), arrayType, array.get()->length());
178 169
179 if (!srcArray.IsEmpty()) 170 if (!srcArray.IsEmpty()) {
180 copyElements(args.Holder(), srcArray, 0); 171 bool copied = copyElements(args.Holder(), srcArray, len, 0);
172 if (!copied) {
173 for (unsigned i = 0; i < len; i++)
174 array->set(i, srcArray->Get(i)->NumberValue());
175 }
176 }
181 177
182 v8::Persistent<v8::Object> wrapper = v8::Persistent<v8::Object>::New(args.Ho lder()); 178 v8::Persistent<v8::Object> wrapper = v8::Persistent<v8::Object>::New(args.Ho lder());
183 wrapper.MarkIndependent(); 179 wrapper.MarkIndependent();
184 V8DOMWrapper::setJSWrapperForDOMObject(array.release(), wrapper); 180 V8DOMWrapper::setJSWrapperForDOMObject(array.release(), wrapper);
185 return args.Holder(); 181 return args.Holder();
186 } 182 }
187 183
188 template <class CPlusPlusArrayType, class JavaScriptWrapperArrayType> 184 template <class CPlusPlusArrayType, class JavaScriptWrapperArrayType>
189 v8::Handle<v8::Value> setWebGLArrayHelper(const v8::Arguments& args) 185 v8::Handle<v8::Value> setWebGLArrayHelper(const v8::Arguments& args)
190 { 186 {
(...skipping 21 matching lines...) Expand all
212 uint32_t offset = 0; 208 uint32_t offset = 0;
213 if (args.Length() == 2) 209 if (args.Length() == 2)
214 offset = toUInt32(args[1]); 210 offset = toUInt32(args[1]);
215 uint32_t length = toUInt32(array->Get(v8::String::New("length"))); 211 uint32_t length = toUInt32(array->Get(v8::String::New("length")));
216 if (offset > impl->length() 212 if (offset > impl->length()
217 || offset + length > impl->length() 213 || offset + length > impl->length()
218 || offset + length < offset) 214 || offset + length < offset)
219 // Out of range offset or overflow 215 // Out of range offset or overflow
220 V8Proxy::setDOMException(INDEX_SIZE_ERR, args.GetIsolate()); 216 V8Proxy::setDOMException(INDEX_SIZE_ERR, args.GetIsolate());
221 else { 217 else {
222 if (!fastSetInstalled(args.Holder())) { 218 bool copied = copyElements(args.Holder(), array, length, offset);
223 installFastSet(args.Holder()); 219 if (!copied) {
224 copyElements(args.Holder(), array, offset);
225 } else {
226 for (uint32_t i = 0; i < length; i++) 220 for (uint32_t i = 0; i < length; i++)
227 impl->set(offset + i, array->Get(i)->NumberValue()); 221 impl->set(offset + i, array->Get(i)->NumberValue());
228 } 222 }
229 } 223 }
230 return v8::Undefined(); 224 return v8::Undefined();
231 } 225 }
232 226
233 V8Proxy::setDOMException(SYNTAX_ERR, args.GetIsolate()); 227 V8Proxy::setDOMException(SYNTAX_ERR, args.GetIsolate());
234 return notHandledByInterceptor(); 228 return notHandledByInterceptor();
235 } 229 }
236 230
237 } 231 }
238 232
239 #endif // V8ArrayBufferViewCustom_h 233 #endif // V8ArrayBufferViewCustom_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698