-
Notifications
You must be signed in to change notification settings - Fork 6
Port QuickJS to SideVM #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Updated: considering using core-js for polyfill since it always implemented almost all standard APIs. |
examples/incomingFetch.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this example show?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shows handling incoming HTTP Request in CF workers style API. (PoC)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding, fetch()
is a method to send http request. So incomingFetch
doesn't sound reasonable to me. Maybe consider incomingHttpRequest
or lowLevelHttpServer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe listeningFetchEvents
? Because that's CF workers gave it the name.
There is already a low level http listening example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I didn't research a lot, but I also searched on CF worker's example page and didn't find name like this. Good to use listeningFetchEvents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
This PR ports QuickJS to SideVM and adds support for async IO.
There are a few implemented async APIs includes
setTimeout/setInterval
,fetch
,XMLHttpRequest
,httpListen
.See
examples/
for features.The execution lifetime
As a SideVM program, it need to be deployed by a pink contract.
At startup,
sidevm-quickjs
would query to the host pink contract (bysidevm_init_script
) to get an entry js code to run. At any time when it running, the host pink contract can send more js code snippets to sidevm-quickjs instance to eval.A sidevm-quickjs instance can host multiple js vm instances, each js instance is associated with it's name. The host pink contract can reset/destroy js instances at any time via sending message.
See the e2e test
tests/tests/itWorks.ts
for detail.Related changes in pRuntime
This PR requires some changes to pRuntime to be applied:
Phala-Network/phala-blockchain#1366: for listening incoming HTTP request via pRPC endpoint.
Phala-Network/phala-blockchain#1398: for query init script from pink contract.
Phala-Network/phala-blockchain#1399: for charging sidevm instance and deploying to selected workers in transaction.