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

I want to run a js file that I wrote myself #153

Open
Guo-yyds opened this issue Oct 10, 2024 · 11 comments
Open

I want to run a js file that I wrote myself #153

Guo-yyds opened this issue Oct 10, 2024 · 11 comments

Comments

@Guo-yyds
Copy link

I have two questions:
Question one:
What is the relationship between this and spidermonkey?
What is the structure of this project that I see mainly in the test section consisting of wasmtime + wasmtools?
What does this have to do with spidermonkey?
Question two:
I want to run a js file that I wrote myself. How do I do it? tests is too confusing

@drogus
Copy link

drogus commented Oct 11, 2024

What is the relationship between this and spidermonkey?

This project uses SpiderMonke under the hood, but adds necessary bindings and glue code to allow run SpiderMonkey as a WASI component.

I want to run a js file that I wrote myself. How do I do it? tests is too confusing

The easiest way is to use componentize.sh to merge the js file into WASM, it's described at the end of the usage section

@Guo-yyds
Copy link
Author

image
What does this code in componentize.sh mean?

I try this with the following code:

./componentize.sh my.js
wasmtime my.wasm

my.js

console.log("hellow world")

but it is error
image

In the last question, I want to ask SpiderMoinkey to print intermediate garbage collection information. Is it possible to solve this problem by adding parameters?

@drogus
Copy link

drogus commented Oct 15, 2024

What does this code in componentize.sh mean?

Wizer is a tool to make the JS runtime instantiation quicker. It starts the runtime and dumps the memory after start, so when it's loaded to WASM it doesn't have to be initialized. From what I read it lowers the time to start SpiderMonkey in WASM from 10-20 miliseconds to a few microseconds.

but it is error

What version of wasmtime binary do you have? It looks like it doesn't provide implementation for some of the WASI APIs 🤔

In the last question, I want to ask SpiderMoinkey to print intermediate garbage collection information. Is it possible to solve this problem by adding parameters?

For that I'm not sure. You could probably add your own C++ functions and bind them to JavaScript APIs, but I'm not sure if there's something like that already available or if you have to write your own implementation

@tschneidereit
Copy link
Member

@Guo-yyds the resulting component imports a few different WASI interfaces, not all of which are enabled by default by wasmtime. If you change wasmtime ghn.wasm to wasmtime -S http ghn.wasm, things should work. (Though nothing would actually happen, because your JS file already has fully executed during the componentization step.)

@Guo-yyds
Copy link
Author

I also want to ask why the componentization phase executes js code?

image

Is the project structured like this?

@tschneidereit
Copy link
Member

Yes, that's roughly correct.

As @drogus says, executing the top-level script during componentization makes it so that when processing an event later on, the script doesn't have to be run over and over again.

If you don't want this to happen, you can call componentize.sh without passing in a JS file. You can then run wasmtime -S http ghn.wasm my.js, and it should print hello world

@Guo-yyds
Copy link
Author

image
If you do not input, it does not seem to be possible

@cfallin
Copy link
Member

cfallin commented Oct 16, 2024

@Guo-yyds, I don't have an answer to your question, but would you mind posting plain text rather than screenshots? I am sure you mean well, but screenshots are a fairly inaccessible way to present text for several reasons, which I described in this comment previously. Thanks!

@Guo-yyds
Copy link
Author

componentize.txt
I want to call componentize.sh without passing in a JS file, but it is error

./componentize my.js

@tschneidereit
Copy link
Member

@Guo-yyds thank you for trying to heed Chris' advice! ❤️ Unfortunately the .txt file is even harder to use on GitHub than an image, because it always automatically downloads, and then one has to open it manually. Could you instead past the contents in a block here? E.g., if you want to share a shell script, you could do so with this kind of block:

```sh
echo "hello world"
```

In this particular case though, it'd be even better if you could just link to the file in this repository, or ideally even to the exact part you mean (which you can do by clicking on the line number, and then Ctrl/Cmd-clicking a second line number to highlight a range of lines.)

@tschneidereit
Copy link
Member

As for your actual message: the shell input you mentioned does pass a JS file, so it wouldn't work.

This should I think work:

./componentize.sh -o my-component.wasm

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

4 participants