Proxyable TypedArray

# 森建 (7 years ago)

Proxy of TypedArray doesn't have [[TypedArrayName]] and [[ViewedArrayBuffer]] slots. so probably, 22.2.3.5.1 ValidateTypedArray throws TypeError like following code.

const uint8 = new Uint8Array([1, 2, 3, 4]);

const proxy = new Proxy(uint8, {});

proxy.map(e => e + 1); // -> TypeError

for(const val of proxy) {
   console.log(val); // -> TypeError
}

Is this behavior taken into account?

# 森建 (7 years ago)

I got the solution, but it's puzzled.

const uint8 = new Uint8Array([1, 2, 3, 4]);

const proxy = new Proxy(uint8, {
     get(target, property) {
         const ret = Reflect.get(target, property);
         return typeof ret === "function" ? ret.bind(target) : ret;
     }
});

proxy.map(e => e + 1); // -> Uint8Array [2, 3, 4, 5]

for(const val of proxy) {
     console.log(val); // -> 1, 2, 3, 4
}