rqjs_ext/modules/
console.rs1use std::env;
2
3use crate::modules::module::export_default;
4use once_cell::sync::Lazy;
5use rquickjs::{
6 atom::PredefinedAtom,
7 function::{Constructor, Opt},
8 Class, Object, Value,
9};
10use rquickjs::{
11 module::{Declarations, Exports, ModuleDef},
12 prelude::Func,
13 AsyncContext, Ctx, Function, Result,
14};
15
16pub struct ConsoleModule;
17fn print(s: String) {
18 print!("{s}");
19}
20pub fn init(ctx: &Ctx<'_>) -> Result<()> {
21 let core = include_str!("../../deno-scripts/00_console.js");
22 let global = ctx.globals();
23 global
24 .set(
25 "__print",
26 Function::new(ctx.clone(), print)
27 .unwrap()
28 .with_name("__print")
29 .unwrap(),
30 )
31 .unwrap();
32 let _: Value = ctx.eval(core.as_bytes()).unwrap();
33 Ok(())
34}