@ -462,17 +462,10 @@ static inline void Swizzle(char* start, unsigned int len) {
template < typename T , enum Endianness endianness >
void ReadFloatGeneric ( const FunctionCallbackInfo < Value > & args ) {
Environment * env = Environment : : GetCurrent ( args . GetIsolate ( ) ) ;
bool doAssert = ! args [ 1 ] - > BooleanValue ( ) ;
size_t offset ;
ARGS_THIS ( args [ 0 ] . As < Object > ( ) ) ;
CHECK_NOT_OOB ( ParseArrayIndex ( args [ 0 ] , 0 , & offset ) ) ;
if ( doAssert ) {
size_t len = Length ( args . This ( ) ) ;
if ( offset + sizeof ( T ) > len | | offset + sizeof ( T ) < offset )
return env - > ThrowRangeError ( " Trying to read beyond buffer length " ) ;
}
uint32_t offset = args [ 1 ] - > Uint32Value ( ) ;
CHECK_LE ( offset + sizeof ( T ) , obj_length ) ;
union NoAlias {
T val ;
@ -480,8 +473,7 @@ void ReadFloatGeneric(const FunctionCallbackInfo<Value>& args) {
} ;
union NoAlias na ;
const void * data = args . This ( ) - > GetIndexedPropertiesExternalArrayData ( ) ;
const char * ptr = static_cast < const char * > ( data ) + offset ;
const char * ptr = static_cast < const char * > ( obj_data ) + offset ;
memcpy ( na . bytes , ptr , sizeof ( na . bytes ) ) ;
if ( endianness ! = GetEndianness ( ) )
Swizzle ( na . bytes , sizeof ( na . bytes ) ) ;
@ -512,24 +504,11 @@ void ReadDoubleBE(const FunctionCallbackInfo<Value>& args) {
template < typename T , enum Endianness endianness >
uint32_t WriteFloatGeneric ( const FunctionCallbackInfo < Value > & args ) {
Environment * env = Environment : : GetCurrent ( args . GetIsolate ( ) ) ;
bool doAssert = ! args [ 2 ] - > BooleanValue ( ) ;
T val = static_cast < T > ( args [ 0 ] - > NumberValue ( ) ) ;
size_t offset ;
if ( ! ParseArrayIndex ( args [ 1 ] , 0 , & offset ) ) {
env - > ThrowRangeError ( " out of range index " ) ;
return 0 ;
}
ARGS_THIS ( args [ 0 ] . As < Object > ( ) )
if ( doAssert ) {
size_t len = Length ( args . This ( ) ) ;
if ( offset + sizeof ( T ) > len | | offset + sizeof ( T ) < offset ) {
env - > ThrowRangeError ( " Trying to write beyond buffer length " ) ;
return 0 ;
}
}
T val = args [ 1 ] - > NumberValue ( ) ;
uint32_t offset = args [ 2 ] - > Uint32Value ( ) ;
CHECK_LE ( offset + sizeof ( T ) , obj_length ) ;
union NoAlias {
T val ;
@ -537,8 +516,7 @@ uint32_t WriteFloatGeneric(const FunctionCallbackInfo<Value>& args) {
} ;
union NoAlias na = { val } ;
void * data = args . This ( ) - > GetIndexedPropertiesExternalArrayData ( ) ;
char * ptr = static_cast < char * > ( data ) + offset ;
char * ptr = static_cast < char * > ( obj_data ) + offset ;
if ( endianness ! = GetEndianness ( ) )
Swizzle ( na . bytes , sizeof ( na . bytes ) ) ;
memcpy ( ptr , na . bytes , sizeof ( na . bytes ) ) ;
@ -643,16 +621,6 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
NODE_SET_METHOD ( proto , " ucs2Write " , Ucs2Write ) ;
NODE_SET_METHOD ( proto , " utf8Write " , Utf8Write ) ;
NODE_SET_METHOD ( proto , " readDoubleBE " , ReadDoubleBE ) ;
NODE_SET_METHOD ( proto , " readDoubleLE " , ReadDoubleLE ) ;
NODE_SET_METHOD ( proto , " readFloatBE " , ReadFloatBE ) ;
NODE_SET_METHOD ( proto , " readFloatLE " , ReadFloatLE ) ;
NODE_SET_METHOD ( proto , " writeDoubleBE " , WriteDoubleBE ) ;
NODE_SET_METHOD ( proto , " writeDoubleLE " , WriteDoubleLE ) ;
NODE_SET_METHOD ( proto , " writeFloatBE " , WriteFloatBE ) ;
NODE_SET_METHOD ( proto , " writeFloatLE " , WriteFloatLE ) ;
NODE_SET_METHOD ( proto , " copy " , Copy ) ;
// for backwards compatibility
@ -668,6 +636,16 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
NODE_SET_METHOD ( internal , " byteLength " , ByteLength ) ;
NODE_SET_METHOD ( internal , " compare " , Compare ) ;
NODE_SET_METHOD ( internal , " fill " , Fill ) ;
NODE_SET_METHOD ( internal , " readDoubleBE " , ReadDoubleBE ) ;
NODE_SET_METHOD ( internal , " readDoubleLE " , ReadDoubleLE ) ;
NODE_SET_METHOD ( internal , " readFloatBE " , ReadFloatBE ) ;
NODE_SET_METHOD ( internal , " readFloatLE " , ReadFloatLE ) ;
NODE_SET_METHOD ( internal , " writeDoubleBE " , WriteDoubleBE ) ;
NODE_SET_METHOD ( internal , " writeDoubleLE " , WriteDoubleLE ) ;
NODE_SET_METHOD ( internal , " writeFloatBE " , WriteFloatBE ) ;
NODE_SET_METHOD ( internal , " writeFloatLE " , WriteFloatLE ) ;
}