Giter Club home page Giter Club logo

pythonmonkey's Issues

import error: module not found

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

WSL - Ubuntu 23.04

Python version (python --version)

3.8.15

PythonMonkey version (pip show pythonmonkey)

0.2.2

Bug Description

I typed

from pythonmonkey import eval as js_eval,

it returns

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>
  File "/home/bruce/.pyenv/versions/miniforge3-4.10.1-5/lib/python3.8/site-packages/pythonmonkey/__init__.py", line 16, in <module>
    require("url")
  File "/home/bruce/.pyenv/versions/miniforge3-4.10.1-5/lib/python3.8/site-packages/pythonmonkey/require.py", line 353, in require
    return createRequire(filename)(moduleIdentifier)
pythonmonkey.SpiderMonkeyError: Error in file /home/bruce/.pyenv/versions/miniforge3-4.10.1-5/lib/python3.8/site-packages/pythonmonkey/node_modules/ctx-module/ctx-module.js, on line 236:
Error: module not found -- require('core-js/actual/dom-exception') from /home/bruce/.pyenv/versions/miniforge3-4.10.1-5/lib/python3.8/site-packages/pythonmonkey/builtin_modules/dom-exception.js
Stack Trace:
  ctxRequire@/home/bruce/.pyenv/versions/miniforge3-4.10.1-5/lib/python3.8/site-packages/pythonmonkey/node_modules/ctx-module/ctx-module.js:120:7

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

Conda version: 23.9.0
nodejs version: 6.13.1

What branch of PythonMonkey were you developing on? (If applicable)

No response

Segfault in InternalCallOrConstruct when using pmjs event-loop

PythonMonkey Version: 68dca85
Repro: ./pmjs tests/js/timers-segfault.simple.failing

Note that I am using the node-style event-loop events implemented in Python, not the standards-compliant ones implemented in C++

This problem is probably not related to the events code, but rather, the events code is setting up a bug in PythonMonkey.

(gdb) run ../../pmjs timers-segfault.simple.failing 
Starting program: /home/wes/.cache/pypoetry/virtualenvs/pythonmonkey-NiDIb4WW-py3.10/bin/python ../../pmjs timers-segfault.simple.failing
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff3dff640 (LWP 1070684)]
[Thread 0x7ffff3dff640 (LWP 1070684) exited]
[New Thread 0x7ffff35fe640 (LWP 1070685)]
[New Thread 0x7ffff33ff640 (LWP 1070686)]
[New Thread 0x7ffff3200640 (LWP 1070687)]
[New Thread 0x7ffff3001640 (LWP 1070688)]
[New Thread 0x7ffff2e02640 (LWP 1070689)]
[New Thread 0x7ffff2c03640 (LWP 1070690)]
[New Thread 0x7ffff2a04640 (LWP 1070691)]
[New Thread 0x7ffff2805640 (LWP 1070692)]

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007ffff4355d43 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
(gdb) bt
#0  0x00007ffff4355d43 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#1  0x00007ffff4356817 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#2  0x00007ffff43edeb7 in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#3  0x00007ffff6704df8 in callJSFunc (jsCxThisFuncTuple=<optimized out>, args=<optimized out>) at /usr/local/include/mozjs-102/js/RootingAPI.h:1216
#4  0x00005555556b0cc8 in cfunction_call (func=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2440f80>, args=<optimized out>, kwargs=<optimized out>)
    at ../Objects/methodobject.c:552
#5  0x00005555556a772b in _PyObject_MakeTpCall (tstate=0x555555b5c2e0, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2440f80>, args=<optimized out>, 
    nargs=<optimized out>, keywords=0x0) at ../Objects/call.c:215
#6  0x000055555583e682 in context_run (self=0x7ffff2440c40, args=0x7ffff2445348, nargs=1, kwnames=0x0) at ../Python/context.c:665
#7  0x00005555556a462b in cfunction_vectorcall_FASTCALL_KEYWORDS (func=<built-in method run of _contextvars.Context object at remote 0x7ffff2440c40>, args=0x7ffff2445348, 
    nargsf=<optimized out>, kwnames=0x0) at ../Objects/methodobject.c:446
#8  0x000055555569bd87 in do_call_core (kwdict=0x0, callargs=(<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2440f80>,), 
    func=<built-in method run of _contextvars.Context object at remote 0x7ffff2440c40>, trace_info=0x7fffffffdbc0, tstate=<optimized out>) at ../Python/ceval.c:5943
#9  _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4277
#10 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x7ffff6b7b490, for file /usr/lib/python3.10/asyncio/events.py, line 80, in _run (self=<TimerHandle at remote 0x7ffff24363b0>), tstate=0x555555b5c2e0)
    at ../Include/internal/pycore_ceval.h:46
#11 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff6783f50, tstate=0x555555b5c2e0) at ../Python/ceval.c:5065
#12 _PyFunction_Vectorcall (func=<function at remote 0x7ffff6783f40>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#13 0x0000555555699c14 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x555555f49210, callable=<function at remote 0x7ffff6783f40>, tstate=0x555555b5c2e0)
    at ../Include/cpython/abstract.h:114
#14 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x555555f49210, callable=<function at remote 0x7ffff6783f40>) at ../Include/cpython/abstract.h:123
#15 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffdd90, tstate=<optimized out>) at ../Python/ceval.c:5891
#16 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4198
#17 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x555555f49040, for file /usr/lib/python3.10/asyncio/base_events.py, line 1896, in _run_once (self=<_UnixSelectorEventLoop(_timer_cancelled_count=0, _closed=False, _stopping=False, _ready=<collections.deque at remote 0x7ffff243a500>, _scheduled=[], _default_executor=None, _internal_fds=1, _thread_id=140737352511488, _clock_resolution=<float at remote 0x7ffff25be990>, _exception_handler=None, _debug=False, slow_callback_duration=<float at remote 0x7ffff6dfdb90>, _current_handle=None, _task_factory=None, _coroutine_origin_tracking_enabled=False, _coroutine_origin_tracking_saved_depth=None, _asyncgens=<WeakSet(data=set(), _remove=<function at remote 0x7ffff2429c60>, _pending_removals=[], _iterating=set()) at remote 0x7ffff24453c0>, _asyncgens_shutdown_called=False, _executor_shutdown_called=False, _selector=<EpollSelector(_fd_to_key={4: <SelectorKey at remote 0x7ffff2448950>}, _map=<_SelectorMapping(_selector=<...>) at remote 0x7ffff2445480>, _selector=<select.epoll at remote 0x7ffff25bec10>) at remote 0x7...(truncated), tstate=0x555555b5c2e0) at ../Include/internal/pycore_ceval.h:46
#18 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff6120560, tstate=0x555555b5c2e0) at ../Python/ceval.c:5065
#19 _PyFunction_Vectorcall (func=<function at remote 0x7ffff6120550>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#20 0x0000555555699c14 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff2562d38, callable=<function at remote 0x7ffff6120550>, tstate=0x555555b5c2e0)
    at ../Include/cpython/abstract.h:114
#21 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff2562d38, callable=<function at remote 0x7ffff6120550>) at ../Include/cpython/abstract.h:123
#22 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffdf60, tstate=<optimized out>) at ../Python/ceval.c:5891
#23 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4198
#24 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x7ffff2562bc0, for file /usr/lib/python3.10/asyncio/base_events.py, line 600, in run_forever (self=<_UnixSelectorEventLoop(_timer_cancelled_count=0, _closed=False, _stopping=False, _ready=<collections.deque at remote 0x7ffff243a500>, _scheduled=[], _default_executor=None, _internal_fds=1, _thread_id=140737352511488, _clock_resolution=<float at remote 0x7f--Type <RET> for more, q to quit, c to continue without paging--
fff25be990>, _exception_handler=None, _debug=False, slow_callback_duration=<float at remote 0x7ffff6dfdb90>, _current_handle=None, _task_factory=None, _coroutine_origin_tracking_enabled=False, _coroutine_origin_tracking_saved_depth=None, _asyncgens=<WeakSet(data=set(), _remove=<function at remote 0x7ffff2429c60>, _pending_removals=[], _iterating=set()) at remote 0x7ffff24453c0>, _asyncgens_shutdown_called=False, _executor_shutdown_called=False, _selector=<EpollSelector(_fd_to_key={4: <SelectorKey at remote 0x7ffff2448950>}, _map=<_SelectorMapping(_selector=<...>) at remote 0x7ffff2445480>, _selector=<select.epoll at remote 0x7ffff25bec10>) at remote 0x...(truncated), tstate=0x555555b5c2e0) at ../Include/internal/pycore_ceval.h:46
#25 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff611e9f0, tstate=0x555555b5c2e0) at ../Python/ceval.c:5065
#26 _PyFunction_Vectorcall (func=<function at remote 0x7ffff611e9e0>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#27 0x0000555555699c14 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x555555f0b430, callable=<function at remote 0x7ffff611e9e0>, tstate=0x555555b5c2e0)
    at ../Include/cpython/abstract.h:114
#28 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x555555f0b430, callable=<function at remote 0x7ffff611e9e0>) at ../Include/cpython/abstract.h:123
#29 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe130, tstate=<optimized out>) at ../Python/ceval.c:5891
#30 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4198
#31 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x555555f0b240, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 367, in main (enterRepl=True, forceRepl=False, opts=[], output=None, verbose=False, ela={'enqueueWithDelay': <function at remote 0x7ffff24296c0>, 'enqueue': <function at remote 0x7ffff2429870>, 'cancelTimer': <function at remote 0x7ffff2429900>, 'getLoop': <function at remote 0x7ffff2429990>, 'setLoop': <function at remote 0x7ffff2429a20>, 'makeLoop': <function at remote 0x7ffff2429ab0>, 'endLoop': <function at remote 0x7ffff2429b40>}, loop=<_UnixSelectorEventLoop(_timer_cancelled_count=0, _closed=False, _stopping=False, _ready=<collections.deque at remote 0x7ffff243a500>, _scheduled=[], _default_executor=None, _internal_fds=1, _thread_id=140737352511488, _clock_resolution=<float at remote 0x7ffff25be990>, _exception_handler=None, _debug=False, slow_callback_duration=<float at remote 0x7ffff6dfdb90>, _current_handle=None, _task_factory=None, _coroutine_origin_tracking_enabled=False, _coroutine_origin_tracking_saved_depth=None,...(truncated), tstate=0x555555b5c2e0) at ../Include/internal/pycore_ceval.h:46
#32 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff24295b0, tstate=0x555555b5c2e0) at ../Python/ceval.c:5065
#33 _PyFunction_Vectorcall (func=<function at remote 0x7ffff24295a0>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#34 0x0000555555699a1d in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff24295a0>, tstate=0x555555b5c2e0)
    at ../Include/cpython/abstract.h:114
#35 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff24295a0>) at ../Include/cpython/abstract.h:123
#36 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe300, tstate=<optimized out>) at ../Python/ceval.c:5891
#37 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4213
#38 0x0000555555696176 in _PyEval_EvalFrame (throwflag=0, f=Frame 0x7ffff6d29c40, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 374, in <module> (), 
    tstate=0x555555b5c2e0) at ../Include/internal/pycore_ceval.h:46
#39 _PyEval_Vector (tstate=0x555555b5c2e0, con=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=<optimized out>)
    at ../Python/ceval.c:5065
#40 0x000055555578bc56 in PyEval_EvalCode (co=<code at remote 0x7ffff6c9f680>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c247c0>, 'readline': <module at remote 0x7ffff6cc9a30>, 'signal': <module at remote 0x7ffff6cca890>, 'getopt': <module at remote 0x7ffff6ccab10>, 'asyncio': <module at remote 0x7ffff6add990>, 'pm': <module at remote 0x7ffff610b560>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff24293f0>, 'initGlobalThis': <function at remote 0x7ffff2429510>, 'main': <function at remote 0x7ffff24295a0>}, locals=<optimized out>) at ../Python/ceval.c:1134
#41 0x00005555557b8b18 in run_eval_code_obj (tstate=0x555555b5c2e0, co=0x7ffff6c9f680, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c247c0>, 'readline': <module at remote 0x7ffff6cc9a30>, 'signal': <module at remote 0x7ffff6cca890>, 'getopt': <module at remote 0x7ffff6ccab10>, 'asyncio': <module at remote 0x7ffff6add990>, 'pm': <module at remote 0x7ffff610b560>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff24293f0>, 'initGlobalThis': <function at remote 0x7ffff2429510>, 'main': <function at remote 0x7ffff24295a0>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remo--Type <RET> for more, q to quit, c to continue without paging--
te 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c247c0>, 'readline': <module at remote 0x7ffff6cc9a30>, 'signal': <module at remote 0x7ffff6cca890>, 'getopt': <module at remote 0x7ffff6ccab10>, 'asyncio': <module at remote 0x7ffff6add990>, 'pm': <module at remote 0x7ffff610b560>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff24293f0>, 'initGlobalThis': <function at remote 0x7ffff2429510>, 'main': <function at remote 0x7ffff24295a0>}) at ../Python/pythonrun.c:1291
#42 0x00005555557b196b in run_mod (mod=<optimized out>, filename=<optimized out>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c247c0>, 'readline': <module at remote 0x7ffff6cc9a30>, 'signal': <module at remote 0x7ffff6cca890>, 'getopt': <module at remote 0x7ffff6ccab10>, 'asyncio': <module at remote 0x7ffff6add990>, 'pm': <module at remote 0x7ffff610b560>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff24293f0>, 'initGlobalThis': <function at remote 0x7ffff2429510>, 'main': <function at remote 0x7ffff24295a0>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c247c0>, 'readline': <module at remote 0x7ffff6cc9a30>, 'signal': <module at remote 0x7ffff6cca890>, 'getopt': <module at remote 0x7ffff6ccab10>, 'asyncio': <module at remote 0x7ffff6add990>, 'pm': <module at remote 0x7ffff610b560>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff24293f0>, 'initGlobalThis': <function at remote 0x7ffff2429510>, 'main': <function at remote 0x7ffff24295a0>}, flags=<optimized out>, arena=<optimized out>) at ../Python/pythonrun.c:1312
#43 0x00005555557b8865 in pyrun_file (fp=fp@entry=0x555555b5e6b0, filename=filename@entry='/home/wes/git/PythonMonkey/tests/js/../../pmjs', start=start@entry=257, 
    globals=globals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c247c0>, 'readline': <module at remote 0x7ffff6cc9a30>, 'signal': <module at remote 0x7ffff6cca890>, 'getopt': <module at remote 0x7ffff6ccab10>, 'asyncio': <module at remote 0x7ffff6add990>, 'pm': <module at remote 0x7ffff610b560>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff24293f0>, 'initGlobalThis': <function at remote 0x7ffff2429510>, 'main': <function at remote 0x7ffff24295a0>}, 
    locals=locals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c247c0>, 'readline': <module at remote 0x7ffff6cc9a30>, 'signal': <module at remote 0x7ffff6cca890>, 'getopt': <module at remote 0x7ffff6ccab10>, 'asyncio': <module at remote 0x7ffff6add990>, 'pm': <module at remote 0x7ffff610b560>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff24293f0>, 'initGlobalThis': <function at remote 0x7ffff2429510>, 'main': <function at remote 0x7ffff24295a0>}, closeit=closeit@entry=1, flags=0x7fffffffe5a8) at ../Python/pythonrun.c:1208
#44 0x00005555557b7d48 in _PyRun_SimpleFileObject (fp=0x555555b5e6b0, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', closeit=1, flags=0x7fffffffe5a8)
    at ../Python/pythonrun.c:456
#45 0x00005555557b7a43 in _PyRun_AnyFileObject (fp=0x555555b5e6b0, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', closeit=1, flags=0x7fffffffe5a8)
    at ../Python/pythonrun.c:90
#46 0x00005555557a8c3e in pymain_run_file_obj (skip_source_first_line=0, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', 
    program_name='/home/wes/.cache/pypoetry/virtualenvs/pythonmonkey-NiDIb4WW-py3.10/bin/python') at ../Modules/main.c:353
#47 pymain_run_file (config=0x555555b406d0) at ../Modules/main.c:372
#48 pymain_run_python (exitcode=0x7fffffffe5a4) at ../Modules/main.c:587
#49 Py_RunMain () at ../Modules/main.c:666
#50 0x000055555577ebcd in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at ../Modules/main.c:720
#51 0x00007ffff7c29d90 in __libc_start_call_main (main=main@entry=0x55555577eb90 <main>, argc=argc@entry=3, argv=argv@entry=0x7fffffffe7b8) at ../sysdeps/nptl/libc_start_call_main.h:58
#52 0x00007ffff7c29e40 in __libc_start_main_impl (main=0x55555577eb90 <main>, argc=3, argv=0x7fffffffe7b8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffffffe7a8) at ../csu/libc-start.c:392
--Type <RET> for more, q to quit, c to continue without paging--
#53 0x000055555577eac5 in _start ()

(gdb) info threads
  Id   Target Id                                       Frame 
* 1    Thread 0x7ffff7e73000 (LWP 1070681) "python"    0x00007ffff4355d43 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
  3    Thread 0x7ffff35fe640 (LWP 1070685) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d32534)
    at ./nptl/futex-internal.c:57
  4    Thread 0x7ffff33ff640 (LWP 1070686) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d32534)
    at ./nptl/futex-internal.c:57
  5    Thread 0x7ffff3200640 (LWP 1070687) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d32530)
    at ./nptl/futex-internal.c:57
  6    Thread 0x7ffff3001640 (LWP 1070688) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d32530)
    at ./nptl/futex-internal.c:57
  7    Thread 0x7ffff2e02640 (LWP 1070689) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d32530)
    at ./nptl/futex-internal.c:57
  8    Thread 0x7ffff2c03640 (LWP 1070690) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d32530)
    at ./nptl/futex-internal.c:57
  9    Thread 0x7ffff2a04640 (LWP 1070691) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d32530)
    at ./nptl/futex-internal.c:57
  10   Thread 0x7ffff2805640 (LWP 1070692) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d32534)
    at ./nptl/futex-internal.c:57
(gdb) 

Add `.new` Method to JavaScript Clases

Describe your feature request here.

Class.new

Feature Request: add a new static method to classes exposed to Python to instantiate JavaScript classes.
Code example:

import pythonmonkey as pm
JsDateClass = pm.Date

myDate = JsDateClass.new(0) # in JS this would look like: myDate = new JsDateClass(0);

Relevant Context

Unlike JavaScript, Python doesn't use the new keyword (or anything like it) for instantiating classes. For example:

class SomeClass:
    pass
obj = SomeClass()

However, JavaScript "classes" may require the new keyword to properly setup the object. ES6 classes will throw an error if not instantiated with new.

So we needed to provide a way for Python to instantiate JavaScript classes and chose to add a new function to the PythonMonkey api which returns a function wrapper for the constructor function which can be used to instantiate the class as if it were called with new. See the relevant ticket here: #144

This topic was debated in the TC39 forums here: https://es.discourse.group/t/function-prototype-new/1772 ; however, the community does not appear to be very unified on this subject. @WebReflection suggested adding Class.new to the JS spec

Pyodide uses Class.new to solve this, refer to the Pyodide documentation here: https://pyodide.org/en/stable/usage/api/python-api/ffi.html#pyodide.ffi.JsProxy.new

  • PythonMonkey should have a similar API spec to Pyodide
  • These products will likely be used together for instance with PythonMonkey on the server and Pyodide in the browser

Code example

import pythonmonkey as pm

myDate = pm.Date.new(0)

Segmentation fault error,but window 10 no this error,window can not find npm module even if installed

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

debian 11, windows 10

Python version (python --version)

3.8

PythonMonkey version (pip show pythonmonkey)

0.2.1

Bug Description

my js code

var a = 1;

function add(x, y) {
    a += x * y
    return a
}

function change(x) {
    a = x
    return a
}

module.exports = {add, change}

Segmentation fault error,but window 10 no this error,window can not find npm module even if installed

import pythonmonkey as pm

d = pm.require('./demo')
for i in range(10000):
    print(i, d.add(1, 5))

change this can not exist progress

import pythonmonkey as pm

for i in range(10000):
    d = pm.require('./demo')
    print(i, d.add(1, 5))

only change this is expected

import pythonmonkey as pm

add = pm.require('./demo').add
for i in range(10000):
    print(i, add(1, 5))

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

main

toString() might be broken sometimes

I was testing PythonMonkey with the CryptoJS NPM package and noticed calling toString() on the objects returned from it would yield empty strings. Refer to this example to reproduce it:


In Python:

(Pdb) CryptoJS.SHA256("hello").toString()
''

^ when ran in Python, it just returns an empty string

In JavaScript

> CryptoJS.SHA256("hello").toString()
'2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'

@wesgarland suggested "we're probably calling toString on the wrong this"

Windows paths not supported by ctx-module

The module system does not understand windows paths, in particular, absolute paths.

We need to fix that.

@Xmader has done some work-arounds at the PythonMonkey level but a long-term solution needs to be addressed at the root.

Function proxies should return the underlying function rather than wrapping it in another function proxy

Currently, when a python function is passed to JS it gets wrapped in a JS function in jsTypeFactory.hh called callPyFunc. If JS then returns that function back to python, it wraps it in a python function in pyTypeFactory.hh called callJSFunc. A similar thing happens in the other direction when starting with a JS function.

What should happen is that when a wrapped python function is returned back to python, it gets unwrapped and the original function is passed back. Conversely, when a wrapped JS function is returned back to JS, it should get unwrapped and the original function passed back.

As an example, the following should be able to pass:

import pythonmonkey as pm
def pyFunc():
  return 0
unwrappedPyFunc = pm.eval("(wrappedPyFunc) => { return wrappedPyFunc; }")(pyFunc)
assert unwrappedPyFunc is pyFunc
import pythonmonkey as pm
wrappedJSFunc = pm.eval(" const JSFunc = () => { return 0; };\nJSFunc;")
assert pm.eval("(unwrappedJSFunc) => { return unwrappedJSFunc === JSFunc; }")(wrappedJSFunc)

Need opaque type wrapper

TypeError: pythonmonkey cannot yet convert python objects of type: _UnixSelectorEventLoop

I can get around these by dict-wrapping, but I think it would be better to have a JS type that functions as some kind of arbitrary opaque type wrapper that can be used to deliver values to/from Python, and to use it automatically in cases like this.

JS’s classes cannot be used correctly in python

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

Windows 11

Python version (python --version)

3.10

PythonMonkey version (pip show pythonmonkey)

0.2.1

Bug Description

When python calls js, it is not possible to modify the properties of a class through its methods.

consult:How to instantiate JS's classes in python?

Standalone code to reproduce the issue

//JS code
class Runoob {
  constructor(name, url) {
    this.name = name;
    this.url = url;
  }
  setname(name)
  {
      this.name = name;
      console.log("box");
      return this.name;
  }
}
//first Type:transmit the class
module.exports = Runoob

//secend Type: Create an instance pass an instance
pepole = new Runoob("ddd","www.baidu.com")

************
#python code


import pythonmonkey as pm

pep =pm.require("./pyreadjs")
#first Type Error:TypeError: class constructors must be invoked with 'new'

pep("ddd","www.baidu.com")
# but can't code like this:
#test = new pep("ddd","www.baidu.com")

print(pep.setname("test")) #can return OK
print(pep.name)     #NOT CHANGE

Relevant log output or backtrace

pythonmonkey.SpiderMonkeyError: TypeError: class constructors must be invoked with 'new'

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Python -> JS Dict/Object Output causes segfault

Description

When exporting a dictionary from Python, requiring it in JavaScript and then running the JS file with PythonMonkey, trying to print it results in a segfault.
Ideally, users should probably be able to print out a dictionary exported from Python in JavaScript.
Attempting to JSON.stringify() said dict also doesn't work, and it probably should assuming that the intention is to have Python Dictionaries be almost indistinguishable from JavaScript objects.

Repro

This has a couple of files, bear with me...

# main.py
import sys, os
import pythonmonkey as pm

require = pm.createRequire(__file__)
require('./pm.js')
# objects.py

def normalDict():
  b_dict = {}

  for i in range(0, 10):
    b_dict[i] = i

  return b_dict

exports['normal_dict'] = normalDict
// pm.js
const { normal_dict } = require('./monkey.py');

let a = normal_dict()
console.log(Object.keys(a).length);
console.log(JSON.stringify(a)); # returns undefined
console.log(a); # segfault

Run main.py, and you will find that the returns are:

10
{}
Segmentation fault (core dumped)

When Py->JS->Py throws, JS cannot catch

Simple repro (needs PR73 for .python command):

Welcome to PythonMonkey v0.0.1.dev940+6a2563b.
Type ".help" for more information.
> .python asdlfkj
Traceback (most recent call last):
  File "/home/wes/git/pythonmonkey2/./pmjs", line 342, in <module>
    main()
  File "/home/wes/git/pythonmonkey2/./pmjs", line 339, in main
    repl()
  File "/home/wes/git/pythonmonkey2/./pmjs", line 224, in repl
    cmd_output = globalThis.replCmd(statement[1:]);
  File "<string>", line 1, in <module>
NameError: name 'asdlfkj' is not defined
[~/git/pythonmonkey2] bergelmir:wes# 

This NameError exception should have been caught by JS.

@Xmader says "Probably we need to change something in https://github.com/Distributive-Network/PythonMonkey/blob/main/src/setSpiderMonkeyException.cc"

@caleb-distributive says "
python-monkey–Jul 9thView in channel
We should be able to get this to work, we would need to check if a python exception has occurred when executing a python function from a wrapper with if (PyErr_Occured()) , and if it has then set an exception for Spidermonkey and remove the exception from the python side (and mirror this behaviour when calling JS functions through python wrappers).
I'll be handling this problem as part of handling PM-59 and PM-58"

Rooting assertion when using setTimeout in pmjs repl

As with issue-112, this is for the node-like ref'd events loop timers, not the standards-compliants that were written in C++.

Version: 398f2ed
Branch: wes/issue-113-repro
Repro: echo 'setTimeout(()=>1)' | ../../pmjs -i

Reading symbols from /usr/lib/debug/.build-id/a6/73a1e2b7a7287c1908dec1a748642e2c02392d.debug...
(gdb) run ../../pmjs
Starting program: /home/wes/.cache/pypoetry/virtualenvs/pythonmonkey-NiDIb4WW-py3.10/bin/python ../../pmjs
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff3dff640 (LWP 1073158)]
[Thread 0x7ffff3dff640 (LWP 1073158) exited]
[New Thread 0x7ffff35fe640 (LWP 1073159)]
[New Thread 0x7ffff33ff640 (LWP 1073160)]
[New Thread 0x7ffff3200640 (LWP 1073161)]
[New Thread 0x7ffff3001640 (LWP 1073162)]
[New Thread 0x7ffff2e02640 (LWP 1073163)]
[New Thread 0x7ffff2c03640 (LWP 1073164)]
[New Thread 0x7ffff2a04640 (LWP 1073165)]
[New Thread 0x7ffff2805640 (LWP 1073166)]
Welcome to PythonMonkey v0.0.1.dev1058+116e777.
Type ".help" for more information.
> setTimeout(()=>1)

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007ffff66faf6a in JS::Rooted<JS::Value>::~Rooted (this=0x7fffffffd4b8, __in_chrg=<optimized out>) at /usr/local/include/mozjs-102/js/RootingAPI.h:1192
1192	    MOZ_ASSERT(*this->stack == this);
(gdb) bt
#0  0x00007ffff66faf6a in JS::Rooted<JS::Value>::~Rooted (this=0x7fffffffd4b8, __in_chrg=<optimized out>) at /usr/local/include/mozjs-102/js/RootingAPI.h:1192
#1  idToKey (cx=<optimized out>, id=...) at /home/wes/git/PythonMonkey/src/PyProxyHandler.cc:37
#2  0x00007fffffffd558 in ?? ()
#3  0x00007ffff43a79dc in js::GetOwnPropertyDescriptorToArray(JSContext*, unsigned int, JS::Value*) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#4  0x00007ffff4355ed9 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#5  0x00007ffff43501a4 in Interpret(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#6  0x00007ffff434731a in js::RunScript(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#7  0x00007ffff43561cf in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#8  0x00007ffff4356817 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#9  0x00007ffff43edeb7 in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#10 0x00007ffff6704df8 in callJSFunc (jsCxThisFuncTuple=<optimized out>, args=<optimized out>) at /usr/local/include/mozjs-102/js/RootingAPI.h:1216
#11 0x00005555556b0cc8 in cfunction_call (func=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2440b40>, args=<optimized out>, kwargs=<optimized out>)
    at ../Objects/methodobject.c:552
#12 0x00005555556a772b in _PyObject_MakeTpCall (tstate=0x555555b5bf80, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2440b40>, args=<optimized out>, 
    nargs=<optimized out>, keywords=0x0) at ../Objects/call.c:215
#13 0x00005555556a00e7 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=<optimized out>, 
    callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2440b40>, tstate=<optimized out>) at ../Include/cpython/abstract.h:112
#14 _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x555555e97948, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2440b40>, 
    tstate=<optimized out>) at ../Include/cpython/abstract.h:99
#15 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x555555e97948, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2440b40>)
    at ../Include/cpython/abstract.h:123
#16 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffdf80, tstate=<optimized out>) at ../Python/ceval.c:5891
#17 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4181
#18 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x555555e97770, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 236, in repl (save_history=<function at remote 0x7ffff2429ea0>, atexit=<module at remote 0x7ffff6944f40>, sigint_handler=<function at remote 0x7ffff2429fc0>), tstate=0x555555b5bf80) at ../Include/internal/pycore_ceval.h:46
#19 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff6c65eb0, tstate=0x555555b5bf80) at ../Python/ceval.c:5065
#20 _PyFunction_Vectorcall (func=<function at remote 0x7ffff6c65ea0>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#21 0x0000555555699a1d in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x555555f03280, callable=<function at remote 0x7ffff6c65ea0>, tstate=0x555555b5bf80)
    at ../Include/cpython/abstract.h:114
#22 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x555555f03280, callable=<function at remote 0x7ffff6c65ea0>) at ../Include/cpython/abstract.h:123
#23 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe150, tstate=<optimized out>) at ../Python/ceval.c:5891
#24 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4213
#25 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x555555f03090, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 371, in main (ela={'enqueueWithDelay': <function at remote 0x7ffff2429750>, 'enqueue': <function at remote 0x7ffff2429900>, 'cancelTimer': <function at remote 0x7ffff2429990>, 'getLoop': <function at remote 0x7ffff2429a20>, 'setLoop': <function at remote 0x7ffff2429ab0>, 'makeLoop': <function at remote 0x7ffff2429b40>, 'endLoop': <function at remote 0x7ffff2429bd0>}, loop=<_UnixSelectorEventLoop(_timer_cancelled_count=0, _closed=False, _stopping=False, _ready=<collections.deque at remote 0x7ffff243a4a0>, _scheduled=[], _default_executor=None, _internal_fds=1, _thread_id=None, _clock_resolution=<float at remote 0x7ffff25beaf0>, _exception_handler=None, _debug=False, slow_callback_duration=<float at remote 0x7ffff6dfdb70>, _current_handle=None, _task_factory=None, _coroutine_origin_tracking_enabled=False, _coroutine_origin_tracking_saved_depth=None, _asyncgens=<WeakSet(data=set(), _remove=<function at remote 0x7ffff2429cf0>, _pe...(truncated), tstate=0x555555b5bf80) at ../Include/internal/pycore_ceval.h:46
--Type <RET> for more, q to quit, c to continue without paging--
#26 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff2429640, tstate=0x555555b5bf80) at ../Python/ceval.c:5065
#27 _PyFunction_Vectorcall (func=<function at remote 0x7ffff2429630>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#28 0x0000555555699a1d in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff2429630>, tstate=0x555555b5bf80)
    at ../Include/cpython/abstract.h:114
#29 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff2429630>) at ../Include/cpython/abstract.h:123
#30 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe320, tstate=<optimized out>) at ../Python/ceval.c:5891
#31 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4213
#32 0x0000555555696176 in _PyEval_EvalFrame (throwflag=0, f=Frame 0x7ffff6d29c40, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 374, in <module> (), 
    tstate=0x555555b5bf80) at ../Include/internal/pycore_ceval.h:46
#33 _PyEval_Vector (tstate=0x555555b5bf80, con=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=<optimized out>)
    at ../Python/ceval.c:5065
#34 0x000055555578bc56 in PyEval_EvalCode (co=<code at remote 0x7ffff6c9f680>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd990>, 'signal': <module at remote 0x7ffff6cce7f0>, 'getopt': <module at remote 0x7ffff6ccea70>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff6b0cfe0>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff2429480>, 'initGlobalThis': <function at remote 0x7ffff24295a0>, 'main': <function at remote 0x7ffff2429630>}, locals=<optimized out>) at ../Python/ceval.c:1134
#35 0x00005555557b8b18 in run_eval_code_obj (tstate=0x555555b5bf80, co=0x7ffff6c9f680, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd990>, 'signal': <module at remote 0x7ffff6cce7f0>, 'getopt': <module at remote 0x7ffff6ccea70>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff6b0cfe0>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff2429480>, 'initGlobalThis': <function at remote 0x7ffff24295a0>, 'main': <function at remote 0x7ffff2429630>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd990>, 'signal': <module at remote 0x7ffff6cce7f0>, 'getopt': <module at remote 0x7ffff6ccea70>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff6b0cfe0>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff2429480>, 'initGlobalThis': <function at remote 0x7ffff24295a0>, 'main': <function at remote 0x7ffff2429630>}) at ../Python/pythonrun.c:1291
#36 0x00005555557b196b in run_mod (mod=<optimized out>, filename=<optimized out>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd990>, 'signal': <module at remote 0x7ffff6cce7f0>, 'getopt': <module at remote 0x7ffff6ccea70>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff6b0cfe0>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff2429480>, 'initGlobalThis': <function at remote 0x7ffff24295a0>, 'main': <function at remote 0x7ffff2429630>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd990>, 'signal': <module at remote 0x7ffff6cce7f0>, 'getopt': <module at remote 0x7ffff6ccea70>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff6b0cfe0>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff2429480>, 'initGlobalThis': <function at remote 0x7ffff24295a0>, 'main': <function at remote 0x7ffff2429630>}, flags=<optimized out>, arena=<optimized out>) at ../Python/pythonrun.c:1312
--Type <RET> for more, q to quit, c to continue without paging--
#37 0x00005555557b8865 in pyrun_file (fp=fp@entry=0x555555b5e350, filename=filename@entry='/home/wes/git/PythonMonkey/tests/js/../../pmjs', start=start@entry=257, 
    globals=globals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd990>, 'signal': <module at remote 0x7ffff6cce7f0>, 'getopt': <module at remote 0x7ffff6ccea70>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff6b0cfe0>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff2429480>, 'initGlobalThis': <function at remote 0x7ffff24295a0>, 'main': <function at remote 0x7ffff2429630>}, 
    locals=locals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd990>, 'signal': <module at remote 0x7ffff6cce7f0>, 'getopt': <module at remote 0x7ffff6ccea70>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff6b0cfe0>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6c65ea0>, 'usage': <function at remote 0x7ffff2429480>, 'initGlobalThis': <function at remote 0x7ffff24295a0>, 'main': <function at remote 0x7ffff2429630>}, closeit=closeit@entry=1, flags=0x7fffffffe5c8) at ../Python/pythonrun.c:1208
#38 0x00005555557b7d48 in _PyRun_SimpleFileObject (fp=0x555555b5e350, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', closeit=1, flags=0x7fffffffe5c8)
    at ../Python/pythonrun.c:456
#39 0x00005555557b7a43 in _PyRun_AnyFileObject (fp=0x555555b5e350, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', closeit=1, flags=0x7fffffffe5c8)
    at ../Python/pythonrun.c:90
#40 0x00005555557a8c3e in pymain_run_file_obj (skip_source_first_line=0, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', 
    program_name='/home/wes/.cache/pypoetry/virtualenvs/pythonmonkey-NiDIb4WW-py3.10/bin/python') at ../Modules/main.c:353
#41 pymain_run_file (config=0x555555b40400) at ../Modules/main.c:372
#42 pymain_run_python (exitcode=0x7fffffffe5c4) at ../Modules/main.c:587
#43 Py_RunMain () at ../Modules/main.c:666
#44 0x000055555577ebcd in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at ../Modules/main.c:720
#45 0x00007ffff7c29d90 in __libc_start_call_main (main=main@entry=0x55555577eb90 <main>, argc=argc@entry=2, argv=argv@entry=0x7fffffffe7d8) at ../sysdeps/nptl/libc_start_call_main.h:58
#46 0x00007ffff7c29e40 in __libc_start_main_impl (main=0x55555577eb90 <main>, argc=2, argv=0x7fffffffe7d8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffffffe7c8) at ../csu/libc-start.c:392
#47 0x000055555577eac5 in _start ()
(gdb) info threads
  Id   Target Id                                       Frame 
* 1    Thread 0x7ffff7e73000 (LWP 1073155) "python"    0x00007ffff66faf6a in JS::Rooted<JS::Value>::~Rooted (this=0x7fffffffd4b8, __in_chrg=<optimized out>)
    at /usr/local/include/mozjs-102/js/RootingAPI.h:1192
  3    Thread 0x7ffff35fe640 (LWP 1073159) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d33ed0)
    at ./nptl/futex-internal.c:57
  4    Thread 0x7ffff33ff640 (LWP 1073160) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d33ed0)
    at ./nptl/futex-internal.c:57
  5    Thread 0x7ffff3200640 (LWP 1073161) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d33ed0)
    at ./nptl/futex-internal.c:57
  6    Thread 0x7ffff3001640 (LWP 1073162) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d33ed0)
    at ./nptl/futex-internal.c:57
  7    Thread 0x7ffff2e02640 (LWP 1073163) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d33ed0)
    at ./nptl/futex-internal.c:57
  8    Thread 0x7ffff2c03640 (LWP 1073164) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d33ed0)
    at ./nptl/futex-internal.c:57
  9    Thread 0x7ffff2a04640 (LWP 1073165) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d33ed0)
    at ./nptl/futex-internal.c:57
  10   Thread 0x7ffff2805640 (LWP 1073166) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555d33ed0)
    at ./nptl/futex-internal.c:57
(gdb) 

Implement cross-language garbage collection and cycle detection

Describe your feature request here.

Pythonmonkey should be able to communicate cross-language reference cycles to the python cycle collector and the spidermonkey garbage collector should be able to collect everything appropriately.

Code example

No response

test array-change-index.simple is failing on main

Issue type

Bug

How did you install PythonMonkey?

None

OS platform and distribution

No response

Python version (python --version)

No response

PythonMonkey version (pip show pythonmonkey)

No response

Bug Description

test array-change-index.simple is failing on main

Standalone code to reproduce the issue

poetry run bash ./peter-jr ./tests/js/js2py/array-change-index.simple
Testing tests/js/js2py/array-change-index.simple ... FAIL

-- tests/js/js2py/array-change-index.simple vvvvvvvvvvvvvv
Traceback (most recent call last):
File "/home/philippe/VirtualEnvs/env1/bin/pmjs", line 6, in
sys.exit(main())
^^^^^^
File "/home/philippe/Sources/temp/tests/PythonMonkey/python/pythonmonkey/cli/pmjs.py", line 323, in main
globalInitModule = initGlobalThis()
^^^^^^^^^^^^^^^^
File "/home/philippe/Sources/temp/tests/PythonMonkey/python/pythonmonkey/cli/pmjs.py", line 312, in initGlobalThis
argvBuilder = globalInitModule.makeArgvBuilder()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pythonmonkey.SpiderMonkeyError: TypeError: undefined is not a function

-- tests/js/js2py/array-change-index.simple ^^^^^^^^^^^^^^

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

segfault in PythonAwaitable_Check moving dates back and forth

Repro from pmjs:

python.eval('(lambda x: throughJS(x))', { throughJS: x=>x })(new Date())

Version:
0.0.1.dev1024+117d00f
932a3ce

Stack:

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
PythonAwaitable_Check (obj=obj@entry=<datetime.datetime at remote 0x7ffff2b3bc30>) at /home/wes/git/PythonMonkey/src/PromiseType.cc:150
150	  Py_DECREF(inspect);
(gdb) bt
#0  PythonAwaitable_Check (obj=obj@entry=<datetime.datetime at remote 0x7ffff2b3bc30>) at /home/wes/git/PythonMonkey/src/PromiseType.cc:150
#1  0x00007ffff6a26710 in jsTypeFactory (cx=cx@entry=0x555555cb4090, object=<datetime.datetime at remote 0x7ffff2b3bc30>) at /home/wes/git/PythonMonkey/src/jsTypeFactory.cc:167
#2  0x00007ffff6a277c4 in callJSFunc (jsCxThisFuncTuple=<optimized out>, args=(<datetime.datetime at remote 0x7ffff2b3bc30>,)) at /home/wes/git/PythonMonkey/src/pyTypeFactory.cc:178
#3  0x00005555556b0cc8 in cfunction_call (func=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67b40>, args=<optimized out>, kwargs=<optimized out>)
    at ../Objects/methodobject.c:552
#4  0x00005555556a772b in _PyObject_MakeTpCall (tstate=0x555555b5bf80, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67b40>, args=<optimized out>, 
    nargs=<optimized out>, keywords=0x0) at ../Objects/call.c:215
#5  0x000055555569fb2c in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6b7bea0, callable=<optimized out>, tstate=<optimized out>)
    at ../Include/cpython/abstract.h:112
#6  _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6b7bea0, callable=<optimized out>, tstate=<optimized out>) at ../Include/cpython/abstract.h:99
#7  PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6b7bea0, callable=<optimized out>) at ../Include/cpython/abstract.h:123
#8  call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffca70, tstate=<optimized out>) at ../Python/ceval.c:5891
#9  _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4213
#10 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, f=Frame 0x7ffff6b7bd30, for file <string>, line 1, in <lambda> (x=<datetime.datetime at remote 0x7ffff2b3bc30>), 
    tstate=0x555555b5bf80) at ../Include/internal/pycore_ceval.h:46
#11 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff2b71490, tstate=0x555555b5bf80) at ../Python/ceval.c:5065
#12 _PyFunction_Vectorcall (func=<function at remote 0x7ffff2b71480>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#13 0x00007ffff6a26b4f in callPyFunc (cx=0x555555cb4090, argc=<optimized out>, vp=0x555555dd2a90) at /home/wes/git/PythonMonkey/src/jsTypeFactory.cc:231
#14 0x00007ffff4b55ed9 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#15 0x00007ffff4b501a4 in Interpret(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#16 0x00007ffff4b4731a in js::RunScript(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#17 0x00007ffff4b57187 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, js::AbstractFramePtr, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#18 0x00007ffff4b79e4c in EvalKernel(JSContext*, JS::Handle<JS::Value>, EvalType, js::AbstractFramePtr, JS::Handle<JSObject*>, unsigned char*, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#19 0x00007ffff4b79562 in js::IndirectEval(JSContext*, unsigned int, JS::Value*) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#20 0x00007ffff4b55ed9 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#21 0x00007ffff4b501a4 in Interpret(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#22 0x00007ffff4b4731a in js::RunScript(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#23 0x00007ffff4b561cf in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#24 0x00007ffff4b56817 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#25 0x00007ffff4bedeb7 in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#26 0x00007ffff6a27878 in callJSFunc (jsCxThisFuncTuple=<optimized out>, args=<optimized out>) at /usr/local/include/mozjs-102/js/RootingAPI.h:1216
#27 0x00005555556b0cc8 in cfunction_call (func=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67d00>, args=<optimized out>, kwargs=<optimized out>)
    at ../Objects/methodobject.c:552
#28 0x00005555556a772b in _PyObject_MakeTpCall (tstate=0x555555b5bf80, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67d00>, args=<optimized out>, 
    nargs=<optimized out>, keywords=0x0) at ../Objects/call.c:215
#29 0x00005555556a00e7 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=<optimized out>, 
    callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67d00>, tstate=<optimized out>) at ../Include/cpython/abstract.h:112
#30 _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x555555ef18c0, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67d00>, 
    tstate=<optimized out>) at ../Include/cpython/abstract.h:99
#31 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x555555ef18c0, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67d00>)
    at ../Include/cpython/abstract.h:123
#32 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffdf20, tstate=<optimized out>) at ../Python/ceval.c:5891
#33 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4181
#34 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
--Type <RET> for more, q to quit, c to continue without paging--
    f=Frame 0x555555ef16f0, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 203, in repl (save_history=<function at remote 0x7ffff2b712d0>, atexit=<module at remote 0x7ffff2b864d0>, sigint_handler=<function at remote 0x7ffff2b713f0>), tstate=0x555555b5bf80) at ../Include/internal/pycore_ceval.h:46
#35 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff6d63da0, tstate=0x555555b5bf80) at ../Python/ceval.c:5065
#36 _PyFunction_Vectorcall (func=<function at remote 0x7ffff6d63d90>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#37 0x0000555555699a1d in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x555555ddeb18, callable=<function at remote 0x7ffff6d63d90>, tstate=0x555555b5bf80)
    at ../Include/cpython/abstract.h:114
#38 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x555555ddeb18, callable=<function at remote 0x7ffff6d63d90>) at ../Include/cpython/abstract.h:123
#39 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe0f0, tstate=<optimized out>) at ../Python/ceval.c:5891
#40 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4213
#41 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x555555dde960, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 309, in main (enterRepl=True, forceRepl=False, globalInitModule={}, opts=[], args=[], output=None, verbose=False), tstate=0x555555b5bf80) at ../Include/internal/pycore_ceval.h:46
#42 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff2b71250, tstate=0x555555b5bf80) at ../Python/ceval.c:5065
#43 _PyFunction_Vectorcall (func=<function at remote 0x7ffff2b71240>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#44 0x0000555555699a1d in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff2b71240>, tstate=0x555555b5bf80)
    at ../Include/cpython/abstract.h:114
#45 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff2b71240>) at ../Include/cpython/abstract.h:123
#46 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe2c0, tstate=<optimized out>) at ../Python/ceval.c:5891
#47 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4213
#48 0x0000555555696176 in _PyEval_EvalFrame (throwflag=0, f=Frame 0x7ffff6d29c40, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 312, in <module> (), tstate=0x555555b5bf80)
    at ../Include/internal/pycore_ceval.h:46
#49 _PyEval_Vector (tstate=0x555555b5bf80, con=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=<optimized out>) at ../Python/ceval.c:5065
#50 0x000055555578bc56 in PyEval_EvalCode (co=<code at remote 0x7ffff6c72c30>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, locals=<optimized out>) at ../Python/ceval.c:1134
#51 0x00005555557b8b18 in run_eval_code_obj (tstate=0x555555b5bf80, co=0x7ffff6c72c30, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}) at ../Python/pythonrun.c:1291
#52 0x00005555557b196b in run_mod (mod=<optimized out>, filename=<optimized out>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, flags=<optimized out>, arena=<optimized out>)
    at ../Python/pythonrun.c:1312
--Type <RET> for more, q to quit, c to continue without paging--
#53 0x00005555557b8865 in pyrun_file (fp=fp@entry=0x555555b5e350, filename=filename@entry='/home/wes/git/PythonMonkey/tests/js/../../pmjs', start=start@entry=257, 
    globals=globals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, 
    locals=locals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, closeit=closeit@entry=1, flags=0x7fffffffe568)
    at ../Python/pythonrun.c:1208
#54 0x00005555557b7d48 in _PyRun_SimpleFileObject (fp=0x555555b5e350, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', closeit=1, flags=0x7fffffffe568)
    at ../Python/pythonrun.c:456
#55 0x00005555557b7a43 in _PyRun_AnyFileObject (fp=0x555555b5e350, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', closeit=1, flags=0x7fffffffe568) at ../Python/pythonrun.c:90
#56 0x00005555557a8c3e in pymain_run_file_obj (skip_source_first_line=0, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', 
    program_name='/home/wes/.cache/pypoetry/virtualenvs/pythonmonkey-NiDIb4WW-py3.10/bin/python') at ../Modules/main.c:353
#57 pymain_run_file (config=0x555555b40400) at ../Modules/main.c:372
#58 pymain_run_python (exitcode=0x7fffffffe564) at ../Modules/main.c:587
#59 Py_RunMain () at ../Modules/main.c:666
#60 0x000055555577ebcd in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at ../Modules/main.c:720
#61 0x00007ffff7c29d90 in __libc_start_call_main (main=main@entry=0x55555577eb90 <main>, argc=argc@entry=2, argv=argv@entry=0x7fffffffe778) at ../sysdeps/nptl/libc_start_call_main.h:58
#62 0x00007ffff7c29e40 in __libc_start_main_impl (main=0x55555577eb90 <main>, argc=2, argv=0x7fffffffe778, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffffffe768) at ../csu/libc-start.c:392
#63 0x000055555577eac5 in _start ()

JavaScript arrays are coerced to JsObjectProxys instead of Python Lists

Issue type

Bug

How did you install PythonMonkey?

From source

OS platform and distribution

Linux Ubuntu 22.04

Python version (python --version)

3.10.6

PythonMonkey version

0.0.1.dev997+1eb8832

Bug Description

When you pass a JavaScript array to Python, it will coerce to a JsObjectProxy instead of a List which is specified in the readme documentation here. Perhaps the documentation should change if this should be the case.

Standalone code to reproduce the issue

>>> type(pm.eval('[]'))
<class 'pythonmonkey.JSObjectProxy'>

Relevant log output or backtrace

example

Additional info if applicable

Wes said I should make sure @caleb-distributive sees this (internal Distributive slack link --> https://dstrbtv.slack.com/archives/C03RNFRL4NQ/p1689342401559729)

What branch of PythonMonkey were you developing on? (If applicable)

feature/js-test-coverage

console.log can't output non-bmp characters

Repro: console.log('🐍🐒')

Error: UnicodeEncodeError: 'utf-8' codec can't encode characters in position 13-16: surrogates not allowed

Pretty sure it's sys.stdout.write that's complaining. I also tried with python.print(), same result

Can we transcode utf16 to utf8 ourselves to work around this? I know how.

Support ES6 modules

Describe your feature request here.

Are there any plans to support ES6 modules in addition to CommonJS?

Example JS:

function hello(items) {
    console.log("hello world");
}

export {hello};

Trying to use this with PythonMonkey currently throws an error:

    return createRequire(filename)(moduleIdentifier)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pythonmonkey.SpiderMonkeyError: Error in file [python code], on line 0:
Error: Python str: Error in file evaluate, on line 5:
export default hello;
^
SyntaxError: export declarations may only appear at top level of a module

Code example

No response

Py_IsTrue and Py_IsFalse are reported during building

python: Python 3.9.5
commit: 77d5473d885d91443faf2dbbf92cf09acc74e987
branch: hamada/module-system

When I run ./build_script.sh, I get the following errors:

/home/will/git/PythonMonkey/src/JSObjectProxy.cc: In static member function ‘static PyObject* JSObjectProxyMethodDefinitions::JSObjectProxy_richcompare(JSObjectProxy*, PyObject*, int)’:
/home/will/git/PythonMonkey/src/JSObjectProxy.cc:197:13: error: ‘Py_IsTrue’ was not declared in this scope; did you mean ‘Py_True’?
  197 |   isEqual = Py_IsTrue(JSObjectProxy_richcompare_helper(self, other, op, visited));
      |             ^~~~~~~~~
      |             Py_True
/home/will/git/PythonMonkey/src/JSObjectProxy.cc: In static member function ‘static PyObject* JSObjectProxyMethodDefinitions::JSObjectProxy_richcompare_helper(JSObjectProxy*, PyObject*, int, std::unordered_map<_object*, _object*>&)’:
/home/will/git/PythonMonkey/src/JSObjectProxy.cc:241:11: error: ‘Py_IsFalse’ was not declared in this scope; did you mean ‘Py_False’?
  241 |       if (Py_IsFalse(JSObjectProxy_richcompare_helper((JSObjectProxy *)pyVal1, pyVal2, op, visited)))
      |           ^~~~~~~~~~
      |           Py_False
/home/will/git/PythonMonkey/src/JSObjectProxy.cc:248:11: error: ‘Py_IsFalse’ was not declared in this scope; did you mean ‘Py_False’?
  248 |       if (Py_IsFalse(JSObjectProxy_richcompare_helper((JSObjectProxy *)pyVal2, pyVal1, op, visited)))
      |           ^~~~~~~~~~
      |           Py_False
/home/will/git/PythonMonkey/src/JSObjectProxy.cc:254:14: error: ‘Py_IsFalse’ was not declared in this scope; did you mean ‘Py_False’?
  254 |     else if (Py_IsFalse(PyObject_RichCompare(pyVal1, pyVal2, Py_EQ)))
      |              ^~~~~~~~~~
      |              Py_False
make[2]: *** [src/CMakeFiles/pythonmonkey.dir/build.make:160: src/CMakeFiles/pythonmonkey.dir/JSObjectProxy.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:400: src/CMakeFiles/pythonmonkey.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

And if I rm rf build/* and re-build, PythonMonkey doesn't compile


After talking with the team, I think this issue is resolved somewhere else

Instantiate JS objects more easily (pm.new?)

Describe your feature request here.

The pattern I've been using to instantiate new JS objects from classes is to wrap the call to "new" in a function:

module = pm.eval("(bufferSource) => new WebAssembly.Module(bufferSource)")(file_buffer)

This gets uglier when you need to pass more things to a constructor:

wasm_instance = pm.eval("(module, importObject) => new WebAssembly.Instance(module, importObject)")(module, import_object)

I think it would be nicer to have some better way of doing "new" since its such a commonly used operator.

WebAssembly = pm.eval("WebAssembly")
module = pm.new(WebAssembly.Module)(file_buffer)
wasm_instance = pm.new(WebAssembly.Instance)(module, import_object)

I'm not sure if this is the best approach, but just an idea


NOTE: some JS constructors don't require the use of the 'new' keyword... but others like WebAssembly.Module will and will report the following error if not used with new Uncaught TypeError: WebAssembly.Module(): WebAssembly.Module must be invoked with 'new'

Code example

API idea:
new method: pm.new
parameters: a function which is a constructor
return: a function which calls the constructor

---

Usage: pm.new(SomeConstructor)(parameters...)

pm.new(Function)(

iter operation returns tuple instead of single

Issue type

Bug

How did you install PythonMonkey?

None

OS platform and distribution

No response

Python version (python --version)

No response

PythonMonkey version (pip show pythonmonkey)

No response

Bug Description

import pythonmonkey as pm

a = pm.eval("({'c':5})")

min(a)

should be
'c'
get instead
('c', 5.0)

similarly for max(a)

Other example:

python 3:
likes = {"color": "blue", "fruit": "apple", "pet": "dog"}

for key in likes:
... print(key)
...
color
fruit
pet

python-monkey:

likes = pm.eval('({"color": "blue", "fruit": "apple", "pet": "dog"})')

for key in likes:
... print(key)
...
('color', 'blue')
('fruit', 'apple')
('pet', 'dog')

ONE MORE:

python 3:

for key in likes:
... print(key, "->", likes[key])
...
color -> blue
fruit -> apple
pet -> dog

python-monkey

for key in likes:
... print(key, "->", likes[key])
...
Traceback (most recent call last):
File "", line 2, in
SystemError: error return without exception set

See https://realpython.com/iterate-through-dictionary-python/

It also seems iter is missing Unit tests, another TODO

-> ALSO

implement missing iter-related dict methods:

{"keys", dictkeys_new, METH_NOARGS,
keys__doc__},
{"items", dictitems_new, METH_NOARGS,
items__doc__},
{"values", dictvalues_new, METH_NOARGS,
values__doc__},
{"update", PyCFunction_CAST(dict_update), METH_VARARGS | METH_KEYWORDS,
update__doc
_},
DICT_FROMKEYS_METHODDEF

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Troubles loading crypto-js

Issue type

Bug

How did you install PythonMonkey?

None

OS platform and distribution

No response

Python version (python --version)

No response

PythonMonkey version (pip show pythonmonkey)

No response

Bug Description

When importing algorithm libraries, globalThis does not have the hasOwnProperty function

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Missing npm should print better error during pip install

Collecting pminit
  Downloading https://nightly.pythonmonkey.io/pminit/pminit-0.0.1.dev1032%2Bb9fb965.tar.gz (6.9 kB)
  Running command pip subprocess to install build dependencies
  Looking in indexes: https://pypi.org/simple, https://nightly.pythonmonkey.io/
  Collecting poetry-core>=1.0.0
    Using cached poetry_core-1.6.1-py3-none-any.whl (450 kB)
  Collecting poetry-dynamic-versioning==0.24.0
    Downloading poetry_dynamic_versioning-0.24.0-py3-none-any.whl (16 kB)
  Collecting dunamai<2.0.0,>=1.17.0
    Downloading dunamai-1.18.0-py3-none-any.whl (24 kB)
  Collecting jinja2<4,>=2.11.1
    Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 5.0 MB/s eta 0:00:00
  Collecting tomlkit>=0.4
    Using cached tomlkit-0.11.8-py3-none-any.whl (35 kB)
  Collecting packaging>=20.9
    Using cached packaging-23.1-py3-none-any.whl (48 kB)
  Collecting MarkupSafe>=2.0
    Downloading MarkupSafe-2.1.3-cp311-cp311-macosx_10_9_x86_64.whl (13 kB)
  Installing collected packages: tomlkit, poetry-core, packaging, MarkupSafe, jinja2, dunamai, poetry-dynamic-versioning
  Successfully installed MarkupSafe-2.1.3 dunamai-1.18.0 jinja2-3.1.2 packaging-23.1 poetry-core-1.6.1 poetry-dynamic-versioning-0.24.0 tomlkit-0.11.8

  [notice] A new release of pip is available: 23.0.1 -> 23.2
  [notice] To update, run: python3.11 -m pip install --upgrade pip
  Installing build dependencies ... done
  Running command Getting requirements to build wheel
  Getting requirements to build wheel ... done
  Running command Preparing metadata (pyproject.toml)
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pminit
  Running command Building wheel for pminit (pyproject.toml)
  /bin/sh: npm: command not found
  Traceback (most recent call last):
    File "/private/var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/pip-install-gmtdwgke/pminit_54b7ddf7e3eb417192a5aa3ca67a62ce/post-install-hook.py", line 20, in <module>
      main()
    File "/private/var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/pip-install-gmtdwgke/pminit_54b7ddf7e3eb417192a5aa3ca67a62ce/post-install-hook.py", line 17, in main
      execute("cd pythonmonkey && npm i --no-package-lock") # do not update package-lock.json
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/pip-install-gmtdwgke/pminit_54b7ddf7e3eb417192a5aa3ca67a62ce/post-install-hook.py", line 14, in execute
      raise subprocess.CalledProcessError(return_code, cmd)
  subprocess.CalledProcessError: Command 'cd pythonmonkey && npm i --no-package-lock' returned non-zero exit status 127.
  Traceback (most recent call last):
    File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/pip-build-env-vj7xz744/overlay/lib/python3.11/site-packages/poetry/core/masonry/api.py", line 57, in build_wheel
      return WheelBuilder.make_in(
             ^^^^^^^^^^^^^^^^^^^^^
    File "/private/var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/pip-build-env-vj7xz744/overlay/lib/python3.11/site-packages/poetry/core/masonry/builders/wheel.py", line 88, in make_in
      wb.build(target_dir=directory)
    File "/private/var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/pip-build-env-vj7xz744/overlay/lib/python3.11/site-packages/poetry/core/masonry/builders/wheel.py", line 123, in build
      self._build(zip_file)
    File "/private/var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/pip-build-env-vj7xz744/overlay/lib/python3.11/site-packages/poetry/core/masonry/builders/wheel.py", line 172, in _build
      self._run_build_script(self._package.build_script)
    File "/private/var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/pip-build-env-vj7xz744/overlay/lib/python3.11/site-packages/poetry/core/masonry/builders/wheel.py", line 232, in _run_build_script
      subprocess.check_call([self.executable.as_posix(), build_script])
    File "/usr/local/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 413, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['/usr/local/Cellar/[email protected]/3.11.4_1/bin/python3.11', 'post-install-hook.py']' returned non-zero exit status 1.
  error: subprocess-exited-with-error
  
  × Building wheel for pminit (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /usr/local/opt/[email protected]/bin/python3.11 /usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/tmpzxvllrjp
  cwd: /private/var/folders/64/b8cgz6zx1sx62yr5kwql813c0000gn/T/pip-install-gmtdwgke/pminit_54b7ddf7e3eb417192a5aa3ca67a62ce
  Building wheel for pminit (pyproject.toml) ... error
  ERROR: Failed building wheel for pminit
Failed to build pminit
ERROR: Could not build wheels for pminit, which is required to install pyproject.toml-based projects

[notice] A new release of pip is available: 23.0.1 -> 23.2
[notice] To update, run: python3.11 -m pip install --upgrade pip
[~] Wes-iMac-2019:wes# ```

Make pmjs repl work on win32

It's my understanding that the pmjs REPL doesn't work on win32 because there is no GNU readline library installed on those python systems.

It's also my understanding that changing to pyreadline3 will fix this

We need this to work

Wrong lexical scope for pmjs evaluation

Type ".help" for more information.
> const c=1
undefined
> c
ReferenceError: c is not defined
    @/home/wes/git/PythonMonkey/./pmjs line 118 > eval:1:1
    replEval@/home/wes/git/PythonMonkey/./pmjs:118:32
> var a=1
undefined
> a
1
> globalThis.a
1
> globalThis.c
undefined
> 

c should have been a property of globalThis, but wasn't. It's as though there is a {...} scope in the way, but I can't see how that would be.

`peter-jr` exits with a non-zero exit code on `.failing` tests

Based on the failing CI checks on #95, it looks like the following minimal repro will cause the test runner to indicate that an unexpected failure occured:

$ echo 'throw new Error();' > error.simple.failing
$ ./peter-jr error.simple.failing
Testing error.simple.failing ... F̶A̶I̶L̶ (expected)
$ echo $?
1

The same thing occurs for .bash.failing tests.

Python dict proxy objects should return the underlying dict rather than wrapping it in a JSObjectProxy

Currently, when a python dict is passed to JS it gets wrapped in a proxy object handled by PyProxyHandler. When JS returns this proxy object back to python, it wraps it in a JSObjectProxy, but ideally we would just be returning the raw dict.

As an example, the following should be able to pass:

import pythonmonkey as pm
d = {"a":1}
new_d = pm.eval("(dict) => { return dict; }")(d)
assert d is new_d

Error when using console.log in Python

Repro

import pythonmonkey as pm
my_print = pm.eval("console.log")
my_print('Hello, world')

Details

In JavaScript, this will print an output as expected:

print = console.log;
print('Hello, world');

I think it makes sense for the example in my repro to work, but I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pythonmonkey.SpiderMonkeyError: Error in file @evaluate line 278 > eval, on line 57:
TypeError: can't access private field or method: object is not the right class
Stack Trace:
  log@@evaluate line 278 > eval:57:5

What are your thoughts? Should this be something that works, or is it not possible?

Unable to pip install pythonmonkey on Windows - Something related to pminit

Issue type

Build/Install

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

Windows 10

Python version (python --version)

3.10

PythonMonkey version (pip show pythonmonkey)

0.2.0

Bug Description

I tried installing pythonmonkey on Windows and encountered errors: Could not build wheels for pminit, which is required to install pyproject.toml-based

Standalone code to reproduce the issue

Use Windows 10, 
Python version: 3.10.10 (also tested it with 3.11 and had the same problem)
Pip version: 23.2.1

---


$ pip install pythonmonkey


### Relevant log output or backtrace

```shell
>python -m pip install pythonmonkey   
                                                                    Collecting pythonmonkey                                                                                                Obtaining dependency information for pythonmonkey from https://files.pythonhosted.org/packages/9f/d1/eda3c505a2a4932cfcb62a5e70831b0446e8839b4cbe700718e34ea63049/pythonmonkey-0.2.0-cp310-cp310-win_amd64.whl.metadata                   Downloading pythonmonkey-0.2.0-cp310-cp310-win_amd64.whl.metadata (15 kB)                                          Collecting pminit (from pythonmonkey)                                                                                  Using cached pminit-0.2.0.tar.gz (6.8 kB)                                                                            Installing build dependencies ... done                                                                               Getting requirements to build wheel ... done                                                                         Preparing metadata (pyproject.toml) ... done                                                                       Collecting pyreadline3<4.0.0,>=3.4.1 (from pythonmonkey)                                                               Using cached pyreadline3-3.4.1-py3-none-any.whl (95 kB)                                                            Using cached pythonmonkey-0.2.0-cp310-cp310-win_amd64.whl (9.7 MB)                                                   Building wheels for collected packages: pminit                                                                         Building wheel for pminit (pyproject.toml) ... error                                                                 error: subprocess-exited-with-error                                                                                                                                                                                                       × Building wheel for pminit (pyproject.toml) did not run successfully.                                               │ exit code: 1                                                                                                       ╰─> [30 lines of output]                                                                                                 'npm' is not recognized as an internal or external command,                                                          operable program or batch file.                                                                                      Traceback (most recent call last):                                                                                     File "C:\Users\Will Pringle\AppData\Local\Temp\pip-install-7h4_kdok\pminit_90353e74102b48bda5f8c5d72665cca9\post-install-hook.py", line 20, in <module>                                                                                     main()                                                                                                             File "C:\Users\Will Pringle\AppData\Local\Temp\pip-install-7h4_kdok\pminit_90353e74102b48bda5f8c5d72665cca9\post-install-hook.py", line 17, in main                                                                                         execute("cd pythonmonkey && npm i --no-package-lock") # do not update package-lock.json                            File "C:\Users\Will Pringle\AppData\Local\Temp\pip-install-7h4_kdok\pminit_90353e74102b48bda5f8c5d72665cca9\post-install-hook.py", line 14, in execute                                                                                      raise subprocess.CalledProcessError(return_code, cmd)                                                            subprocess.CalledProcessError: Command 'cd pythonmonkey && npm i --no-package-lock' returned non-zero exit status 1.                                                                                                                      Traceback (most recent call last):                                                                                     File "C:\Users\Will Pringle\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>                                                                        main()                                                                                                             File "C:\Users\Will Pringle\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main                                                                            json_out['return_val'] = hook(**hook_input['kwargs'])                                                              File "C:\Users\Will Pringle\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 251, in build_wheel                                                                     return _build_backend().build_wheel(wheel_directory, config_settings,                                              File "C:\Users\Will Pringle\AppData\Local\Temp\pip-build-env-fbkopqxr\overlay\Lib\site-packages\poetry\core\masonry\api.py", line 57, in build_wheel                                                                                        return WheelBuilder.make_in(                                                                                       File "C:\Users\Will Pringle\AppData\Local\Temp\pip-build-env-fbkopqxr\overlay\Lib\site-packages\poetry\core\masonry\builders\wheel.py", line 88, in make_in                                                                                 wb.build(target_dir=directory)                                                                                     File "C:\Users\Will Pringle\AppData\Local\Temp\pip-build-env-fbkopqxr\overlay\Lib\site-packages\poetry\core\masonry\builders\wheel.py", line 123, in build                                                                                  self._build(zip_file)                                                                                              File "C:\Users\Will Pringle\AppData\Local\Temp\pip-build-env-fbkopqxr\overlay\Lib\site-packages\poetry\core\masonry\builders\wheel.py", line 172, in _build                                                                                 self._run_build_script(self._package.build_script)                                                                 File "C:\Users\Will Pringle\AppData\Local\Temp\pip-build-env-fbkopqxr\overlay\Lib\site-packages\poetry\core\masonry\builders\wheel.py", line 232, in _run_build_script                                                                      subprocess.check_call([self.executable.as_posix(), build_script])                                                  File "C:\Users\Will Pringle\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 369, in check_call                                                                                                                             raise CalledProcessError(retcode, cmd)                                                                           subprocess.CalledProcessError: Command '['C:/Users/Will Pringle/AppData/Local/Programs/Python/Python310/python.exe', 'post-install-hook.py']' returned non-zero exit status 1.                                                            [end of output]                                                                                                                                                                                                                       note: This error originates from a subprocess, and is likely not a problem with pip.                                 ERROR: Failed building wheel for pminit                                                                            Failed to build pminit                                                                                               ERROR: Could not build wheels for pminit, which is required to install pyproject.toml-based projects

Additional info if applicable

My friend also had this issue when she tried to install it

What branch of PythonMonkey were you developing on? (If applicable)

No response

JSArrayProxy

Describe your feature request here.

Implement a type to proxy Javascript Arrays that is list-like in Python. Likely this will end up re-using some code from JSObjectProxy, and in general reading JSObjectProxy would be a good idea before tackling this.

Code example

import pythonmonkey as pm
l = pm.eval("[1, 2, 3]")
print(l[0]) # this should print 1

poetry install assumes we are at the topdir

[git/PythonMonkey/tests/js] bergelmir:wes# poetry install
Installing dependencies from lock file
Warning: poetry.lock is not consistent with pyproject.toml. You may be getting improper dependencies. Run `poetry lock [--no-update]` to fix it.

Package operations: 0 installs, 1 update, 0 removals

  • Updating pminit (0.0.1.dev1006+4932bf0 /home/wes/git/PythonMonkey/python/pminit -> 0.0.1.dev1024+117d00f /home/wes/git/PythonMonkey/python/pminit)

Preparing build environment with build-system requirements poetry-core>=1.0.0, poetry-dynamic-versioning==0.24.0
bash: ./setup.sh: No such file or directory
Traceback (most recent call last):
  File "/home/wes/git/PythonMonkey/build.py", line 62, in <module>
    build()
  File "/home/wes/git/PythonMonkey/build.py", line 57, in build
    ensure_spidermonkey()
  File "/home/wes/git/PythonMonkey/build.py", line 35, in ensure_spidermonkey
    execute("bash ./setup.sh")
  File "/home/wes/git/PythonMonkey/build.py", line 26, in execute
    raise subprocess.CalledProcessError(return_code, cmd)
subprocess.CalledProcessError: Command 'bash ./setup.sh' returned non-zero exit status 127.

Command ['/tmp/tmp0w4d7k4y/.venv/bin/python', '/home/wes/git/PythonMonkey/build.py'] errored with the following return code 1

Dict dir operation not implemented

Issue type

Bug

How did you install PythonMonkey?

None

OS platform and distribution

No response

Python version (python --version)

No response

PythonMonkey version (pip show pythonmonkey)

No response

Bug Description

in python3:

a = {'c':5}

a
{'c': 5}
dir(a)
['class', 'class_getitem', 'contains', 'delattr', 'delitem', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'getitem', 'getstate', 'gt', 'hash', 'init', 'init_subclass', 'ior', 'iter', 'le', 'len', 'lt', 'ne', 'new', 'or', 'reduce', 'reduce_ex', 'repr', 'reversed', 'ror', 'setattr', 'setitem', 'sizeof', 'str', 'subclasshook', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']

in python-monkey:

a = pm.eval("({'c':5})")
a
{'c': 5.0}
dir({})
['class', 'class_getitem', 'contains', 'delattr', 'delitem', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'getitem', 'getstate', 'gt', 'hash', 'init', 'init_subclass', 'ior', 'iter', 'le', 'len', 'lt', 'ne', 'new', 'or', 'reduce', 'reduce_ex', 'repr', 'reversed', 'ror', 'setattr', 'setitem', 'sizeof', 'str', 'subclasshook', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
dir(a)
[]

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Installation error in Python 3.9.5

Issue type

Build/Install

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

Linux Ubuntu 20.04 LTS (Focal Fossa)

Python version (python --version)

3.9.5

PythonMonkey version (pip show pythonmonkey)

No response

Bug Description

There is a problem with the installation of PythonMonkey module using PIP. When I run python3 -m pip install pythonmonkey the following error occurs:

Collecting pythonmonkey
  Using cached pythonmonkey-0.2.1.tar.gz (112 kB)
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 186, in _main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 357, in run
    resolver.resolve(requirement_set)
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 177, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 333, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 282, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 515, in prepare_linked_requirement
    abstract_dist = _get_prepared_distribution(
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 95, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "/usr/lib/python3/dist-packages/pip/_internal/distributions/sdist.py", line 33, in prepare_distribution_metadata
    self.req.load_pyproject_toml()
  File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 512, in load_pyproject_toml
    pyproject_toml_data = load_pyproject_toml(
  File "/usr/lib/python3/dist-packages/pip/_internal/pyproject.py", line 75, in load_pyproject_toml
    pp_toml = toml.load(f)
  File "/usr/share/python-wheels/toml-0.10.0-py2.py3-none-any.whl/toml/decoder.py", line 134, in load
    return loads(f.read(), _dict, decoder)
  File "/usr/share/python-wheels/toml-0.10.0-py2.py3-none-any.whl/toml/decoder.py", line 455, in loads
    ret = decoder.load_line(line, currentlevel, multikey,
  File "/usr/share/python-wheels/toml-0.10.0-py2.py3-none-any.whl/toml/decoder.py", line 725, in load_line
    value, vtype = self.load_value(pair[1], strictly_valid)
  File "/usr/share/python-wheels/toml-0.10.0-py2.py3-none-any.whl/toml/decoder.py", line 802, in load_value
    return (self.load_array(v), "array")
  File "/usr/share/python-wheels/toml-0.10.0-py2.py3-none-any.whl/toml/decoder.py", line 914, in load_array
    a[b] = a[b] + ',' + a[b + 1]
IndexError: list index out of range

I've also tried the same on RPi4 with Raspbian OS and got the same result. Python version is 3.9 also.

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Unable to pip install pythonmonkey on ubuntu linux

Issue type

Build/Install

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

Linux Ubuntu 18.04.6 LTS (Bionic Beaver)

Python version (python --version)

Python 3.9.17 with miniconda

PythonMonkey version (pip show pythonmonkey)

0.2.1

Bug Description

I'm try to install pythonmonkey in windows 10 using pip and anaconda it's working fine,
but when I try to install pythonmonkey in ubuntu linux using miniconda in myserver it getting error
carbon (4)

Standalone code to reproduce the issue

pip install pythonmonkey

Relevant log output or backtrace

(py3917) admin@server:~$ pip install pythonmonkey
Collecting pythonmonkey
  Using cached pythonmonkey-0.2.1.tar.gz (112 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting pminit (from pythonmonkey)
  Using cached pminit-0.2.1-cp39-cp39-manylinux_2_27_x86_64.whl
Building wheels for collected packages: pythonmonkey
  Building wheel for pythonmonkey (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for pythonmonkey (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [29 lines of output]
      fatal: not a git repository (or any of the parent directories): .git
      Traceback (most recent call last):
        File "/tmp/pip-install-ph7wqk6v/pythonmonkey_34995c194ff54c12b4582084f0010eb0/build.py", line 61, in <module>
          build()
        File "/tmp/pip-install-ph7wqk6v/pythonmonkey_34995c194ff54c12b4582084f0010eb0/build.py", line 55, in build
          execute("git submodule update --init --recursive", cwd=TOP_DIR)
        File "/tmp/pip-install-ph7wqk6v/pythonmonkey_34995c194ff54c12b4582084f0010eb0/build.py", line 27, in execute
          raise subprocess.CalledProcessError(return_code, cmd)
      subprocess.CalledProcessError: Command 'git submodule update --init --recursive' returned non-zero exit status 128.
      Traceback (most recent call last):
        File "/home/admin/miniconda3/envs/py3917/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/admin/miniconda3/envs/py3917/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/admin/miniconda3/envs/py3917/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
        File "/tmp/pip-build-env-7_kl5896/overlay/lib/python3.9/site-packages/poetry/core/masonry/api.py", line 58, in build_wheel
          return WheelBuilder.make_in(
        File "/tmp/pip-build-env-7_kl5896/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 88, in make_in
          wb.build(target_dir=directory)
        File "/tmp/pip-build-env-7_kl5896/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 123, in build
          self._build(zip_file)
        File "/tmp/pip-build-env-7_kl5896/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 172, in _build
          self._run_build_script(self._package.build_script)
        File "/tmp/pip-build-env-7_kl5896/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 266, in _run_build_script
          subprocess.check_call([self.executable.as_posix(), build_script])
        File "/home/admin/miniconda3/envs/py3917/lib/python3.9/subprocess.py", line 373, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['/home/admin/miniconda3/envs/py3917/bin/python', 'build.py']' returned non-zero exit status 1.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pythonmonkey
Failed to build pythonmonkey
ERROR: Could not build wheels for pythonmonkey, which is required to install pyproject.toml-based projects

Additional info if applicable

this is my version I'm using of miniconda, python, pip, node npm

(py3917) admin@server:~$ conda --version
conda 23.9.0
(py3917) admin@server:~$ python --version
Python 3.9.17
(py3917) admin@server:~$ pip --version
pip 23.3.1 from /home/admin/miniconda3/envs/py3917/lib/python3.9/site-packages/pip (python 3.9)
(py3917) admin@server:~$ node --version
v18.16.0
(py3917) admin@server:~$ npm --version
9.5.1

What branch of PythonMonkey were you developing on? (If applicable)

No response

Add Fetch API to PythonMonkey

Describe your feature request here.

Add the Fetch API to PythonMonkey as per its spec (or a subset of it)

Work for fetch will include:


This will likely be implemented as a wrapper over Python's requests module.


Using fetch from JavaScript code would be very familiar for Web developers using PythonMonkey. It will also provide fetch to Python developers as an alternative promise based request api.


Example usage (in Python):

import pythonmonkey
import asyncio

async def logMovies():
    response = await pythonmonkey.fetch("http://example.com/movies.json")
    movies = await response.json()
    print(movies)

asyncio.run(logMovies)

Example usage (in JavaScript):

async function logMovies() {
  const response = await fetch("http://example.com/movies.json");
  const movies = await response.json();
  console.log(movies);
}

logMovies()

Code example

Promise<Response> fetch(RequestInfo input, optional RequestInit init = {});

Lists are converted to objects instead of arrays

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

MacOS 13.5.2

Python version (python --version)

3.11

PythonMonkey version (pip show pythonmonkey)

0.2.2.dev85+a7e1bcc

Bug Description

When passing a list into a JS function, the list is converted into an object rather than an array, which is unexpected.

Expected:
[ 1, 2, 3 ] true

Actual:
{ '0': 1, '1': 2, '2': 3 } false

Standalone code to reproduce the issue

import pythonmonkey as pm

items = [1, 2, 3]
isArray = pm.eval('Array.isArray')(items)
pm.eval('console.log')(items, isArray)

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Incorrect behavior when using pmjs event-loop

Steps to Repo: ./pmjs tests/js/timer-reject.js
Branch: wes/pmjs-event-loop
Version: 87b311b72bf867a76ee31b23a8b4ffe5655d7ef4

Reading symbols from python...
Reading symbols from /usr/lib/debug/.build-id/a6/73a1e2b7a7287c1908dec1a748642e2c02392d.debug...
(gdb) run ./pmjs tests/js/timer-reject.js
Starting program: /home/wes/.cache/pypoetry/virtualenvs/pythonmonkey-StuBmUri-py3.10/bin/python ./pmjs tests/js/timer-reject.js

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff3dff640 (LWP 1145451)]
[Thread 0x7ffff3dff640 (LWP 1145451) exited]
[New Thread 0x7ffff35fe640 (LWP 1145452)]
[New Thread 0x7ffff33ff640 (LWP 1145453)]
[New Thread 0x7ffff3200640 (LWP 1145454)]
[New Thread 0x7ffff3001640 (LWP 1145455)]
[New Thread 0x7ffff2e02640 (LWP 1145456)]
[New Thread 0x7ffff2c03640 (LWP 1145457)]
[New Thread 0x7ffff2a04640 (LWP 1145458)]
[New Thread 0x7ffff2805640 (LWP 1145459)]
hello
Error: goodbye
    @@evaluate:8:32
    timerCallbackWrapper@@evaluate line 278 > eval:97:26

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007ffff44e1a24 in JS_GetPropertyById(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::PropertyKey>, JS::MutableHandle<JS::Value>) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
(gdb) bt
#0  0x00007ffff44e1a24 in JS_GetPropertyById(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::PropertyKey>, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#1  0x00007ffff66fdd8c in JSObjectProxyMethodDefinitions::JSObjectProxy_get (self=0x7ffff243a860, key=<optimized out>) at /usr/local/include/mozjs-102/js/RootingAPI.h:1216
#2  0x0000555555699fff in _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:2109
#3  0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x7ffff259f9a0, for file /home/wes/git/PythonMonkey/./pmjs, line 357, in cleanupExit (code=<float at remote 0x7ffff25bf5b0>), tstate=0x555555b5c120)
    at ../Include/internal/pycore_ceval.h:46
#4  _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff2429d90, tstate=0x555555b5c120) at ../Python/ceval.c:5065
#5  _PyFunction_Vectorcall (func=<function at remote 0x7ffff2429d80>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#6  0x00007ffff670409f in callPyFunc (cx=0x555555de49f0, argc=<optimized out>, vp=0x555555ebb308) at /home/wes/git/PythonMonkey/src/jsTypeFactory.cc:234
#7  0x00007ffff4355ed9 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#8  0x00007ffff43501a4 in Interpret(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#9  0x00007ffff434731a in js::RunScript(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#10 0x00007ffff43561cf in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#11 0x00007ffff4356817 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#12 0x00007ffff44a5751 in PromiseReactionJob(JSContext*, unsigned int, JS::Value*) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#13 0x00007ffff4355ed9 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#14 0x00007ffff4356817 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#15 0x00007ffff43edeb7 in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#16 0x00007ffff6704d98 in callJSFunc (jsCxThisFuncTuple=<optimized out>, args=<optimized out>) at /usr/local/include/mozjs-102/js/RootingAPI.h:1216
#17 0x00005555556b0cc8 in cfunction_call (func=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2441140>, args=<optimized out>, kwargs=<optimized out>)
    at ../Objects/methodobject.c:552
#18 0x00005555556a772b in _PyObject_MakeTpCall (tstate=0x555555b5c120, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2441140>, args=<optimized out>, 
    nargs=<optimized out>, keywords=0x0) at ../Objects/call.c:215
#19 0x000055555583e682 in context_run (self=0x7ffff2441280, args=0x7ffff24454f8, nargs=1, kwnames=0x0) at ../Python/context.c:665
#20 0x00005555556a462b in cfunction_vectorcall_FASTCALL_KEYWORDS (func=<built-in method run of _contextvars.Context object at remote 0x7ffff2441280>, args=0x7ffff24454f8, 
    nargsf=<optimized out>, kwnames=0x0) at ../Objects/methodobject.c:446
#21 0x000055555569bd87 in do_call_core (kwdict=0x0, callargs=(<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2441140>,), 
    func=<built-in method run of _contextvars.Context object at remote 0x7ffff2441280>, trace_info=0x7fffffffdb90, tstate=<optimized out>) at ../Python/ceval.c:5943
#22 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4277
#23 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x7ffff6b7a510, for file /usr/lib/python3.10/asyncio/events.py, line 80, in _run (self=<Handle at remote 0x7ffff243a980>), tstate=0x555555b5c120)
    at ../Include/internal/pycore_ceval.h:46
#24 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff6783ec0, tstate=0x555555b5c120) at ../Python/ceval.c:5065
#25 _PyFunction_Vectorcall (func=<function at remote 0x7ffff6783eb0>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#26 0x0000555555699c14 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x55555600d150, callable=<function at remote 0x7ffff6783eb0>, tstate=0x555555b5c120)
    at ../Include/cpython/abstract.h:114
#27 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x55555600d150, callable=<function at remote 0x7ffff6783eb0>) at ../Include/cpython/abstract.h:123
#28 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffdd60, tstate=<optimized out>) at ../Python/ceval.c:5891
#29 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4198
#30 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x55555600cf80, for file /usr/lib/python3.10/asyncio/base_events.py, line 1896, in _run_once (self=<_UnixSelectorEventLoop(_timer_cancelled_count=0, _closed=False, _stopping=False, _ready=<collections.deque at remote 0x7ffff243a620>, _scheduled=[<TimerHandle at remote 0x7ffff2436490>], _default_executor=None, _internal_fds=1, _thread_id=140737352511488, _clock_resolution=<float at remote 0x7ffff25beb10>, _exception_handler=None, _debug=False, slow_callback_duration=<float at remote 0x7ffff6dfdb90>, _current_handle=None, _task_factory=None, _coroutine_origin_tracking_enabled=False, _coroutine_origin_tracking_saved_depth=None, _asyncgens=<WeakSet(data=set(), _remove=<function at remote 0x7ffff2429bd0>, _pending_removals=[], _iterating=s--Type <RET> for more, q to quit, c to continue without paging--
et()) at remote 0x7ffff2444d30>, _asyncgens_shutdown_called=False, _executor_shutdown_called=False, _selector=<EpollSelector(_fd_to_key={4: <SelectorKey at remote 0x7ffff243f880>}, _map=<_SelectorMapping(_selector=<...>) at remote 0x7ffff2444df0>, _selector=<select.epoll at...(truncated), tstate=0x555555b5c120) at ../Include/internal/pycore_ceval.h:46
#31 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff61204d0, tstate=0x555555b5c120) at ../Python/ceval.c:5065
#32 _PyFunction_Vectorcall (func=<function at remote 0x7ffff61204c0>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#33 0x0000555555699c14 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff2562b68, callable=<function at remote 0x7ffff61204c0>, tstate=0x555555b5c120)
    at ../Include/cpython/abstract.h:114
#34 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff2562b68, callable=<function at remote 0x7ffff61204c0>) at ../Include/cpython/abstract.h:123
#35 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffdf30, tstate=<optimized out>) at ../Python/ceval.c:5891
#36 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4198
#37 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x7ffff25629f0, for file /usr/lib/python3.10/asyncio/base_events.py, line 600, in run_forever (self=<_UnixSelectorEventLoop(_timer_cancelled_count=0, _closed=False, _stopping=False, _ready=<collections.deque at remote 0x7ffff243a620>, _scheduled=[<TimerHandle at remote 0x7ffff2436490>], _default_executor=None, _internal_fds=1, _thread_id=140737352511488, _clock_resolution=<float at remote 0x7ffff25beb10>, _exception_handler=None, _debug=False, slow_callback_duration=<float at remote 0x7ffff6dfdb90>, _current_handle=None, _task_factory=None, _coroutine_origin_tracking_enabled=False, _coroutine_origin_tracking_saved_depth=None, _asyncgens=<WeakSet(data=set(), _remove=<function at remote 0x7ffff2429bd0>, _pending_removals=[], _iterating=set()) at remote 0x7ffff2444d30>, _asyncgens_shutdown_called=False, _executor_shutdown_called=False, _selector=<EpollSelector(_fd_to_key={4: <SelectorKey at remote 0x7ffff243f880>}, _map=<_SelectorMapping(_selector=<...>) at remote 0x7ffff2444df0>, _selector=<select.epoll a...(truncated), tstate=0x555555b5c120) at ../Include/internal/pycore_ceval.h:46
#38 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff611e960, tstate=0x555555b5c120) at ../Python/ceval.c:5065
#39 _PyFunction_Vectorcall (func=<function at remote 0x7ffff611e950>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#40 0x0000555555699c14 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x555555bddfa8, callable=<function at remote 0x7ffff611e950>, tstate=0x555555b5c120)
    at ../Include/cpython/abstract.h:114
#41 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x555555bddfa8, callable=<function at remote 0x7ffff611e950>) at ../Include/cpython/abstract.h:123
#42 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe100, tstate=<optimized out>) at ../Python/ceval.c:5891
#43 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4198
#44 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x555555bdddc0, for file /home/wes/git/PythonMonkey/./pmjs, line 366, in main (enterRepl=True, forceRepl=False, opts=[], output=None, verbose=False, loop=<_UnixSelectorEventLoop(_timer_cancelled_count=0, _closed=False, _stopping=False, _ready=<collections.deque at remote 0x7ffff243a620>, _scheduled=[<TimerHandle at remote 0x7ffff2436490>], _default_executor=None, _internal_fds=1, _thread_id=140737352511488, _clock_resolution=<float at remote 0x7ffff25beb10>, _exception_handler=None, _debug=False, slow_callback_duration=<float at remote 0x7ffff6dfdb90>, _current_handle=None, _task_factory=None, _coroutine_origin_tracking_enabled=False, _coroutine_origin_tracking_saved_depth=None, _asyncgens=<WeakSet(data=set(), _remove=<function at remote 0x7ffff2429bd0>, _pending_removals=[], _iterating=set()) at remote 0x7ffff2444d30>, _asyncgens_shutdown_called=False, _executor_shutdown_called=False, _selector=<EpollSelector(_fd_to_key={4: <SelectorKey at remote 0x7ffff243f880>}, _map=<_SelectorMapping(_selector=<...>...(truncated), tstate=0x555555b5c120) at ../Include/internal/pycore_ceval.h:46
#45 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff2429520, tstate=0x555555b5c120) at ../Python/ceval.c:5065
#46 _PyFunction_Vectorcall (func=<function at remote 0x7ffff2429510>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#47 0x0000555555699a1d in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff2429510>, tstate=0x555555b5c120)
    at ../Include/cpython/abstract.h:114
#48 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff2429510>) at ../Include/cpython/abstract.h:123
#49 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe2d0, tstate=<optimized out>) at ../Python/ceval.c:5891
#50 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4213
#51 0x0000555555696176 in _PyEval_EvalFrame (throwflag=0, f=Frame 0x7ffff6d29c40, for file /home/wes/git/PythonMonkey/./pmjs, line 373, in <module> (), tstate=0x555555b5c120)
    at ../Include/internal/pycore_ceval.h:46
#52 _PyEval_Vector (tstate=0x555555b5c120, con=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=<optimized out>) at ../Python/ceval.c:5065
#53 0x000055555578bc56 in PyEval_EvalCode (co=<code at remote 0x7ffff6c9f680>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/./pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/./pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24770>, 'readline': <module at remote 0x7ffff6ccda30>, 'signal': <module at remote 0x7ffff6cce890>, 'getopt': <module at remote 0x7ffff6cceb10>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff610b380>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2429360>, 'initGlobalThis': <function at remote 0x7ffff2429480>, 'main': <function at remote 0x7ffff2429510>}, 
    locals=<optimized out>) at ../Python/ceval.c:1134
#54 0x00005555557b8b18 in run_eval_code_obj (tstate=0x555555b5c120, co=0x7ffff6c9f680, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/./pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/./pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24770>, 'readline': <module at remote 0x7ffff6ccda30>, 'signal': <module at remote 0x7ffff6cce890>, 'getopt': <module at remote 0x7ffff6cc--Type <RET> for more, q to quit, c to continue without paging--
eb10>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff610b380>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2429360>, 'initGlobalThis': <function at remote 0x7ffff2429480>, 'main': <function at remote 0x7ffff2429510>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/./pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/./pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24770>, 'readline': <module at remote 0x7ffff6ccda30>, 'signal': <module at remote 0x7ffff6cce890>, 'getopt': <module at remote 0x7ffff6cceb10>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff610b380>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2429360>, 'initGlobalThis': <function at remote 0x7ffff2429480>, 'main': <function at remote 0x7ffff2429510>})
    at ../Python/pythonrun.c:1291
#55 0x00005555557b196b in run_mod (mod=<optimized out>, filename=<optimized out>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/./pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/./pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24770>, 'readline': <module at remote 0x7ffff6ccda30>, 'signal': <module at remote 0x7ffff6cce890>, 'getopt': <module at remote 0x7ffff6cceb10>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff610b380>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2429360>, 'initGlobalThis': <function at remote 0x7ffff2429480>, 'main': <function at remote 0x7ffff2429510>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/./pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/./pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24770>, 'readline': <module at remote 0x7ffff6ccda30>, 'signal': <module at remote 0x7ffff6cce890>, 'getopt': <module at remote 0x7ffff6cceb10>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff610b380>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2429360>, 'initGlobalThis': <function at remote 0x7ffff2429480>, 'main': <function at remote 0x7ffff2429510>}, 
    flags=<optimized out>, arena=<optimized out>) at ../Python/pythonrun.c:1312
#56 0x00005555557b8865 in pyrun_file (fp=fp@entry=0x555555b5e4f0, filename=filename@entry='/home/wes/git/PythonMonkey/./pmjs', start=start@entry=257, 
    globals=globals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/./pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/./pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24770>, 'readline': <module at remote 0x7ffff6ccda30>, 'signal': <module at remote 0x7ffff6cce890>, 'getopt': <module at remote 0x7ffff6cceb10>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff610b380>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2429360>, 'initGlobalThis': <function at remote 0x7ffff2429480>, 'main': <function at remote 0x7ffff2429510>}, 
    locals=locals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/./pmjs') at remote 0x7ffff6c01090>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/./pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24770>, 'readline': <module at remote 0x7ffff6ccda30>, 'signal': <module at remote 0x7ffff6cce890>, 'getopt': <module at remote 0x7ffff6cceb10>, 'asyncio': <module at remote 0x7ffff6add940>, 'pm': <module at remote 0x7ffff610b380>, 'globalThis': {}, 'evalOptions': {'strict': False}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2429360>, 'initGlobalThis': <function at remote 0x7ffff2429480>, 'main': <function at remote 0x7ffff2429510>}, 
    closeit=closeit@entry=1, flags=0x7fffffffe578) at ../Python/pythonrun.c:1208
#57 0x00005555557b7d48 in _PyRun_SimpleFileObject (fp=0x555555b5e4f0, filename='/home/wes/git/PythonMonkey/./pmjs', closeit=1, flags=0x7fffffffe578) at ../Python/pythonrun.c:456
#58 0x00005555557b7a43 in _PyRun_AnyFileObject (fp=0x555555b5e4f0, filename='/home/wes/git/PythonMonkey/./pmjs', closeit=1, flags=0x7fffffffe578) at ../Python/pythonrun.c:90
#59 0x00005555557a8c3e in pymain_run_file_obj (skip_source_first_line=0, filename='/home/wes/git/PythonMonkey/./pmjs', 
    program_name='/home/wes/.cache/pypoetry/virtualenvs/pythonmonkey-StuBmUri-py3.10/bin/python') at ../Modules/main.c:353
#60 pymain_run_file (config=0x555555b40550) at ../Modules/main.c:372
#61 pymain_run_python (exitcode=0x7fffffffe574) at ../Modules/main.c:587
#62 Py_RunMain () at ../Modules/main.c:666
#63 0x000055555577ebcd in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at ../Modules/main.c:720
#64 0x00007ffff7c29d90 in __libc_start_call_main (main=main@entry=0x55555577eb90 <main>, argc=argc@entry=3, argv=argv@entry=0x7fffffffe788) at ../sysdeps/nptl/libc_start_call_main.h:58
#65 0x00007ffff7c29e40 in __libc_start_main_impl (main=0x55555577eb90 <main>, argc=3, argv=0x7fffffffe788, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffffffe778) at ../csu/libc-start.c:392
#66 0x000055555577eac5 in _start ()
(gdb) info threads
  Id   Target Id                                       Frame 
* 1    Thread 0x7ffff7e73000 (LWP 1145448) "python"    0x00007ffff44e1a24 in JS_GetPropertyById(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::PropertyKey>, JS::MutableHandle<JS::Value>) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
  3    Thread 0x7ffff35fe640 (LWP 1145452) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ddb2c0)
    at ./nptl/futex-internal.c:57
  4    Thread 0x7ffff33ff640 (LWP 1145453) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ddb2c0)
    at ./nptl/futex-internal.c:57
  5    Thread 0x7ffff3200640 (LWP 1145454) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ddb2c0)
    at ./nptl/futex-internal.c:57
  6    Thread 0x7ffff3001640 (LWP 1145455) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ddb2c0)
    at ./nptl/futex-internal.c:57
  7    Thread 0x7ffff2e02640 (LWP 1145456) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ddb2c0)
    at ./nptl/futex-internal.c:57
  8    Thread 0x7ffff2c03640 (LWP 1145457) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ddb2c0)
    at ./nptl/futex-internal.c:57
  9    Thread 0x7ffff2a04640 (LWP 1145458) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ddb2c0)
    at ./nptl/futex-internal.c:57
  10   Thread 0x7ffff2805640 (LWP 1145459) "JS Helper" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ddb2c4)
    at ./nptl/futex-internal.c:57
(gdb)

Sequence interface "contains" method implementation is missing for Objects thus Operation "in" is not implemented yet

Issue type

Support

How did you install PythonMonkey?

Source

OS platform and distribution

No response

Python version (python --version)

No response

PythonMonkey version (pip show pythonmonkey)

latest main

Bug Description

Operation "in" is not implemented yet

Standalone code to reproduce the issue

import pythonmonkey as pm

pm.eval("let obj = {'c':5}")
a = pm.eval('obj')
'c' in a

-> yields False but should be True

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Object methods use incorrect `this`

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

Ubuntu 22.04

Python version (python --version)

Python 3.10.12

PythonMonkey version (pip show pythonmonkey)

0.2.1

Bug Description

When calling the method of a class, this in the scope of the function is globalThis and not the function's this

example.js

// old style class
function Rectangle(w, h) {
  this.w = w;
  this.h = h
}
 
Rectangle.prototype = {
  getThis: function () {
    return this;
  },
  getArea: function () {
    return this.w * this.h;
  },
};

// es5 class
class Rectangle2 {
  constructor(w,h) {
    this.w = w;
    this.h = h;
  }

  getThis() {
    return this;
  }

  getArea() {
    return this.w * this.h;
  }
}

module.exports.Rectangle = Rectangle;
module.exports.Rectangle2 = Rectangle2;

main.py

import pythonmonkey as pm

example = pm.require('./example')
r = pm.new(example.Rectangle)(1,2)

print(r.getArea()) # nan, should be 2
print(r.getThis()) # globalThis, should be { w: 1, h: 2 }

###
r2 = pm.new(example.Rectangle2)(1,2)

print(r2.getArea()) # nan, should be 2
print(r2.getThis()) # globalThis, should be { w: 1, h: 2 }

--- When I run python3 main.py I get the following output:

nan
{'python': {'pythonMonkey': {'dir': '/home/will/.local/lib/python3.10/site-packages/pythonmonkey', 'isCompilableUnit': <built-in function isCompilableUnit>, 'nodeModules': '/home/will/.local/lib/python3.10/site-packages/pythonmonkey/node_modules'}, 'stdout': {'write': <function <lambda> at 0x7fec94386710>, 'read': <function <lambda> at 0x7fec90642290>}, 'stderr': {'write': <function <lambda> at 0x7fec9079a830>, 'read': <function <lambda> at 0x7fec90642320>}, 'print': <built-in function print>, 'eval': <built-in function eval>, 'exec': <built-in function exec>, 'getenv': <function getenv at 0x7fec94373880>, 'paths': ['/home/will/test/pm-bug/getArea', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/will/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages'], 'exit': <built-in method JSFunctionCallable of tuple object at 0x7fec90458340>, 'load': <function load at 0x7fec90642560>}, 'pmEval': <built-in function eval>, 'bootstrap': {'modules': {'vm': {'runInContext': <built-in method JSFunctionCallable of tuple object at 0x7fec904584c0>}, 'ctx-module': {'makeNodeProgramContext': <built-in method JSFunctionCallable of tuple object at 0x7fec90458540>, 'CtxModule': <built-in method JSFunctionCallable of tuple object at 0x7fec90458500>}, 'debug': <built-in method JSFunctionCallable of tuple object at 0x7fec90458480>, 'fs': {'constants': {'S_IFDIR': 16384.0}, 'statSync': <built-in method JSFunctionCallable of tuple object at 0x7fec90458580>, 'statSync_inner': <function statSync_inner at 0x7fec906423b0>, 'readFileSync': <function readFileSync at 0x7fec90642440>, 'existsSync': <function existsSync at 0x7fec906424d0>}}, 'require': <built-in method JSFunctionCallable of tuple object at 0x7fec90458440>, 'builtinModules': {'debug': <built-in method JSFunctionCallable of tuple object at 0x7fec90458380>}}, 'console': {'log': <built-in method JSFunctionCallable of tuple object at 0x7fec90458600>, 'debug': <built-in method JSFunctionCallable of tuple object at 0x7fec90458640>, 'info': <built-in method JSFunctionCallable of tuple object at 0x7fec90458680>, 'warn': <built-in method JSFunctionCallable of tuple object at 0x7fec904586c0>, 'error': <built-in method JSFunctionCallable of tuple object at 0x7fec90458700>}, 'atob': <function <lambda> at 0x7fec90439d80>, 'btoa': <function <lambda> at 0x7fec90439ea0>}
nan
{'python': {'pythonMonkey': {'dir': '/home/will/.local/lib/python3.10/site-packages/pythonmonkey', 'isCompilableUnit': <built-in function isCompilableUnit>, 'nodeModules': '/home/will/.local/lib/python3.10/site-packages/pythonmonkey/node_modules'}, 'stdout': {'write': <function <lambda> at 0x7fec94386710>, 'read': <function <lambda> at 0x7fec90642290>}, 'stderr': {'write': <function <lambda> at 0x7fec9079a830>, 'read': <function <lambda> at 0x7fec90642320>}, 'print': <built-in function print>, 'eval': <built-in function eval>, 'exec': <built-in function exec>, 'getenv': <function getenv at 0x7fec94373880>, 'paths': ['/home/will/test/pm-bug/getArea', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/will/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages'], 'exit': <built-in method JSFunctionCallable of tuple object at 0x7fec90458bc0>, 'load': <function load at 0x7fec90642560>}, 'pmEval': <built-in function eval>, 'bootstrap': {'modules': {'vm': {'runInContext': <built-in method JSFunctionCallable of tuple object at 0x7fec90459300>}, 'ctx-module': {'makeNodeProgramContext': <built-in method JSFunctionCallable of tuple object at 0x7fec90459400>, 'CtxModule': <built-in method JSFunctionCallable of tuple object at 0x7fec90459480>}, 'debug': <built-in method JSFunctionCallable of tuple object at 0x7fec90459200>, 'fs': {'constants': {'S_IFDIR': 16384.0}, 'statSync': <built-in method JSFunctionCallable of tuple object at 0x7fec90459580>, 'statSync_inner': <function statSync_inner at 0x7fec906423b0>, 'readFileSync': <function readFileSync at 0x7fec90642440>, 'existsSync': <function existsSync at 0x7fec906424d0>}}, 'require': <built-in method JSFunctionCallable of tuple object at 0x7fec90459080>, 'builtinModules': {'debug': <built-in method JSFunctionCallable of tuple object at 0x7fec90459780>}}, 'console': {'log': <built-in method JSFunctionCallable of tuple object at 0x7fec90459840>, 'debug': <built-in method JSFunctionCallable of tuple object at 0x7fec904598c0>, 'info': <built-in method JSFunctionCallable of tuple object at 0x7fec90459940>, 'warn': <built-in method JSFunctionCallable of tuple object at 0x7fec904599c0>, 'error': <built-in method JSFunctionCallable of tuple object at 0x7fec90459a40>}, 'atob': <function <lambda> at 0x7fec90439d80>, 'btoa': <function <lambda> at 0x7fec90439ea0>}

getArea returns nan because globalThis.w === undefined and undefined * undefined = NaN, getThis returns globalThis because this is not set to the object this.

Standalone code to reproduce the issue

import pythonmonkey as pm

pm.eval("""
function Square(w) {
  this.w = w;
}
Square.prototype = {
  getThis: function () {
    return this;
  },
};
""")

Square = pm.globalThis.Square
r = pm.new(Square)(5)

print(r.getThis()) # globalThis, but should just be { w: 5 }

Relevant log output or backtrace

{'python': {'pythonMonkey': {'dir': '/home/will/.local/lib/python3.10/site-packages/pythonmonkey', 'isCompilableUnit': <built-in function isCompilableUnit>, 'nodeModules': '/home/will/.local/lib/python3.10/site-packages/pythonmonkey/node_modules'}, 'stdout': {'write': <function <lambda> at 0x7fb456a867a0>, 'read': <function <lambda> at 0x7fb452c42200>}, 'stderr': {'write': <function <lambda> at 0x7fb452d9a7a0>, 'read': <function <lambda> at 0x7fb452c42290>}, 'print': <built-in function print>, 'eval': <built-in function eval>, 'exec': <built-in function exec>, 'getenv': <function getenv at 0x7fb456a73880>, 'paths': ['/home/will/test/pm-bug/getArea', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/will/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages'], 'exit': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58380>, 'load': <function load at 0x7fb452c424d0>}, 'pmEval': <built-in function eval>, 'bootstrap': {'modules': {'vm': {'runInContext': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58500>}, 'ctx-module': {'makeNodeProgramContext': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58580>, 'CtxModule': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58540>}, 'debug': <built-in method JSFunctionCallable of tuple object at 0x7fb452a584c0>, 'fs': {'constants': {'S_IFDIR': 16384.0}, 'statSync': <built-in method JSFunctionCallable of tuple object at 0x7fb452a585c0>, 'statSync_inner': <function statSync_inner at 0x7fb452c42320>, 'readFileSync': <function readFileSync at 0x7fb452c423b0>, 'existsSync': <function existsSync at 0x7fb452c42440>}}, 'require': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58480>, 'builtinModules': {'debug': <built-in method JSFunctionCallable of tuple object at 0x7fb452a583c0>}}, 'console': {'log': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58640>, 'debug': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58680>, 'info': <built-in method JSFunctionCallable of tuple object at 0x7fb452a586c0>, 'warn': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58700>, 'error': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58740>}, 'atob': <function <lambda> at 0x7fb452a39cf0>, 'btoa': <function <lambda> at 0x7fb452a39e10>, 'Square': <built-in method JSFunctionCallable of tuple object at 0x7fb452a58340>}

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

pythonmonkey.SpiderMonkeyError: InternalError: too much recursion

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

Linux Mint 20.3 x86_64

Python version (python --version)

3.9.17

PythonMonkey version (pip show pythonmonkey)

0.2.1

Bug Description

doing a require inside a Django application results a recursion error

from pythonmonkey import require

def view(request)
    require('./module.js')
    ...
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 980, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 917, in run
    self._target(*self._args, **self._kwargs)
  File "/.../project/env/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/.../project/env/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 133, in inner_run
    self.check(display_num_errors=True)
  File "/.../project/env/lib/python3.9/site-packages/django/core/management/base.py", line 485, in check
    all_issues = checks.run_checks(
  File "/.../project/env/lib/python3.9/site-packages/django/core/checks/registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/.../project/env/lib/python3.9/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "/.../project/env/lib/python3.9/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    return check_method()
  File "/.../project/env/lib/python3.9/site-packages/django/urls/resolvers.py", line 494, in check
    for pattern in self.url_patterns:
  File "/.../project/env/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/.../project/env/lib/python3.9/site-packages/django/urls/resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/.../project/env/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/.../project/env/lib/python3.9/site-packages/django/urls/resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/.../project/example/project/urls.py", line 24, in <module>
    path("", include("core.urls")),
  File "/.../project/env/lib/python3.9/site-packages/django/urls/conf.py", line 38, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/.../project/example/apps/core/urls.py", line 1, in <module>
    from core import views
  File "/.../project/example/apps/core/views.py", line 6, in <module>
    from djust.views import api, render_jsx
  File "/.../project/src/djust/views.py", line 25, in <module>
    response = require(
  File "/.../project/env/lib/python3.9/site-packages/pythonmonkey/require.py", line 353, in require
    return createRequire(filename)(moduleIdentifier)
pythonmonkey.SpiderMonkeyError: InternalError: too much recursion

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Array indexing from numbers passed from JavaScript to Python doesn't work

Issue type

Bug

How did you install PythonMonkey?

Source

OS platform and distribution

Linux Ubuntu 22.04

Python version (python --version)

3.10

PythonMonkey version

0.0.1.dev1049+1323d65

Bug Description

Array indexing in Python from numbers passed from JavaScript fails since they're coerced to floats in Python. When running code with pmjs, the error message is a lot harder to understand SystemError: error return without exception set and may involve other issues, but in Python with pythonmonkey it reports TypeError: list indices must be integers or slices, not float.

Example 1

Code:

#!/usr/bin/env python3
import pythonmonkey as pm

[1,2,3][pm.eval("1")]

Error:

Traceback (most recent call last):
  File "/home/will/git/PythonMonkey/./example.py", line 5, in <module>
    [1,2,3][pm.eval("1")]
TypeError: list indices must be integers or slices, not float

Example 2

Code:

#!/usr/bin/env pmjs
python.exec(`
def setArrayAtIndex(array, index, new):
  array[index] = new 
  return array
`);
const setArrayAtIndex = python.eval("setArrayAtIndex")
const numbersBack = setArrayAtIndex([1,2,3], 1, 999);

Error:

Traceback (most recent call last):
  File "/home/will/git/PythonMonkey/./pmjs", line 348, in <module>
    main()
  File "/home/will/git/PythonMonkey/./pmjs", line 342, in main
    pm.runProgramModule(args[0], args, requirePath)
  File "/home/will/git/PythonMonkey/python/pythonmonkey/require.py", line 328, in runProgramModule
    pm.eval(mainModuleSource.read())
  File "<string>", line 3, in setArrayAtIndex
SystemError: error return without exception set

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

Related to MR https://github.com/Distributive-Network/PythonMonkey/pull/119

What branch of PythonMonkey were you developing on? (If applicable)

main

Segfault when using Object.values() and Object.entries()

Description

Converting a Python obj to JavaScript, and then attempting to run Object.values() and Object.entries() on it leads to a segfault.

Repro

In the pmjs REPL:

> obj = python.eval('{"a": 1, "b": 2, "c": 3}')
{"a":1,"b":2,"c":3}
> throughJS = (x) => x
(x) => x
> jsObj = throughJS(obj)
{"a":1,"b":2,"c":3}
> jsObj
{"a":1,"b":2,"c":3}
> Object.entries(jsObj)
Segmentation fault (core dumped)

Also happens with Object.values()

Several missing Dict methods

Issue type

Bug

How did you install PythonMonkey?

None

OS platform and distribution

No response

Python version (python --version)

No response

PythonMonkey version (pip show pythonmonkey)

No response

Bug Description

-> see cPython dictobject.c

static PyMethodDef mapp_methods[] = {

DICT_GET_METHODDEF
DICT_SETDEFAULT_METHODDEF
DICT_POP_METHODDEF
DICT_POPITEM_METHODDEF
{"clear",           (PyCFunction)dict_clear,        METH_NOARGS,
 clear__doc__},
{"copy",            (PyCFunction)dict_copy,         METH_NOARGS,
 copy__doc__},
{NULL,              NULL}   /* sentinel */

};

I took out the iteration-related methods and put them in

#190

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Get rid of automatic source code transformation

Describe your feature request here.

The last two times I have pulled and built the main branch, git has shown that I have uncommitted changes because some tool in our build (uncrustify?) has modified the source code during the build by removing whitespace.

This needs to go away; the sooner the better.

Code example

No response

segfault in _PyEval_MakeFrameVector moving promises back and forth

Repro:

python.eval('(lambda x: throughJS(x))', { throughJS: x=>x })(new Promise(()=>1),     Promise)

Version:
0.0.1.dev1024+117d00f
932a3ce

Stack:

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
_PyEval_MakeFrameVector (tstate=<optimized out>, con=0x7ffff2b71640, locals=<optimized out>, args=<optimized out>, argcount=2, kwnames=<optimized out>) at ../Python/ceval.c:4824
4824	../Python/ceval.c: No such file or directory.
(gdb) bt
#0  _PyEval_MakeFrameVector (tstate=<optimized out>, con=0x7ffff2b71640, locals=<optimized out>, args=<optimized out>, argcount=2, kwnames=<optimized out>) at ../Python/ceval.c:4824
#1  0x00005555556b14be in _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff2b71640, tstate=0x555555b5bf80)
    at ../Python/ceval.c:5057
#2  _PyFunction_Vectorcall (func=<function at remote 0x7ffff2b71630>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#3  0x00007ffff6a26b4f in callPyFunc (cx=0x555555cb4090, argc=<optimized out>, vp=0x555555dd2a90) at /home/wes/git/PythonMonkey/src/jsTypeFactory.cc:231
#4  0x00007ffff4b55ed9 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#5  0x00007ffff4b501a4 in Interpret(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#6  0x00007ffff4b4731a in js::RunScript(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#7  0x00007ffff4b57187 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, js::AbstractFramePtr, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#8  0x00007ffff4b79e4c in EvalKernel(JSContext*, JS::Handle<JS::Value>, EvalType, js::AbstractFramePtr, JS::Handle<JSObject*>, unsigned char*, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#9  0x00007ffff4b79562 in js::IndirectEval(JSContext*, unsigned int, JS::Value*) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#10 0x00007ffff4b55ed9 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#11 0x00007ffff4b501a4 in Interpret(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#12 0x00007ffff4b4731a in js::RunScript(JSContext*, js::RunState&) () from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#13 0x00007ffff4b561cf in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#14 0x00007ffff4b56817 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#15 0x00007ffff4bedeb7 in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) ()
   from /home/wes/git/PythonMonkey/python/pythonmonkey/libmozjs-102.so
#16 0x00007ffff6a27878 in callJSFunc (jsCxThisFuncTuple=<optimized out>, args=<optimized out>) at /usr/local/include/mozjs-102/js/RootingAPI.h:1216
#17 0x00005555556b0cc8 in cfunction_call (func=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67dc0>, args=<optimized out>, kwargs=<optimized out>)
    at ../Objects/methodobject.c:552
#18 0x00005555556a772b in _PyObject_MakeTpCall (tstate=0x555555b5bf80, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67dc0>, args=<optimized out>, 
    nargs=<optimized out>, keywords=0x0) at ../Objects/call.c:215
#19 0x00005555556a00e7 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=<optimized out>, 
    callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67dc0>, tstate=<optimized out>) at ../Include/cpython/abstract.h:112
#20 _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x555555ef18c0, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67dc0>, 
    tstate=<optimized out>) at ../Include/cpython/abstract.h:99
#21 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x555555ef18c0, callable=<built-in method JSFunctionCallable of tuple object at remote 0x7ffff2b67dc0>)
    at ../Include/cpython/abstract.h:123
#22 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffdf20, tstate=<optimized out>) at ../Python/ceval.c:5891
#23 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4181
#24 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x555555ef16f0, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 203, in repl (save_history=<function at remote 0x7ffff2b712d0>, atexit=<module at remote 0x7ffff2b864d0>, sigint_handler=<function at remote 0x7ffff2b713f0>), tstate=0x555555b5bf80) at ../Include/internal/pycore_ceval.h:46
#25 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff6d63da0, tstate=0x555555b5bf80) at ../Python/ceval.c:5065
#26 _PyFunction_Vectorcall (func=<function at remote 0x7ffff6d63d90>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#27 0x0000555555699a1d in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x555555ddeb18, callable=<function at remote 0x7ffff6d63d90>, tstate=0x555555b5bf80)
    at ../Include/cpython/abstract.h:114
#28 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x555555ddeb18, callable=<function at remote 0x7ffff6d63d90>) at ../Include/cpython/abstract.h:123
#29 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe0f0, tstate=<optimized out>) at ../Python/ceval.c:5891
#30 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4213
#31 0x00005555556b14ec in _PyEval_EvalFrame (throwflag=0, 
    f=Frame 0x555555dde960, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 309, in main (enterRepl=True, forceRepl=False, globalInitModule={}, opts=[], args=[], output=None, verbose=False), tstate=0x555555b5bf80) at ../Include/internal/pycore_ceval.h:46
#32 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=<optimized out>, locals=0x0, con=0x7ffff2b71250, tstate=0x555555b5bf80) at ../Python/ceval.c:5065
--Type <RET> for more, q to quit, c to continue without paging--
#33 _PyFunction_Vectorcall (func=<function at remote 0x7ffff2b71240>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:342
#34 0x0000555555699a1d in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff2b71240>, tstate=0x555555b5bf80)
    at ../Include/cpython/abstract.h:114
#35 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff6d29da8, callable=<function at remote 0x7ffff2b71240>) at ../Include/cpython/abstract.h:123
#36 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, trace_info=0x7fffffffe2c0, tstate=<optimized out>) at ../Python/ceval.c:5891
#37 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:4213
#38 0x0000555555696176 in _PyEval_EvalFrame (throwflag=0, f=Frame 0x7ffff6d29c40, for file /home/wes/git/PythonMonkey/tests/js/../../pmjs, line 312, in <module> (), tstate=0x555555b5bf80)
    at ../Include/internal/pycore_ceval.h:46
#39 _PyEval_Vector (tstate=0x555555b5bf80, con=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=<optimized out>) at ../Python/ceval.c:5065
#40 0x000055555578bc56 in PyEval_EvalCode (co=<code at remote 0x7ffff6c72c30>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, locals=<optimized out>) at ../Python/ceval.c:1134
#41 0x00005555557b8b18 in run_eval_code_obj (tstate=0x555555b5bf80, co=0x7ffff6c72c30, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}) at ../Python/pythonrun.c:1291
#42 0x00005555557b196b in run_mod (mod=<optimized out>, filename=<optimized out>, 
    globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, 
    locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, flags=<optimized out>, arena=<optimized out>)
    at ../Python/pythonrun.c:1312
#43 0x00005555557b8865 in pyrun_file (fp=fp@entry=0x555555b5e350, filename=filename@entry='/home/wes/git/PythonMonkey/tests/js/../../pmjs', start=start@entry=257, 
    globals=globals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, 
    locals=locals@entry={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='/home/wes/git/PythonMonkey/tests/js/../../pmjs') at remote 0x7ffff6c010f0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff6d905e0>, '__file__': '/home/wes/git/PythonMonkey/tests/js/../../pmjs', '__cached__': None, 'sys': <module at remote 0x7ffff6d7e250>, 'os': <module at remote 0x7ffff6c24720>, 'readline': <module at remote 0x7ffff6ccd800>, 'signal': <module at remote 0x7ffff6cce660>, 'getopt': <module at remote 0x7ffff6cce930>, 'pm': <module at remote 0x7ffff6add620>, 'globalThis': {}, 'requirePath': False, 'repl': <function at remote 0x7ffff6d63d90>, 'usage': <function at remote 0x7ffff2b71090>, 'initGlobalThis': <function at remote 0x7ffff2b711b0>, 'main': <function at remote 0x7ffff2b71240>}, closeit=closeit@entry=1, flags=0x7fffffffe568)
    at ../Python/pythonrun.c:1208
#44 0x00005555557b7d48 in _PyRun_SimpleFileObject (fp=0x555555b5e350, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', closeit=1, flags=0x7fffffffe568)
--Type <RET> for more, q to quit, c to continue without paging--
    at ../Python/pythonrun.c:456
#45 0x00005555557b7a43 in _PyRun_AnyFileObject (fp=0x555555b5e350, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', closeit=1, flags=0x7fffffffe568) at ../Python/pythonrun.c:90
#46 0x00005555557a8c3e in pymain_run_file_obj (skip_source_first_line=0, filename='/home/wes/git/PythonMonkey/tests/js/../../pmjs', 
    program_name='/home/wes/.cache/pypoetry/virtualenvs/pythonmonkey-NiDIb4WW-py3.10/bin/python') at ../Modules/main.c:353
#47 pymain_run_file (config=0x555555b40400) at ../Modules/main.c:372
#48 pymain_run_python (exitcode=0x7fffffffe564) at ../Modules/main.c:587
#49 Py_RunMain () at ../Modules/main.c:666
#50 0x000055555577ebcd in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at ../Modules/main.c:720
#51 0x00007ffff7c29d90 in __libc_start_call_main (main=main@entry=0x55555577eb90 <main>, argc=argc@entry=2, argv=argv@entry=0x7fffffffe778) at ../sysdeps/nptl/libc_start_call_main.h:58
#52 0x00007ffff7c29e40 in __libc_start_main_impl (main=0x55555577eb90 <main>, argc=2, argv=0x7fffffffe778, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffffffe768) at ../csu/libc-start.c:392
#53 0x000055555577eac5 in _start ()

Dates are offset by timezone

>>> pm.eval('new Date(Date.UTC(1970, 0, 0, 0, 0, 0))') -  datetime.datetime.utcfromtimestamp(0)
datetime.timedelta(days=-2, seconds=68400)

There should be no delta.

Tested with - commit b62bd55 (HEAD -> feature/js-test-coverage)
test - tests/js/js2py/datetime2.simple.failing

dict or operation not implemented yet

Issue type

Bug

How did you install PythonMonkey?

None

OS platform and distribution

No response

Python version (python --version)

No response

PythonMonkey version (pip show pythonmonkey)

No response

Bug Description

import pythonmonkey as pm

a = pm.eval("({'c':5})")
b = pm.eval("({'d':7})")

a | b
JSObjectProxy_get
JSObjectProxy_get
Segmentation fault (core dumped)

same for in_place

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.