Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node -p resolves promises earlier in Node.js 22 than previous releases #56144

Closed
andreas-schwab opened this issue Dec 5, 2024 · 3 comments
Closed
Labels
cli Issues and PRs related to the Node.js command line interface. invalid Issues and PRs that are invalid.

Comments

@andreas-schwab
Copy link
Contributor

andreas-schwab commented Dec 5, 2024

EDIT: background from pscript test suite On riscv64 the testsuite of the pscript python modules fails:

=================================== FAILURES ===================================
______________________ TestFunctions.test_async_and_await ______________________

self = <test_parser2.TestFunctions object at 0x7f2d4a4f2e10>

def test_async_and_await(self):
    if sys.version_info < (3, 6):
        return

    foo = py2js('async def foo(): return 42\n\n')
    spam = py2js('async def spam(): print(await foo())\n\n')
    eggs = py2js('async def eggs(): return await foo()\n\n')
    js = foo + spam + eggs

    assert 'Promise' in evaljs(js + 'foo()')
    assert 'Promise' in evaljs(js + 'spam()')
    assert 'Promise' in evaljs(js + 'eggs()')

    assert '42' in evaljs(js + 'spam()')
  assert '42' not in evaljs(js + 'eggs()')

E AssertionError: assert '42' not in 'Promise { 42 }'
E
E '42' is contained here:
E Promise { 42 }
E ? ++

pscript/tests/test_parser2.py:874: AssertionError
=========================== short test summary info ============================
FAILED pscript/tests/test_parser2.py::TestFunctions::test_async_and_await - A...
============= 1 failed, 223 passed, 2 skipped in 670.27s (0:11:10) =============

This is a regression from node21:

$ node22 -p -e 'var foo; foo = async function flx_foo () { return 42; }; var eggs; eggs = async function flx_eggs () { return await foo(); }; eggs()'
Promise { 42 }
$ node21 -p -e 'var foo; foo = async function flx_foo () { return 42; }; var eggs; eggs = async function flx_eggs () { return await foo(); }; eggs()'
Promise { <pending> }
@targos targos added the riscv64 Issues and PRs related to the riscv64 architecture. label Dec 5, 2024
@joyeecheung
Copy link
Member

joyeecheung commented Dec 5, 2024

It looks like what you are really reporting is something more like

$ node20 -p 'var foo; foo = async function flx_foo () { return 42; }; var eggs; eggs = async function flx_eggs () { return await foo(); }; eggs()'
Promise { <pending> }

$ node21 -p 'var foo; foo = async function flx_foo () { return 42; }; var eggs; eggs = async function flx_eggs () { return await foo(); }; eggs()'
Promise { 42 }

I can reproduce it on macOS + arm64 so I don't think it's a riscv64 issue.

I am not sure if this counts as a regression, however, there is no clear rule about when/whether the promises should be resolved before node -p prints something - or generally node -p has a lot of undocumented areas and undefined behaviors. It looks more like undefined behaviors that you should not rely on?

@joyeecheung joyeecheung added cli Issues and PRs related to the Node.js command line interface. and removed riscv64 Issues and PRs related to the riscv64 architecture. labels Dec 5, 2024
@joyeecheung joyeecheung changed the title node22 breaks pscript python module node -p resolves promises earlier in Node.js 22 than previous releases Dec 5, 2024
@aduh95
Copy link
Contributor

aduh95 commented Dec 5, 2024

It's not a bug, it's a feature: #52172

@joyeecheung
Copy link
Member

Closing since this is a semver-major feature.

@joyeecheung joyeecheung added the invalid Issues and PRs that are invalid. label Dec 5, 2024
@aduh95 aduh95 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Issues and PRs related to the Node.js command line interface. invalid Issues and PRs that are invalid.
Projects
None yet
Development

No branches or pull requests

4 participants