brython-dev / brython

Brython (Browser Python) is an implementation of Python 3 running in the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error accessing a value received as a JSArray

benjie-git opened this issue · comments

I'm running head of master brython.
When handling an image paste in the browser, I use the following code but run into a problem:

async def readClipboard():
    items = await context.navigator.clipboard.read()
    for item in items:
        window.zzz = item   # for debugging
        for k in item.types:
            ...
aio.run(readClipboard())

item.types should be usable as a list. But attempting to access it throws:

JavascriptError: TypeError: Cannot define property $is_js_array, object is not extensible

Here's what item looks like on the console:

image

Hum, it seems they add Object.preventExtensions(), cf https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible

It seems the only work-around is to modify the object prototype :

Properties can still be added to the object prototype.

cf https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions

In the commit referenced above, the error when setting the property is ignored. Does this fix the issue ?

Yes, this now works for me!

Thanks!