From bf3e0f417bbf4ba749730a76dd36a3e59d44da3e Mon Sep 17 00:00:00 2001 From: Vladimir Kurchatkin Date: Tue, 18 Nov 2014 12:30:27 +0300 Subject: [PATCH] smalloc: don't allow to dispose typed arrays PR-URL: https://github.com/joyent/node/pull/8743 Reviewed-by: Trevor Norris --- lib/smalloc.js | 2 ++ src/smalloc.cc | 4 ++++ test/simple/test-smalloc.js | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/lib/smalloc.js b/lib/smalloc.js index fd82ba8..2b4175e 100644 --- a/lib/smalloc.js +++ b/lib/smalloc.js @@ -86,6 +86,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'); diff --git a/src/smalloc.cc b/src/smalloc.cc index c7913d9..7dc3510 100644 --- a/src/smalloc.cc +++ b/src/smalloc.cc @@ -446,6 +446,9 @@ bool HasExternalData(Environment* env, Local obj) { return obj->HasIndexedPropertiesInExternalArrayData(); } +void IsTypedArray(const FunctionCallbackInfo& args) { + args.GetReturnValue().Set(args[0]->IsTypedArray()); +} void AllocTruncate(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); @@ -547,6 +550,7 @@ void Initialize(Handle exports, NODE_SET_METHOD(exports, "truncate", AllocTruncate); NODE_SET_METHOD(exports, "hasExternalData", HasExternalData); + NODE_SET_METHOD(exports, "isTypedArray", IsTypedArray); exports->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kMaxLength"), Uint32::NewFromUnsigned(env->isolate(), kMaxLength)); diff --git a/test/simple/test-smalloc.js b/test/simple/test-smalloc.js index 091f5aa..198b5c7 100644 --- a/test/simple/test-smalloc.js +++ b/test/simple/test-smalloc.js @@ -324,5 +324,9 @@ assert.throws(function() { }); assert.throws(function() { + smalloc.dispose(new Uint8Array(new ArrayBuffer(1))); +}); + +assert.throws(function() { smalloc.dispose({}); }); -- 2.7.4