Skip to content

Commit 93cdd94

Browse files
committed
Add browser.py module
1 parent 56bcb02 commit 93cdd94

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

wasm/lib/src/browser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from _browser import *
2+
from _js import JsValue
3+
from _window import window
4+
5+
6+
_alert = window.get_prop("alert")
7+
8+
9+
def alert(msg):
10+
if type(msg) != str:
11+
raise TypeError("msg must be a string")
12+
_alert.call(JsValue.fromstr(msg))

wasm/lib/src/browser_module.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,9 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
418418
pub fn setup_browser_module(vm: &VirtualMachine) {
419419
vm.stdlib_inits
420420
.borrow_mut()
421-
.insert("browser".to_string(), Box::new(make_module));
421+
.insert("_browser".to_string(), Box::new(make_module));
422+
vm.frozen.borrow_mut().insert(
423+
"browser".to_string(),
424+
py_compile_bytecode!(file = "src/browser.py"),
425+
);
422426
}

0 commit comments

Comments
 (0)