Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: src/typedarray.js

Issue 68503006: Remove boilerplate code in DataView getter/setter implementations (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 340 }
341 341
342 function DataViewGetByteLength() { 342 function DataViewGetByteLength() {
343 if (!IS_DATAVIEW(this)) { 343 if (!IS_DATAVIEW(this)) {
344 throw MakeTypeError('incompatible_method_receiver', 344 throw MakeTypeError('incompatible_method_receiver',
345 ['DataView.byteLength', this]); 345 ['DataView.byteLength', this]);
346 } 346 }
347 return %DataViewGetByteLength(this); 347 return %DataViewGetByteLength(this);
348 } 348 }
349 349
350 macro DATA_VIEW_TYPES(FUNCTION)
351 FUNCTION(Int8)
352 FUNCTION(Uint8)
353 FUNCTION(Int16)
354 FUNCTION(Uint16)
355 FUNCTION(Int32)
356 FUNCTION(Uint32)
357 FUNCTION(Float32)
358 FUNCTION(Float64)
359 endmacro
360
350 function ToPositiveDataViewOffset(offset) { 361 function ToPositiveDataViewOffset(offset) {
351 return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset'); 362 return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset');
352 } 363 }
353 364
354 function DataViewGetInt8(offset, little_endian) { 365
366 macro DATA_VIEW_GETTER_SETTER(TYPENAME)
367 function DataViewGetTYPENAME(offset, little_endian) {
355 if (!IS_DATAVIEW(this)) { 368 if (!IS_DATAVIEW(this)) {
356 throw MakeTypeError('incompatible_method_receiver', 369 throw MakeTypeError('incompatible_method_receiver',
357 ['DataView.getInt8', this]); 370 ['DataView.getTYPENAME', this]);
358 } 371 }
359 if (%_ArgumentsLength() < 1) { 372 if (%_ArgumentsLength() < 1) {
360 throw MakeTypeError('invalid_argument'); 373 throw MakeTypeError('invalid_argument');
361 } 374 }
362 return %DataViewGetInt8(this, 375 return %DataViewGetTYPENAME(this,
363 ToPositiveDataViewOffset(offset), 376 ToPositiveDataViewOffset(offset),
364 !!little_endian); 377 !!little_endian);
365 } 378 }
366 379
367 function DataViewSetInt8(offset, value, little_endian) { 380 function DataViewSetTYPENAME(offset, value, little_endian) {
368 if (!IS_DATAVIEW(this)) { 381 if (!IS_DATAVIEW(this)) {
369 throw MakeTypeError('incompatible_method_receiver', 382 throw MakeTypeError('incompatible_method_receiver',
370 ['DataView.setInt8', this]); 383 ['DataView.setTYPENAME', this]);
371 } 384 }
372 if (%_ArgumentsLength() < 2) { 385 if (%_ArgumentsLength() < 2) {
373 throw MakeTypeError('invalid_argument'); 386 throw MakeTypeError('invalid_argument');
374 } 387 }
375 %DataViewSetInt8(this, 388 %DataViewSetTYPENAME(this,
376 ToPositiveDataViewOffset(offset), 389 ToPositiveDataViewOffset(offset),
377 TO_NUMBER_INLINE(value), 390 TO_NUMBER_INLINE(value),
378 !!little_endian); 391 !!little_endian);
379 } 392 }
393 endmacro
380 394
381 function DataViewGetUint8(offset, little_endian) { 395 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER)
382 if (!IS_DATAVIEW(this)) {
383 throw MakeTypeError('incompatible_method_receiver',
384 ['DataView.getUint8', this]);
385 }
386 if (%_ArgumentsLength() < 1) {
387 throw MakeTypeError('invalid_argument');
388 }
389 return %DataViewGetUint8(this,
390 ToPositiveDataViewOffset(offset),
391 !!little_endian);
392 }
393
394 function DataViewSetUint8(offset, value, little_endian) {
395 if (!IS_DATAVIEW(this)) {
396 throw MakeTypeError('incompatible_method_receiver',
397 ['DataView.setUint8', this]);
398 }
399 if (%_ArgumentsLength() < 2) {
400 throw MakeTypeError('invalid_argument');
401 }
402 %DataViewSetUint8(this,
403 ToPositiveDataViewOffset(offset),
404 TO_NUMBER_INLINE(value),
405 !!little_endian);
406 }
407
408 function DataViewGetInt16(offset, little_endian) {
409 if (!IS_DATAVIEW(this)) {
410 throw MakeTypeError('incompatible_method_receiver',
411 ['DataView.getInt16', this]);
412 }
413 if (%_ArgumentsLength() < 1) {
414 throw MakeTypeError('invalid_argument');
415 }
416 return %DataViewGetInt16(this,
417 ToPositiveDataViewOffset(offset),
418 !!little_endian);
419 }
420
421 function DataViewSetInt16(offset, value, little_endian) {
422 if (!IS_DATAVIEW(this)) {
423 throw MakeTypeError('incompatible_method_receiver',
424 ['DataView.setInt16', this]);
425 }
426 if (%_ArgumentsLength() < 2) {
427 throw MakeTypeError('invalid_argument');
428 }
429 %DataViewSetInt16(this,
430 ToPositiveDataViewOffset(offset),
431 TO_NUMBER_INLINE(value),
432 !!little_endian);
433 }
434
435 function DataViewGetUint16(offset, little_endian) {
436 if (!IS_DATAVIEW(this)) {
437 throw MakeTypeError('incompatible_method_receiver',
438 ['DataView.getUint16', this]);
439 }
440 if (%_ArgumentsLength() < 1) {
441 throw MakeTypeError('invalid_argument');
442 }
443 return %DataViewGetUint16(this,
444 ToPositiveDataViewOffset(offset),
445 !!little_endian);
446 }
447
448 function DataViewSetUint16(offset, value, little_endian) {
449 if (!IS_DATAVIEW(this)) {
450 throw MakeTypeError('incompatible_method_receiver',
451 ['DataView.setUint16', this]);
452 }
453 if (%_ArgumentsLength() < 2) {
454 throw MakeTypeError('invalid_argument');
455 }
456 %DataViewSetUint16(this,
457 ToPositiveDataViewOffset(offset),
458 TO_NUMBER_INLINE(value),
459 !!little_endian);
460 }
461
462 function DataViewGetInt32(offset, little_endian) {
463 if (!IS_DATAVIEW(this)) {
464 throw MakeTypeError('incompatible_method_receiver',
465 ['DataView.getInt32', this]);
466 }
467 if (%_ArgumentsLength() < 1) {
468 throw MakeTypeError('invalid_argument');
469 }
470 return %DataViewGetInt32(this,
471 ToPositiveDataViewOffset(offset),
472 !!little_endian);
473 }
474
475 function DataViewSetInt32(offset, value, little_endian) {
476 if (!IS_DATAVIEW(this)) {
477 throw MakeTypeError('incompatible_method_receiver',
478 ['DataView.setInt32', this]);
479 }
480 if (%_ArgumentsLength() < 2) {
481 throw MakeTypeError('invalid_argument');
482 }
483 %DataViewSetInt32(this,
484 ToPositiveDataViewOffset(offset),
485 TO_NUMBER_INLINE(value),
486 !!little_endian);
487 }
488
489 function DataViewGetUint32(offset, little_endian) {
490 if (!IS_DATAVIEW(this)) {
491 throw MakeTypeError('incompatible_method_receiver',
492 ['DataView.getUint32', this]);
493 }
494 if (%_ArgumentsLength() < 1) {
495 throw MakeTypeError('invalid_argument');
496 }
497 return %DataViewGetUint32(this,
498 ToPositiveDataViewOffset(offset),
499 !!little_endian);
500 }
501
502 function DataViewSetUint32(offset, value, little_endian) {
503 if (!IS_DATAVIEW(this)) {
504 throw MakeTypeError('incompatible_method_receiver',
505 ['DataView.setUint32', this]);
506 }
507 if (%_ArgumentsLength() < 2) {
508 throw MakeTypeError('invalid_argument');
509 }
510 %DataViewSetUint32(this,
511 ToPositiveDataViewOffset(offset),
512 TO_NUMBER_INLINE(value),
513 !!little_endian);
514 }
515
516 function DataViewGetFloat32(offset, little_endian) {
517 if (!IS_DATAVIEW(this)) {
518 throw MakeTypeError('incompatible_method_receiver',
519 ['DataView.getFloat32', this]);
520 }
521 if (%_ArgumentsLength() < 1) {
522 throw MakeTypeError('invalid_argument');
523 }
524 return %DataViewGetFloat32(this,
525 ToPositiveDataViewOffset(offset),
526 !!little_endian);
527 }
528
529 function DataViewSetFloat32(offset, value, little_endian) {
530 if (!IS_DATAVIEW(this)) {
531 throw MakeTypeError('incompatible_method_receiver',
532 ['DataView.setFloat32', this]);
533 }
534 if (%_ArgumentsLength() < 2) {
535 throw MakeTypeError('invalid_argument');
536 }
537 %DataViewSetFloat32(this,
538 ToPositiveDataViewOffset(offset),
539 TO_NUMBER_INLINE(value),
540 !!little_endian);
541 }
542
543 function DataViewGetFloat64(offset, little_endian) {
544 if (!IS_DATAVIEW(this)) {
545 throw MakeTypeError('incompatible_method_receiver',
546 ['DataView.getFloat64', this]);
547 }
548 if (%_ArgumentsLength() < 1) {
549 throw MakeTypeError('invalid_argument');
550 }
551 return %DataViewGetFloat64(this,
552 ToPositiveDataViewOffset(offset),
553 !!little_endian);
554 }
555
556 function DataViewSetFloat64(offset, value, little_endian) {
557 if (!IS_DATAVIEW(this)) {
558 throw MakeTypeError('incompatible_method_receiver',
559 ['DataView.setFloat64', this]);
560 }
561 if (%_ArgumentsLength() < 2) {
562 throw MakeTypeError('invalid_argument');
563 }
564 %DataViewSetFloat64(this,
565 ToPositiveDataViewOffset(offset),
566 TO_NUMBER_INLINE(value),
567 !!little_endian);
568 }
569 396
570 function SetupDataView() { 397 function SetupDataView() {
571 %CheckIsBootstrapping(); 398 %CheckIsBootstrapping();
572 399
573 // Setup the DataView constructor. 400 // Setup the DataView constructor.
574 %SetCode($DataView, DataViewConstructor); 401 %SetCode($DataView, DataViewConstructor);
575 %FunctionSetPrototype($DataView, new $Object); 402 %FunctionSetPrototype($DataView, new $Object);
576 403
577 // Set up constructor property on the DataView prototype. 404 // Set up constructor property on the DataView prototype.
578 %SetProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); 405 %SetProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM);
(...skipping 23 matching lines...) Expand all
602 429
603 "getFloat32", DataViewGetFloat32, 430 "getFloat32", DataViewGetFloat32,
604 "setFloat32", DataViewSetFloat32, 431 "setFloat32", DataViewSetFloat32,
605 432
606 "getFloat64", DataViewGetFloat64, 433 "getFloat64", DataViewGetFloat64,
607 "setFloat64", DataViewSetFloat64 434 "setFloat64", DataViewSetFloat64
608 )); 435 ));
609 } 436 }
610 437
611 SetupDataView(); 438 SetupDataView();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698