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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length); | 66 RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length); |
67 if (!array) { | 67 if (!array) { |
68 V8Proxy::setDOMException(INDEX_SIZE_ERR); | 68 V8Proxy::setDOMException(INDEX_SIZE_ERR); |
69 return notHandledByInterceptor(); | 69 return notHandledByInterceptor(); |
70 } | 70 } |
71 // Transform the holder into a wrapper object for the array. | 71 // Transform the holder into a wrapper object for the array. |
72 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); | 72 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); |
73 if (hasIndexer) | 73 if (hasIndexer) |
74 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->base
Address(), arrayType, array.get()->length()); | 74 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->base
Address(), arrayType, array.get()->length()); |
75 return toV8(array.release(), args.Holder()); | 75 return toV8(array.release(), args.Holder(), MarkIndependent); |
76 } | 76 } |
77 | 77 |
78 // Template function used by the ArrayBufferView*Constructor callbacks. | 78 // Template function used by the ArrayBufferView*Constructor callbacks. |
79 template<class ArrayClass, class ElementType> | 79 template<class ArrayClass, class ElementType> |
80 v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, WrapperType
Info* type, v8::ExternalArrayType arrayType) | 80 v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, WrapperType
Info* type, v8::ExternalArrayType arrayType) |
81 { | 81 { |
82 if (!args.IsConstructCall()) | 82 if (!args.IsConstructCall()) |
83 return throwError("DOM object constructor cannot be called as a function
."); | 83 return throwError("DOM object constructor cannot be called as a function
."); |
84 | 84 |
85 int argLen = args.Length(); | 85 int argLen = args.Length(); |
86 if (!argLen) { | 86 if (!argLen) { |
87 // This happens when we return a previously constructed | 87 // This happens when we return a previously constructed |
88 // ArrayBufferView, e.g. from the call to <Type>Array.subset(). | 88 // ArrayBufferView, e.g. from the call to <Type>Array.subset(). |
89 // The V8DOMWrapper will set the internal pointer in the | 89 // The V8DOMWrapper will set the internal pointer in the |
90 // created object. Unfortunately it doesn't look like it's | 90 // created object. Unfortunately it doesn't look like it's |
91 // possible to distinguish between this case and that where | 91 // possible to distinguish between this case and that where |
92 // the user calls "new <Type>Array()" from JavaScript. We must | 92 // the user calls "new <Type>Array()" from JavaScript. We must |
93 // construct an empty view to avoid crashes when fetching the | 93 // construct an empty view to avoid crashes when fetching the |
94 // length. | 94 // length. |
95 RefPtr<ArrayClass> array = ArrayClass::create(0); | 95 RefPtr<ArrayClass> array = ArrayClass::create(0); |
96 // Transform the holder into a wrapper object for the array. | 96 // Transform the holder into a wrapper object for the array. |
97 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); | 97 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); |
98 // Do not call SetIndexedPropertiesToExternalArrayData on this | 98 // Do not call SetIndexedPropertiesToExternalArrayData on this |
99 // object. Not only is there no point from a performance | 99 // object. Not only is there no point from a performance |
100 // perspective, but doing so causes errors in the subset() case. | 100 // perspective, but doing so causes errors in the subset() case. |
101 return toV8(array.release(), args.Holder()); | 101 return toV8(array.release(), args.Holder(), MarkIndependent); |
102 } | 102 } |
103 | 103 |
104 // Supported constructors: | 104 // Supported constructors: |
105 // WebGL<T>Array(n) where n is an integer: | 105 // WebGL<T>Array(n) where n is an integer: |
106 // -- create an empty array of n elements | 106 // -- create an empty array of n elements |
107 // WebGL<T>Array(arr) where arr is an array: | 107 // WebGL<T>Array(arr) where arr is an array: |
108 // -- create a WebGL<T>Array containing the contents of "arr" | 108 // -- create a WebGL<T>Array containing the contents of "arr" |
109 // WebGL<T>Array(buf, offset, length) | 109 // WebGL<T>Array(buf, offset, length) |
110 // -- create a WebGL<T>Array pointing to the ArrayBuffer | 110 // -- create a WebGL<T>Array pointing to the ArrayBuffer |
111 // "buf", starting at the specified offset, for the given | 111 // "buf", starting at the specified offset, for the given |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // Need to copy the incoming array into the newly created ArrayBufferVie
w. | 150 // Need to copy the incoming array into the newly created ArrayBufferVie
w. |
151 for (unsigned i = 0; i < len; i++) { | 151 for (unsigned i = 0; i < len; i++) { |
152 v8::Local<v8::Value> val = srcArray->Get(v8::Integer::NewFromUnsigne
d(i)); | 152 v8::Local<v8::Value> val = srcArray->Get(v8::Integer::NewFromUnsigne
d(i)); |
153 array->set(i, val->NumberValue()); | 153 array->set(i, val->NumberValue()); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 // Transform the holder into a wrapper object for the array. | 157 // Transform the holder into a wrapper object for the array. |
158 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); | 158 V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); |
159 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddr
ess(), arrayType, array.get()->length()); | 159 args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddr
ess(), arrayType, array.get()->length()); |
160 return toV8(array.release(), args.Holder()); | 160 return toV8(array.release(), args.Holder(), MarkIndependent); |
161 } | 161 } |
162 | 162 |
163 template <class CPlusPlusArrayType, class JavaScriptWrapperArrayType> | 163 template <class CPlusPlusArrayType, class JavaScriptWrapperArrayType> |
164 v8::Handle<v8::Value> setWebGLArrayHelper(const v8::Arguments& args) | 164 v8::Handle<v8::Value> setWebGLArrayHelper(const v8::Arguments& args) |
165 { | 165 { |
166 if (args.Length() < 1) { | 166 if (args.Length() < 1) { |
167 V8Proxy::setDOMException(SYNTAX_ERR); | 167 V8Proxy::setDOMException(SYNTAX_ERR); |
168 return notHandledByInterceptor(); | 168 return notHandledByInterceptor(); |
169 } | 169 } |
170 | 170 |
(...skipping 30 matching lines...) Expand all Loading... |
201 return v8::Undefined(); | 201 return v8::Undefined(); |
202 } | 202 } |
203 | 203 |
204 V8Proxy::setDOMException(SYNTAX_ERR); | 204 V8Proxy::setDOMException(SYNTAX_ERR); |
205 return notHandledByInterceptor(); | 205 return notHandledByInterceptor(); |
206 } | 206 } |
207 | 207 |
208 } | 208 } |
209 | 209 |
210 #endif // V8ArrayBufferViewCustom_h | 210 #endif // V8ArrayBufferViewCustom_h |
OLD | NEW |