Use default export as main JavaScript function
This commit is contained in:
parent
500368958f
commit
292d35280c
1 changed files with 2 additions and 2 deletions
|
@ -32,7 +32,7 @@ pub async fn run(
|
|||
// Enable async code in the runtime
|
||||
run.spawn_executor(&exe).detach();
|
||||
// Create the main function structure
|
||||
let src = format!("export async function main() {{ {} }}", src);
|
||||
let src = format!("export default async function() {{ {} }}", src);
|
||||
// Attempt to execute the script
|
||||
let res: Result<Promise<Value>, js::Error> = ctx.with(|ctx| {
|
||||
// Get the context global object
|
||||
|
@ -48,7 +48,7 @@ pub async fn run(
|
|||
// Attempt to compile the script
|
||||
let res = ctx.compile("script", src)?;
|
||||
// Attempt to fetch the main export
|
||||
let fnc = res.get::<_, Function>("main")?;
|
||||
let fnc = res.get::<_, Function>("default")?;
|
||||
// Execute the main function
|
||||
fnc.call((This(doc), Rest(arg)))
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue