OLD | NEW |
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 | 165 |
166 uint32_t len = 0; | 166 uint32_t len = 0; |
167 v8::Handle<v8::Object> srcArray; | 167 v8::Handle<v8::Object> srcArray; |
168 bool doInstantiation = false; | 168 bool doInstantiation = false; |
169 | 169 |
170 if (args[0]->IsObject()) { | 170 if (args[0]->IsObject()) { |
171 srcArray = args[0]->ToObject(); | 171 srcArray = args[0]->ToObject(); |
172 if (srcArray.IsEmpty()) | 172 if (srcArray.IsEmpty()) |
173 return throwTypeError("Could not convert argument 0 to an array", ar
gs.GetIsolate()); | 173 return throwTypeError("Could not convert argument 0 to an array", ar
gs.GetIsolate()); |
174 len = toUInt32(srcArray->Get(v8::String::NewSymbol("length"))); | 174 v8::Local<v8::Value> val = srcArray->Get(v8::String::NewSymbol("length")
); |
| 175 if (val.IsEmpty()) { |
| 176 // Exception thrown during fetch of length property. |
| 177 return v8Undefined(); |
| 178 } |
| 179 len = toUInt32(val); |
175 doInstantiation = true; | 180 doInstantiation = true; |
176 } else { | 181 } else { |
177 bool ok = false; | 182 bool ok = false; |
178 int32_t tempLength = toInt32(args[0], ok); // NaN/+inf/-inf returns 0, t
his is intended by WebIDL | 183 int32_t tempLength = toInt32(args[0], ok); // NaN/+inf/-inf returns 0, t
his is intended by WebIDL |
179 if (ok && tempLength >= 0) { | 184 if (ok && tempLength >= 0) { |
180 len = static_cast<uint32_t>(tempLength); | 185 len = static_cast<uint32_t>(tempLength); |
181 doInstantiation = true; | 186 doInstantiation = true; |
182 } | 187 } |
183 } | 188 } |
184 | 189 |
(...skipping 16 matching lines...) Expand all Loading... |
201 v8::V8::AdjustAmountOfExternalAllocatedMemory(array->byteLength()); | 206 v8::V8::AdjustAmountOfExternalAllocatedMemory(array->byteLength()); |
202 } | 207 } |
203 | 208 |
204 | 209 |
205 // Transform the holder into a wrapper object for the array. | 210 // Transform the holder into a wrapper object for the array. |
206 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddr
ess(), arrayType, array.get()->length()); | 211 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddr
ess(), arrayType, array.get()->length()); |
207 | 212 |
208 if (!srcArray.IsEmpty()) { | 213 if (!srcArray.IsEmpty()) { |
209 bool copied = copyElements(args.Holder(), srcArray, len, 0, args.GetIsol
ate()); | 214 bool copied = copyElements(args.Holder(), srcArray, len, 0, args.GetIsol
ate()); |
210 if (!copied) { | 215 if (!copied) { |
211 for (unsigned i = 0; i < len; i++) | 216 for (unsigned i = 0; i < len; i++) { |
212 array->set(i, srcArray->Get(i)->NumberValue()); | 217 v8::Local<v8::Value> val = srcArray->Get(i); |
| 218 if (val.IsEmpty()) { |
| 219 // Exception thrown during fetch. |
| 220 return v8Undefined(); |
| 221 } |
| 222 array->set(i, val->NumberValue()); |
| 223 } |
213 } | 224 } |
214 } | 225 } |
215 | 226 |
216 v8::Handle<v8::Object> wrapper = args.Holder(); | 227 v8::Handle<v8::Object> wrapper = args.Holder(); |
217 v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWith
Wrapper(array.release(), type, wrapper); | 228 v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWith
Wrapper(array.release(), type, wrapper); |
218 wrapperHandle.MarkIndependent(); | 229 wrapperHandle.MarkIndependent(); |
219 return wrapper; | 230 return wrapper; |
220 } | 231 } |
221 | 232 |
222 template <class CPlusPlusArrayType, class JavaScriptWrapperArrayType> | 233 template <class CPlusPlusArrayType, class JavaScriptWrapperArrayType> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 265 } |
255 return v8::Undefined(); | 266 return v8::Undefined(); |
256 } | 267 } |
257 | 268 |
258 return throwTypeError("Invalid argument", args.GetIsolate()); | 269 return throwTypeError("Invalid argument", args.GetIsolate()); |
259 } | 270 } |
260 | 271 |
261 } | 272 } |
262 | 273 |
263 #endif // V8ArrayBufferViewCustom_h | 274 #endif // V8ArrayBufferViewCustom_h |
OLD | NEW |