Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

Uint32Array missing the function subarray()

Open idofr opened this issue 5 years ago • 3 comments

I'm trying to work with a function which calls subarray on a Uint32Array object. This returns an error and it seems that the respective function is not implemented. I've manage to work around the problem with slice, but it creates a copy rather than a pointer. Meaning it only works for me since I'm lucky enough to not have this call in conjunction with an assignment. Yet it also means that I can't really automate the code and i have to keep a hard copy of the script. If it will change in the future on the server side, everything might break

idofr avatar Jun 23 '20 15:06 idofr

You can use polyfills - they will contain implementation of Uint32Array in pure JS.

PiotrDabkowski avatar Jun 23 '20 16:06 PiotrDabkowski

Thanks for the quick response. Could you please elaborate?

idofr avatar Jun 23 '20 16:06 idofr

ctx = js2py.EvalJs()
js2py.require("babel-polyfill", context=ctx._context)
ctx.eval("let arr = new Uint32Array([0, 1, 2, 3, 4])")
ctx.eval("arr.slice(1, 2)")
ctx.eval("arr.subarray(1, 2)")

The polyfill adds Map, complete Uint32Array and other non JS5 features. However, it seems the subarray method for some reason does not work as expected (returns an empty array) even though it is now defined. Slice does work. Can you try patching this method manually?

PiotrDabkowski avatar Jun 24 '20 07:06 PiotrDabkowski