From 9ad2057694c878cdb569dbefbf5ebf9f97d26cd7 Mon Sep 17 00:00:00 2001 From: Taylor Woll Date: Wed, 1 Mar 2017 16:20:35 -0800 Subject: [PATCH 1/2] napi_is_buffer should not return error when called with a non-TypedArray --- src/node_jsrtapi.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node_jsrtapi.cc b/src/node_jsrtapi.cc index a2b8650578..8ece4a3add 100644 --- a/src/node_jsrtapi.cc +++ b/src/node_jsrtapi.cc @@ -1358,8 +1358,14 @@ napi_status napi_create_buffer_copy(napi_env e, napi_status napi_is_buffer(napi_env e, napi_value v, bool* result) { CHECK_ARG(result); JsValueRef typedArray = reinterpret_cast(v); + JsValueType objectType; + CHECK_JSRT(JsGetValueType(typedArray, &objectType)); + if (objectType != JsTypedArray) { + *result = false; + return napi_ok; + } JsTypedArrayType arrayType; - CHECK_JSRT(JsGetTypedArrayInfo(typedArray, &arrayType, nullptr, nullptr, nullptr)); + JsErrorCode code = JsGetTypedArrayInfo(typedArray, &arrayType, nullptr, nullptr, nullptr); *result = (arrayType == JsArrayTypeUint8); return napi_ok; } From 2bb22e08cc88e19be122b5df1b6b20f942c42493 Mon Sep 17 00:00:00 2001 From: Taylor Woll Date: Wed, 1 Mar 2017 16:23:43 -0800 Subject: [PATCH 2/2] Remove unused erorr code variable --- src/node_jsrtapi.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_jsrtapi.cc b/src/node_jsrtapi.cc index 8ece4a3add..bc69aeb2a7 100644 --- a/src/node_jsrtapi.cc +++ b/src/node_jsrtapi.cc @@ -1365,7 +1365,7 @@ napi_status napi_is_buffer(napi_env e, napi_value v, bool* result) { return napi_ok; } JsTypedArrayType arrayType; - JsErrorCode code = JsGetTypedArrayInfo(typedArray, &arrayType, nullptr, nullptr, nullptr); + CHECK_JSRT(JsGetTypedArrayInfo(typedArray, &arrayType, nullptr, nullptr, nullptr)); *result = (arrayType == JsArrayTypeUint8); return napi_ok; }