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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index d435803a5aa603793c5cce5ada2bd884979f0a24..422dc4a03cba36b8a422b5913babaafe1c83bb06 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -347,225 +347,52 @@ function DataViewGetByteLength() {
return %DataViewGetByteLength(this);
}
+macro DATA_VIEW_TYPES(FUNCTION)
+ FUNCTION(Int8)
+ FUNCTION(Uint8)
+ FUNCTION(Int16)
+ FUNCTION(Uint16)
+ FUNCTION(Int32)
+ FUNCTION(Uint32)
+ FUNCTION(Float32)
+ FUNCTION(Float64)
+endmacro
+
function ToPositiveDataViewOffset(offset) {
return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset');
}
-function DataViewGetInt8(offset, little_endian) {
+
+macro DATA_VIEW_GETTER_SETTER(TYPENAME)
+function DataViewGetTYPENAME(offset, little_endian) {
if (!IS_DATAVIEW(this)) {
throw MakeTypeError('incompatible_method_receiver',
- ['DataView.getInt8', this]);
+ ['DataView.getTYPENAME', this]);
}
if (%_ArgumentsLength() < 1) {
throw MakeTypeError('invalid_argument');
}
- return %DataViewGetInt8(this,
+ return %DataViewGetTYPENAME(this,
ToPositiveDataViewOffset(offset),
!!little_endian);
}
-function DataViewSetInt8(offset, value, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.setInt8', this]);
- }
- if (%_ArgumentsLength() < 2) {
- throw MakeTypeError('invalid_argument');
- }
- %DataViewSetInt8(this,
- ToPositiveDataViewOffset(offset),
- TO_NUMBER_INLINE(value),
- !!little_endian);
-}
-
-function DataViewGetUint8(offset, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.getUint8', this]);
- }
- if (%_ArgumentsLength() < 1) {
- throw MakeTypeError('invalid_argument');
- }
- return %DataViewGetUint8(this,
- ToPositiveDataViewOffset(offset),
- !!little_endian);
-}
-
-function DataViewSetUint8(offset, value, little_endian) {
+function DataViewSetTYPENAME(offset, value, little_endian) {
if (!IS_DATAVIEW(this)) {
throw MakeTypeError('incompatible_method_receiver',
- ['DataView.setUint8', this]);
+ ['DataView.setTYPENAME', this]);
}
if (%_ArgumentsLength() < 2) {
throw MakeTypeError('invalid_argument');
}
- %DataViewSetUint8(this,
+ %DataViewSetTYPENAME(this,
ToPositiveDataViewOffset(offset),
TO_NUMBER_INLINE(value),
!!little_endian);
}
+endmacro
-function DataViewGetInt16(offset, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.getInt16', this]);
- }
- if (%_ArgumentsLength() < 1) {
- throw MakeTypeError('invalid_argument');
- }
- return %DataViewGetInt16(this,
- ToPositiveDataViewOffset(offset),
- !!little_endian);
-}
-
-function DataViewSetInt16(offset, value, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.setInt16', this]);
- }
- if (%_ArgumentsLength() < 2) {
- throw MakeTypeError('invalid_argument');
- }
- %DataViewSetInt16(this,
- ToPositiveDataViewOffset(offset),
- TO_NUMBER_INLINE(value),
- !!little_endian);
-}
-
-function DataViewGetUint16(offset, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.getUint16', this]);
- }
- if (%_ArgumentsLength() < 1) {
- throw MakeTypeError('invalid_argument');
- }
- return %DataViewGetUint16(this,
- ToPositiveDataViewOffset(offset),
- !!little_endian);
-}
-
-function DataViewSetUint16(offset, value, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.setUint16', this]);
- }
- if (%_ArgumentsLength() < 2) {
- throw MakeTypeError('invalid_argument');
- }
- %DataViewSetUint16(this,
- ToPositiveDataViewOffset(offset),
- TO_NUMBER_INLINE(value),
- !!little_endian);
-}
-
-function DataViewGetInt32(offset, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.getInt32', this]);
- }
- if (%_ArgumentsLength() < 1) {
- throw MakeTypeError('invalid_argument');
- }
- return %DataViewGetInt32(this,
- ToPositiveDataViewOffset(offset),
- !!little_endian);
-}
-
-function DataViewSetInt32(offset, value, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.setInt32', this]);
- }
- if (%_ArgumentsLength() < 2) {
- throw MakeTypeError('invalid_argument');
- }
- %DataViewSetInt32(this,
- ToPositiveDataViewOffset(offset),
- TO_NUMBER_INLINE(value),
- !!little_endian);
-}
-
-function DataViewGetUint32(offset, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.getUint32', this]);
- }
- if (%_ArgumentsLength() < 1) {
- throw MakeTypeError('invalid_argument');
- }
- return %DataViewGetUint32(this,
- ToPositiveDataViewOffset(offset),
- !!little_endian);
-}
-
-function DataViewSetUint32(offset, value, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.setUint32', this]);
- }
- if (%_ArgumentsLength() < 2) {
- throw MakeTypeError('invalid_argument');
- }
- %DataViewSetUint32(this,
- ToPositiveDataViewOffset(offset),
- TO_NUMBER_INLINE(value),
- !!little_endian);
-}
-
-function DataViewGetFloat32(offset, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.getFloat32', this]);
- }
- if (%_ArgumentsLength() < 1) {
- throw MakeTypeError('invalid_argument');
- }
- return %DataViewGetFloat32(this,
- ToPositiveDataViewOffset(offset),
- !!little_endian);
-}
-
-function DataViewSetFloat32(offset, value, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.setFloat32', this]);
- }
- if (%_ArgumentsLength() < 2) {
- throw MakeTypeError('invalid_argument');
- }
- %DataViewSetFloat32(this,
- ToPositiveDataViewOffset(offset),
- TO_NUMBER_INLINE(value),
- !!little_endian);
-}
-
-function DataViewGetFloat64(offset, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.getFloat64', this]);
- }
- if (%_ArgumentsLength() < 1) {
- throw MakeTypeError('invalid_argument');
- }
- return %DataViewGetFloat64(this,
- ToPositiveDataViewOffset(offset),
- !!little_endian);
-}
-
-function DataViewSetFloat64(offset, value, little_endian) {
- if (!IS_DATAVIEW(this)) {
- throw MakeTypeError('incompatible_method_receiver',
- ['DataView.setFloat64', this]);
- }
- if (%_ArgumentsLength() < 2) {
- throw MakeTypeError('invalid_argument');
- }
- %DataViewSetFloat64(this,
- ToPositiveDataViewOffset(offset),
- TO_NUMBER_INLINE(value),
- !!little_endian);
-}
+DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER)
function SetupDataView() {
%CheckIsBootstrapping();
« 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