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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 190 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
191 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); | 191 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); |
192 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); | 192 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); |
193 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); | 193 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); |
194 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); | 194 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); |
195 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); | 195 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); |
196 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); | 196 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); |
197 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); | 197 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); |
198 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); | 198 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); |
199 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); | 199 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); |
200 | |
201 | |
202 // --------------------------- DataView ----------------------------- | |
203 | |
204 var $DataView = global.DataView; | |
205 | |
206 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | |
207 if (%_IsConstructCall()) { | |
208 if (!IS_ARRAYBUFFER(buffer)) { | |
209 throw MakeTypeError('data_view_not_array_buffer',[]); | |
210 } | |
211 var bufferByteLength = %ArrayBufferGetByteLength(buffer); | |
212 var offset = IS_UNDEFINED(byteOffset) ? 0 : TO_POSITIVE_INTEGER(byteOffset); | |
213 if (offset > bufferByteLength) { | |
214 throw MakeRangeError('invalid_data_view_offset',[]); | |
rossberg
2013/06/21 08:44:01
Nit: space after comma
Dmitry Lomov (no reviews)
2013/06/21 11:32:10
Done.
| |
215 } | |
216 var length = IS_UNDEFINED(byteLength) ? | |
217 bufferByteLength - offset : TO_POSITIVE_INTEGER(byteLength); | |
218 if (offset + length > bufferByteLength) { | |
219 throw new MakeRangeError('invalid_data_view_length'); | |
220 } | |
221 %DataViewInitialize(this, buffer, offset, length); | |
222 } else { | |
223 return new $DataView(buffer, byteOffset, byteLength) | |
224 } | |
225 } | |
226 | |
227 function DataViewGetBuffer() { | |
228 return %DataViewGetBuffer(this); | |
229 } | |
230 | |
231 function DataViewGetByteOffset() { | |
232 return %DataViewGetByteOffset(this); | |
233 } | |
234 | |
235 function DataViewGetByteLength() { | |
236 return %DataViewGetByteLength(this); | |
237 } | |
238 | |
239 function DataViewGetInt8(offset, little_endian) { | |
240 if (!IS_DATAVIEW(this)) { | |
241 throw MakeTypeError('incompatible_method_reciever', | |
242 ['DataView.getInt8', this]); | |
243 } | |
244 var little_endian = IS_UNDEFINED(little_endian) | |
rossberg
2013/06/21 08:44:01
Don't use redundant 'var' (here and below).
Also,
Dmitry Lomov (no reviews)
2013/06/21 11:32:10
Done.
| |
245 ? false : (little_endian ? true : false); | |
246 var offset = TO_POSITIVE_INTEGER(offset); | |
247 return %DataViewGetInt8(this, offset, little_endian); | |
248 } | |
249 | |
250 function DataViewSetInt8(offset, value, little_endian) { | |
251 if (!IS_DATAVIEW(this)) { | |
252 throw MakeTypeError('incompatible_method_reciever', | |
253 ['DataView.setInt8', this]); | |
254 } | |
255 var little_endian = IS_UNDEFINED(little_endian) | |
256 ? false : (little_endian ? true : false); | |
257 var value = TO_NUMBER_INLINE(value); | |
258 var offset = TO_POSITIVE_INTEGER(offset); | |
259 %DataViewSetInt8(this, offset, value, little_endian); | |
260 } | |
261 | |
262 function DataViewGetUint8(offset, little_endian) { | |
263 if (!IS_DATAVIEW(this)) { | |
264 throw MakeTypeError('incompatible_method_reciever', | |
265 ['DataView.getUint8', this]); | |
266 } | |
267 var little_endian = IS_UNDEFINED(little_endian) | |
268 ? false : (little_endian ? true : false); | |
269 var offset = TO_POSITIVE_INTEGER(offset); | |
270 return %DataViewGetUint8(this, offset, little_endian); | |
271 } | |
272 | |
273 function DataViewSetUint8(offset, value, little_endian) { | |
274 if (!IS_DATAVIEW(this)) { | |
275 throw MakeTypeError('incompatible_method_reciever', | |
276 ['DataView.setUint8', this]); | |
277 } | |
278 var little_endian = IS_UNDEFINED(little_endian) | |
279 ? false : (little_endian ? true : false); | |
280 var value = TO_NUMBER_INLINE(value); | |
281 var offset = TO_POSITIVE_INTEGER(offset); | |
282 %DataViewSetUint8(this, offset, value, little_endian); | |
283 } | |
284 function DataViewGetInt16(offset, little_endian) { | |
285 if (!IS_DATAVIEW(this)) { | |
286 throw MakeTypeError('incompatible_method_reciever', | |
287 ['DataView.getInt16', this]); | |
288 } | |
289 var little_endian = IS_UNDEFINED(little_endian) | |
290 ? false : (little_endian ? true : false); | |
291 var offset = TO_POSITIVE_INTEGER(offset); | |
292 return %DataViewGetInt16(this, offset, little_endian); | |
293 } | |
294 | |
295 function DataViewSetInt16(offset, value, little_endian) { | |
296 if (!IS_DATAVIEW(this)) { | |
297 throw MakeTypeError('incompatible_method_reciever', | |
298 ['DataView.setInt16', this]); | |
299 } | |
300 var little_endian = IS_UNDEFINED(little_endian) | |
301 ? false : (little_endian ? true : false); | |
302 var value = TO_NUMBER_INLINE(value); | |
303 var offset = TO_POSITIVE_INTEGER(offset); | |
304 %DataViewSetInt16(this, offset, value, little_endian); | |
305 } | |
306 | |
307 function DataViewGetUint16(offset, little_endian) { | |
308 if (!IS_DATAVIEW(this)) { | |
309 throw MakeTypeError('incompatible_method_reciever', | |
310 ['DataView.getUint16', this]); | |
311 } | |
312 var little_endian = IS_UNDEFINED(little_endian) | |
313 ? false : (little_endian ? true : false); | |
314 var offset = TO_POSITIVE_INTEGER(offset); | |
315 return %DataViewGetUint16(this, offset, little_endian); | |
316 } | |
317 | |
318 function DataViewSetUint16(offset, value, little_endian) { | |
319 if (!IS_DATAVIEW(this)) { | |
320 throw MakeTypeError('incompatible_method_reciever', | |
321 ['DataView.setUint16', this]); | |
322 } | |
323 var little_endian = IS_UNDEFINED(little_endian) | |
324 ? false : (little_endian ? true : false); | |
325 var value = TO_NUMBER_INLINE(value); | |
326 var offset = TO_POSITIVE_INTEGER(offset); | |
327 %DataViewSetUint16(this, offset, value, little_endian); | |
328 } | |
329 | |
330 function DataViewGetInt32(offset, little_endian) { | |
331 if (!IS_DATAVIEW(this)) { | |
332 throw MakeTypeError('incompatible_method_reciever', | |
333 ['DataView.getInt32', this]); | |
334 } | |
335 var little_endian = IS_UNDEFINED(little_endian) | |
336 ? false : (little_endian ? true : false); | |
337 var offset = TO_POSITIVE_INTEGER(offset); | |
338 return %DataViewGetInt32(this, offset, little_endian); | |
339 } | |
340 | |
341 function DataViewSetInt32(offset, value, little_endian) { | |
342 if (!IS_DATAVIEW(this)) { | |
343 throw MakeTypeError('incompatible_method_reciever', | |
344 ['DataView.setInt32', this]); | |
345 } | |
346 var little_endian = IS_UNDEFINED(little_endian) | |
347 ? false : (little_endian ? true : false); | |
348 var value = TO_NUMBER_INLINE(value); | |
349 var offset = TO_POSITIVE_INTEGER(offset); | |
350 %DataViewSetInt32(this, offset, value, little_endian); | |
351 } | |
352 | |
353 function DataViewGetUint32(offset, little_endian) { | |
354 if (!IS_DATAVIEW(this)) { | |
355 throw MakeTypeError('incompatible_method_reciever', | |
356 ['DataView.getUint32', this]); | |
357 } | |
358 var little_endian = IS_UNDEFINED(little_endian) | |
359 ? false : (little_endian ? true : false); | |
360 var offset = TO_POSITIVE_INTEGER(offset); | |
361 return %DataViewGetUint32(this, offset, little_endian); | |
362 } | |
363 | |
364 function DataViewSetUint32(offset, value, little_endian) { | |
365 if (!IS_DATAVIEW(this)) { | |
366 throw MakeTypeError('incompatible_method_reciever', | |
367 ['DataView.setUint32', this]); | |
368 } | |
369 var little_endian = IS_UNDEFINED(little_endian) | |
370 ? false : (little_endian ? true : false); | |
371 var value = TO_NUMBER_INLINE(value); | |
372 var offset = TO_POSITIVE_INTEGER(offset); | |
373 %DataViewSetUint32(this, offset, value, little_endian); | |
374 } | |
375 | |
376 function DataViewGetFloat32(offset, little_endian) { | |
377 if (!IS_DATAVIEW(this)) { | |
378 throw MakeTypeError('incompatible_method_reciever', | |
379 ['DataView.getFloat32', this]); | |
380 } | |
381 var little_endian = IS_UNDEFINED(little_endian) | |
382 ? false : (little_endian ? true : false); | |
383 var offset = TO_POSITIVE_INTEGER(offset); | |
384 return %DataViewGetFloat32(this, offset, little_endian); | |
385 } | |
386 | |
387 function DataViewSetFloat32(offset, value, little_endian) { | |
388 if (!IS_DATAVIEW(this)) { | |
389 throw MakeTypeError('incompatible_method_reciever', | |
390 ['DataView.setFloat32', this]); | |
391 } | |
392 var little_endian = IS_UNDEFINED(little_endian) | |
393 ? false : (little_endian ? true : false); | |
394 var value = TO_NUMBER_INLINE(value); | |
395 var offset = TO_POSITIVE_INTEGER(offset); | |
396 %DataViewSetFloat32(this, offset, value, little_endian); | |
397 } | |
398 | |
399 function DataViewGetFloat64(offset, little_endian) { | |
400 if (!IS_DATAVIEW(this)) { | |
401 throw MakeTypeError('incompatible_method_reciever', | |
402 ['DataView.getFloat64', this]); | |
403 } | |
404 var little_endian = IS_UNDEFINED(little_endian) | |
405 ? false : (little_endian ? true : false); | |
406 var offset = TO_POSITIVE_INTEGER(offset); | |
407 return %DataViewGetFloat64(this, offset, little_endian); | |
408 } | |
409 | |
410 function DataViewSetFloat64(offset, value, little_endian) { | |
411 if (!IS_DATAVIEW(this)) { | |
412 throw MakeTypeError('incompatible_method_reciever', | |
413 ['DataView.setFloat64', this]); | |
414 } | |
415 var little_endian = IS_UNDEFINED(little_endian) | |
416 ? false : (little_endian ? true : false); | |
417 var value = TO_NUMBER_INLINE(value); | |
418 var offset = TO_POSITIVE_INTEGER(offset); | |
419 %DataViewSetFloat64(this, offset, value, little_endian); | |
420 } | |
421 | |
422 function SetupDataView() { | |
423 %CheckIsBootstrapping(); | |
424 | |
425 // Setup the DataView constructor. | |
426 %SetCode($DataView, DataViewConstructor); | |
427 %FunctionSetPrototype($DataView, new $Object); | |
428 | |
429 // Set up constructor property on the DataView prototype. | |
430 %SetProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); | |
431 | |
432 InstallGetter($DataView.prototype, "buffer", DataViewGetBuffer); | |
433 InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset); | |
434 InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength); | |
435 | |
436 InstallFunctions($DataView.prototype, DONT_ENUM, $Array( | |
437 "getInt8", DataViewGetInt8, | |
438 "setInt8", DataViewSetInt8, | |
439 | |
440 "getUint8", DataViewGetUint8, | |
441 "setUint8", DataViewSetUint8, | |
442 | |
443 "getInt16", DataViewGetInt16, | |
444 "setInt16", DataViewSetInt16, | |
445 | |
446 "getUint16", DataViewGetUint16, | |
447 "setUint16", DataViewSetUint16, | |
448 | |
449 "getInt32", DataViewGetInt32, | |
450 "setInt32", DataViewSetInt32, | |
451 | |
452 "getUint32", DataViewGetUint32, | |
453 "setUint32", DataViewSetUint32, | |
454 | |
455 "getFloat32", DataViewGetFloat32, | |
456 "setFloat32", DataViewSetFloat32, | |
457 | |
458 "getFloat64", DataViewGetFloat64, | |
459 "setFloat64", DataViewSetFloat64 | |
460 )); | |
461 } | |
462 | |
463 SetupDataView(); | |
OLD | NEW |