Skip to content

Commit 3b06c0e

Browse files
committed
feat(typing): add typings for the helper functions
1 parent f1f3241 commit 3b06c0e

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

python/pythonmonkey/pythonmonkey.pyi

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ def eval(code: str, evalOpts: EvalOptions = {}, /) -> _typing.Any:
2626
"""
2727

2828

29+
def require(moduleIdentifier: str, /) -> JSObjectProxy:
30+
"""
31+
Return the exports of a CommonJS module identified by `moduleIdentifier`, using standard CommonJS semantics
32+
"""
33+
34+
35+
def new(ctor: JSFunctionProxy) -> _typing.Callable[..., _typing.Any]:
36+
"""
37+
Wrap the JS new operator, emitting a lambda which constructs a new
38+
JS object upon invocation
39+
"""
40+
41+
42+
def typeof(jsval: _typing.Any, /):
43+
"""
44+
This is the JS `typeof` operator, wrapped in a function so that it can be used easily from Python.
45+
"""
46+
47+
2948
def wait() -> _typing.Awaitable[None]:
3049
"""
3150
Block until all asynchronous jobs (Promise/setTimeout/etc.) finish.
@@ -44,6 +63,12 @@ def stop() -> None:
4463
"""
4564

4665

66+
def runProgramModule(filename: str, argv: _typing.List[str], extraPaths: _typing.List[str] = []) -> None:
67+
"""
68+
Load and evaluate a program (main) module. Program modules must be written in JavaScript.
69+
"""
70+
71+
4772
def isCompilableUnit(code: str) -> bool:
4873
"""
4974
Hint if a string might be compilable Javascript without actual evaluation
@@ -117,6 +142,12 @@ class SpiderMonkeyError(Exception):
117142

118143

119144
null = _typing.Annotated[
120-
_typing.NewType("pythonmonkey.null", object),
121-
"Representing the JS null type in Python using a singleton object",
145+
_typing.NewType("pythonmonkey.null", object),
146+
"Representing the JS null type in Python using a singleton object",
147+
]
148+
149+
150+
globalThis = _typing.Annotated[
151+
JSObjectProxy,
152+
"A Python Dict which is equivalent to the globalThis object in JavaScript",
122153
]

0 commit comments

Comments
 (0)