forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.py
More file actions
76 lines (56 loc) · 1.42 KB
/
browser.py
File metadata and controls
76 lines (56 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from _browser import (
fetch,
request_animation_frame,
cancel_animation_frame,
Document,
Element,
load_module,
)
from _js import JSValue, Promise
from _window import window
__all__ = [
"jsstr",
"jsclosure",
"jsclosure_once",
"jsfloat",
"NULL",
"UNDEFINED",
"alert",
"confirm",
"prompt",
"fetch",
"request_animation_frame",
"cancel_animation_frame",
"Document",
"Element",
"load_module",
"JSValue",
"Promise",
]
jsstr = window.new_from_str
jsclosure = window.new_closure
jsclosure_once = window.new_closure_once
_jsfloat = window.new_from_float
UNDEFINED = window.undefined()
NULL = window.null()
def jsfloat(n):
return _jsfloat(float(n))
_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(msg), jsstr(default_val) if default_val else UNDEFINED
).as_str()