Browse Source

smalloc: update use of ExternalArrayType constants

The constants in enum v8::ExternalArrayType have been changed. The old
values are there for legacy reasons, but it's best to update anyway.

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
v0.11.15-release
Trevor Norris 10 years ago
parent
commit
4809c7aa4f
  1. 3
      lib/smalloc.js
  2. 18
      src/smalloc.cc

3
lib/smalloc.js

@ -37,6 +37,7 @@ Object.defineProperty(exports, 'kMaxLength', {
// enumerated values for different external array types
var Types = {};
// Must match enum v8::ExternalArrayType.
Object.defineProperties(Types, {
'Int8': { enumerable: true, value: 1, writable: false },
'Uint8': { enumerable: true, value: 2, writable: false },
@ -68,7 +69,7 @@ function alloc(n, obj, type) {
throw new TypeError('obj must be an Object');
}
// 1 == v8::kExternalByteArray, 9 == v8::kExternalPixelArray
// 1 == v8::kExternalUint8Array, 9 == v8::kExternalUint8ClampedArray
if (type < 1 || type > 9)
throw new TypeError('unknown external array type: ' + type);
if (util.isArray(obj))

18
src/smalloc.cc

@ -147,23 +147,23 @@ void CallbackInfo::WeakCallback(Isolate* isolate, Local<Object> object) {
// return size of external array type, or 0 if unrecognized
size_t ExternalArraySize(enum ExternalArrayType type) {
switch (type) {
case v8::kExternalUnsignedByteArray:
case v8::kExternalUint8Array:
return sizeof(uint8_t);
case v8::kExternalByteArray:
case v8::kExternalInt8Array:
return sizeof(int8_t);
case v8::kExternalShortArray:
case v8::kExternalInt16Array:
return sizeof(int16_t);
case v8::kExternalUnsignedShortArray:
case v8::kExternalUint16Array:
return sizeof(uint16_t);
case v8::kExternalIntArray:
case v8::kExternalInt32Array:
return sizeof(int32_t);
case v8::kExternalUnsignedIntArray:
case v8::kExternalUint32Array:
return sizeof(uint32_t);
case v8::kExternalFloatArray:
case v8::kExternalFloat32Array:
return sizeof(float); // NOLINT(runtime/sizeof)
case v8::kExternalDoubleArray:
case v8::kExternalFloat64Array:
return sizeof(double); // NOLINT(runtime/sizeof)
case v8::kExternalPixelArray:
case v8::kExternalUint8ClampedArray:
return sizeof(uint8_t);
}
return 0;

Loading…
Cancel
Save