Commit e4ddf3ca authored by dslomov@chromium.org's avatar dslomov@chromium.org

Remove boilerplate code in DataView getter/setter implementations

R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/68503006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17704 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8769c92b
...@@ -347,225 +347,52 @@ function DataViewGetByteLength() { ...@@ -347,225 +347,52 @@ function DataViewGetByteLength() {
return %DataViewGetByteLength(this); 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) { function ToPositiveDataViewOffset(offset) {
return ToPositiveInteger(offset, 'invalid_data_view_accessor_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)) { if (!IS_DATAVIEW(this)) {
throw MakeTypeError('incompatible_method_receiver', throw MakeTypeError('incompatible_method_receiver',
['DataView.getInt8', this]); ['DataView.getTYPENAME', this]);
} }
if (%_ArgumentsLength() < 1) { if (%_ArgumentsLength() < 1) {
throw MakeTypeError('invalid_argument'); throw MakeTypeError('invalid_argument');
} }
return %DataViewGetInt8(this, return %DataViewGetTYPENAME(this,
ToPositiveDataViewOffset(offset), ToPositiveDataViewOffset(offset),
!!little_endian); !!little_endian);
} }
function DataViewSetInt8(offset, value, little_endian) { function DataViewSetTYPENAME(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) {
if (!IS_DATAVIEW(this)) { if (!IS_DATAVIEW(this)) {
throw MakeTypeError('incompatible_method_receiver', throw MakeTypeError('incompatible_method_receiver',
['DataView.setUint8', this]); ['DataView.setTYPENAME', this]);
} }
if (%_ArgumentsLength() < 2) { if (%_ArgumentsLength() < 2) {
throw MakeTypeError('invalid_argument'); throw MakeTypeError('invalid_argument');
} }
%DataViewSetUint8(this, %DataViewSetTYPENAME(this,
ToPositiveDataViewOffset(offset), ToPositiveDataViewOffset(offset),
TO_NUMBER_INLINE(value), TO_NUMBER_INLINE(value),
!!little_endian); !!little_endian);
} }
endmacro
function DataViewGetInt16(offset, little_endian) { DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER)
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);
}
function SetupDataView() { function SetupDataView() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment