OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 if (!buf) | 47 if (!buf) |
48 return throwError("Could not convert argument 0 to a ArrayBuffer"); | 48 return throwError("Could not convert argument 0 to a ArrayBuffer"); |
49 bool ok; | 49 bool ok; |
50 uint32_t offset = 0; | 50 uint32_t offset = 0; |
51 int argLen = args.Length(); | 51 int argLen = args.Length(); |
52 if (argLen > 1) { | 52 if (argLen > 1) { |
53 offset = toUInt32(args[1], ok); | 53 offset = toUInt32(args[1], ok); |
54 if (!ok) | 54 if (!ok) |
55 return throwError("Could not convert argument 1 to a number"); | 55 return throwError("Could not convert argument 1 to a number"); |
56 } | 56 } |
57 if ((buf->byteLength() - offset) % sizeof(ElementType)) | 57 uint32_t length = 0; |
58 return throwError("ArrayBuffer length minus the byteOffset is not a mult
iple of the element size.", V8Proxy::RangeError); | |
59 uint32_t length = (buf->byteLength() - offset) / sizeof(ElementType); | |
60 if (argLen > 2) { | 58 if (argLen > 2) { |
61 length = toUInt32(args[2], ok); | 59 length = toUInt32(args[2], ok); |
62 if (!ok) | 60 if (!ok) |
63 return throwError("Could not convert argument 2 to a number"); | 61 return throwError("Could not convert argument 2 to a number"); |
| 62 } else { |
| 63 if ((buf->byteLength() - offset) % sizeof(ElementType)) |
| 64 return throwError("ArrayBuffer length minus the byteOffset is not a
multiple of the element size.", V8Proxy::RangeError); |
| 65 length = (buf->byteLength() - offset) / sizeof(ElementType); |
64 } | 66 } |
65 | |
66 RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length); | 67 RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length); |
67 if (!array) { | 68 if (!array) { |
68 V8Proxy::setDOMException(INDEX_SIZE_ERR); | 69 V8Proxy::setDOMException(INDEX_SIZE_ERR); |
69 return notHandledByInterceptor(); | 70 return notHandledByInterceptor(); |
70 } | 71 } |
71 // Transform the holder into a wrapper object for the array. | 72 // Transform the holder into a wrapper object for the array. |
72 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); | 73 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); |
73 if (hasIndexer) | 74 if (hasIndexer) |
74 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->base
Address(), arrayType, array.get()->length()); | 75 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->base
Address(), arrayType, array.get()->length()); |
75 return toV8(array.release(), args.Holder(), MarkIndependent); | 76 return toV8(array.release(), args.Holder(), MarkIndependent); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 return v8::Undefined(); | 202 return v8::Undefined(); |
202 } | 203 } |
203 | 204 |
204 V8Proxy::setDOMException(SYNTAX_ERR); | 205 V8Proxy::setDOMException(SYNTAX_ERR); |
205 return notHandledByInterceptor(); | 206 return notHandledByInterceptor(); |
206 } | 207 } |
207 | 208 |
208 } | 209 } |
209 | 210 |
210 #endif // V8ArrayBufferViewCustom_h | 211 #endif // V8ArrayBufferViewCustom_h |
OLD | NEW |