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

Cannot pass script file on embedtest command line #45484

Closed
pdpaulson opened this issue Nov 16, 2022 · 4 comments
Closed

Cannot pass script file on embedtest command line #45484

pdpaulson opened this issue Nov 16, 2022 · 4 comments

Comments

@pdpaulson
Copy link

pdpaulson commented Nov 16, 2022

Version

19.0.1

Platform

Linux sodela-laptop-3 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

embedtest.cc

What steps will reproduce the bug?

Build node from source

  1. git clone https://github.com/nodejs/node.git
  2. cd node
  3. git checkout v19.0.1
  4. ./configure --prefix=~/opt/node --shared
  5. make install

Create and build external embedtest project

  1. mkdir embedtest
  2. cd embedtest
  3. cp ~/node/test/embedding/embedtest.cc .
  4. Create Makefile
  5. make

Run the test

Run the command as follows:

LD_LIBRARY_PATH=~/opt/node/lib ./embedtest

See the following sections for test cases.

How often does it reproduce? Is there a required condition?

100%

What is the expected behavior?

There two test cases, one that passes a script by value on the command line, the second that passes the name of a script file on the command line. Here are the examples with expected behavior:

$ LD_LIBRARY_PATH=~/opt/node/lib ./embedtest -e "console.log('hello friend')"
hello friend

$ LD_LIBRARY_PATH=~/opt/node/lib ./embedtest test.js
hello friend

What do you see instead?

$ LD_LIBRARY_PATH=~/opt/node/lib ./embedtest -e "console.log('hello friend')"

$ LD_LIBRARY_PATH=~/opt/node/lib ./embedtest test.js
evalmachine.<anonymous>:1
test.js
^

ReferenceError: test is not defined
    at evalmachine.<anonymous>:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:313:38)
    at node:embedder_main_0:1:173

Node.js v19.0.1

Additional information

The first test case works if the -e option is not used. For example,

$ LD_LIBRARY_PATH=~/opt/node/lib ./embedtest "console.log('hello friend')"
hello friend

The Makefile and script file are attached.

Makefile and test.js files

makefile-and-js.zip

@bnoordhuis
Copy link
Member

I assume you're coming at this having looked through doc/api/embedding.md? It explicitly says "perform[s] the equivalent of node -e <code>".

Change ./embedtest test.js to ./embedtest 'require("./test.js") and it'll work.

@pdpaulson
Copy link
Author

I was looking at https://nodejs.org/api/embedding.html, but I see that it also states the same thing. Thanks for the clarification.

@bnoordhuis
Copy link
Member

No problem. I'll close this then but I can convert it to a discussion if you have follow-up questions.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2022
@pdpaulson
Copy link
Author

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants