Skip to content

Commit b353114

Browse files
committed
Fix typedarray bugs
1 parent cd9dea8 commit b353114

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

napi-inl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,9 @@ inline TypedArrayOf<T> TypedArrayOf<T>::New(napi_env env,
10791079
env, type, elementLength, arrayBuffer, bufferOffset, &value);
10801080
if (status != napi_ok) throw Error::New(env);
10811081

1082-
return TypedArrayOf<T>(env, value, type, elementLength, reinterpret_cast<T*>(arrayBuffer.Data()));
1082+
return TypedArrayOf<T>(
1083+
env, value, type, elementLength,
1084+
reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(arrayBuffer.Data()) + bufferOffset));
10831085
}
10841086

10851087
template <typename T>

test/typedarray.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void SetTypedArrayElement(const CallbackInfo& info) {
109109
array.As<Uint8Array>()[index] = static_cast<uint8_t>(value.Uint32Value());
110110
break;
111111
case napi_int16_array:
112-
array.As<Int16Array>()[index] = static_cast<int16_t>(value.Uint32Value());
112+
array.As<Int16Array>()[index] = static_cast<int16_t>(value.Int32Value());
113113
break;
114114
case napi_uint16_array:
115115
array.As<Uint16Array>()[index] = static_cast<uint16_t>(value.Uint32Value());

0 commit comments

Comments
 (0)