OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 endInt = beginInt; | 138 endInt = beginInt; |
139 } | 139 } |
140 var newLength = endInt - beginInt; | 140 var newLength = endInt - beginInt; |
141 var beginByteOffset = | 141 var beginByteOffset = |
142 %TypedArrayGetByteOffset(this) + beginInt * elementSize; | 142 %TypedArrayGetByteOffset(this) + beginInt * elementSize; |
143 return new constructor(%TypedArrayGetBuffer(this), | 143 return new constructor(%TypedArrayGetBuffer(this), |
144 beginByteOffset, newLength); | 144 beginByteOffset, newLength); |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 function TypedArraySet(obj, offset) { | |
149 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_POSITIVE_INTEGER(offset); | |
150 if (%TypedArraySetSpecialCases(this, obj, intOffset)) | |
151 return; | |
152 | |
153 var l = obj.length; | |
154 if (IS_UNDEFINED(l)) { | |
155 throw MakeTypeError("invalid_argument"); | |
156 } | |
157 if (intOffset + l > this.length) { | |
158 throw MakeRangeError("typed_array_set_source_too_long"); | |
159 } | |
160 for (var i = 0; i < l; i++) { | |
rossberg
2013/05/07 13:53:23
Is this function supposed to work with non-typed-a
Dmitry Lomov (no reviews)
2013/05/07 14:20:00
Done. No non-typed-array receivers
On 2013/05/07 1
| |
161 this[intOffset+i] = obj[i]; | |
rossberg
2013/05/07 13:53:23
Style nit: space around +
Dmitry Lomov (no reviews)
2013/05/07 14:20:00
Done.
| |
162 } | |
163 } | |
148 | 164 |
149 // ------------------------------------------------------------------- | 165 // ------------------------------------------------------------------- |
150 | 166 |
151 function SetupTypedArray(arrayId, name, constructor, elementSize) { | 167 function SetupTypedArray(arrayId, name, constructor, elementSize) { |
152 %CheckIsBootstrapping(); | 168 %CheckIsBootstrapping(); |
153 var fun = CreateTypedArrayConstructor(name, elementSize, | 169 var fun = CreateTypedArrayConstructor(name, elementSize, |
154 arrayId, constructor); | 170 arrayId, constructor); |
155 %SetCode(constructor, fun); | 171 %SetCode(constructor, fun); |
156 %FunctionSetPrototype(constructor, new $Object()); | 172 %FunctionSetPrototype(constructor, new $Object()); |
157 | 173 |
158 %SetProperty(constructor.prototype, | 174 %SetProperty(constructor.prototype, |
159 "constructor", constructor, DONT_ENUM); | 175 "constructor", constructor, DONT_ENUM); |
160 %SetProperty(constructor.prototype, | 176 %SetProperty(constructor.prototype, |
161 "BYTES_PER_ELEMENT", elementSize, | 177 "BYTES_PER_ELEMENT", elementSize, |
162 READ_ONLY | DONT_ENUM | DONT_DELETE); | 178 READ_ONLY | DONT_ENUM | DONT_DELETE); |
163 InstallGetter(constructor.prototype, "buffer", TypedArrayGetBuffer); | 179 InstallGetter(constructor.prototype, "buffer", TypedArrayGetBuffer); |
164 InstallGetter(constructor.prototype, "byteOffset", TypedArrayGetByteOffset); | 180 InstallGetter(constructor.prototype, "byteOffset", TypedArrayGetByteOffset); |
165 InstallGetter(constructor.prototype, "byteLength", TypedArrayGetByteLength); | 181 InstallGetter(constructor.prototype, "byteLength", TypedArrayGetByteLength); |
166 InstallGetter(constructor.prototype, "length", TypedArrayGetLength); | 182 InstallGetter(constructor.prototype, "length", TypedArrayGetLength); |
167 | 183 |
168 InstallFunctions(constructor.prototype, DONT_ENUM, $Array( | 184 InstallFunctions(constructor.prototype, DONT_ENUM, $Array( |
169 "subarray", CreateSubArray(elementSize, constructor) | 185 "subarray", CreateSubArray(elementSize, constructor), |
186 "set", TypedArraySet | |
170 )); | 187 )); |
171 } | 188 } |
172 | 189 |
173 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 190 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
174 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); | 191 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); |
175 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); | 192 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); |
176 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); | 193 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); |
177 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); | 194 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); |
178 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); | 195 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); |
179 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); | 196 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); |
180 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); | 197 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); |
181 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); | 198 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); |
182 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); | 199 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); |
OLD | NEW |