Skip to content

Commit

Permalink
Fix Float16Array Proxy get handler to not affect getter properties no…
Browse files Browse the repository at this point in the history
…t related to TypedArray prototype
  • Loading branch information
petamoriken committed Oct 15, 2021
1 parent 2847996 commit 88ff220
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Float16Array.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,26 @@ function copyToArray(float16bitsArray) {

const TypedArrayPrototype = Reflect.getPrototypeOf(Uint8Array).prototype;

const TypedArrayPrototypeGetters = new Set();
for (const key of Reflect.ownKeys(TypedArrayPrototype)) {
const descriptor = Object.getOwnPropertyDescriptor(TypedArrayPrototype, key);
if (hasOwn(descriptor, "get")) {
TypedArrayPrototypeGetters.add(key);
}
}

/** @type {ProxyHandler<Float16Array>} */
const handler = Object.freeze({
get(target, key) {
get(target, key, receiver) {
if (isCanonicalIntegerIndexString(key) && hasOwn(target, key)) {
return convertToNumber(Reflect.get(target, key));
}

return Reflect.get(target, key);
if (TypedArrayPrototypeGetters.has(key)) {
return Reflect.get(target, key);
}

return Reflect.get(target, key, receiver);
},

set(target, key, value) {
Expand Down

0 comments on commit 88ff220

Please sign in to comment.