smalloc: don't allow to dispose typed arrays

PR-URL: https://github.com/joyent/node/pull/8743
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
Vladimir Kurchatkin 2014-11-18 12:30:27 +03:00 committed by Bert Belder
parent 50d7401244
commit f1f511fd22
3 changed files with 10 additions and 0 deletions

View File

@ -88,6 +88,8 @@ function dispose(obj) {
throw new TypeError('obj must be an Object');
if (util.isBuffer(obj))
throw new TypeError('obj cannot be a Buffer');
if (smalloc.isTypedArray(obj))
throw new TypeError('obj cannot be a typed array');
if (!smalloc.hasExternalData(obj))
throw new Error('obj has no external array data');

View File

@ -440,6 +440,9 @@ bool HasExternalData(Environment* env, Local<Object> obj) {
return obj->HasIndexedPropertiesInExternalArrayData();
}
void IsTypedArray(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(args[0]->IsTypedArray());
}
void AllocTruncate(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
@ -540,6 +543,7 @@ void Initialize(Handle<Object> exports,
env->SetMethod(exports, "truncate", AllocTruncate);
env->SetMethod(exports, "hasExternalData", HasExternalData);
env->SetMethod(exports, "isTypedArray", IsTypedArray);
exports->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kMaxLength"),
Uint32::NewFromUnsigned(env->isolate(), kMaxLength));

View File

@ -323,6 +323,10 @@ assert.throws(function() {
smalloc.dispose(new Buffer());
});
assert.throws(function() {
smalloc.dispose(new Uint8Array(new ArrayBuffer(1)));
});
assert.throws(function() {
smalloc.dispose({});
});