Files
RustPython/wasm/lib/src/browser.py
2019-06-21 20:20:21 -05:00

38 lines
791 B
Python

from _browser import *
from _js import JsValue
from _window import window
jsstr = window.new_from_str
_alert = window.get_prop("alert")
def alert(msg):
if type(msg) != str:
raise TypeError("msg must be a string")
_alert.call(jsstr(msg))
_confirm = window.get_prop("confirm")
def confirm(msg):
if type(msg) != str:
raise TypeError("msg must be a string")
return _confirm.call(jsstr(msg)).as_bool()
_prompt = window.get_prop("prompt")
def prompt(msg, default_val=None):
if type(msg) != str:
raise TypeError("msg must be a string")
if default_val is not None and type(default_val) != str:
raise TypeError("default_val must be a string")
return _prompt.call(*(jsstr(arg) for arg in [msg, default_val] if arg)).as_str()