echidnae-javascript 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- echidnae_javascript-0.3.0/CHANGELOG.md +18 -0
- echidnae_javascript-0.3.0/LICENSE.md +21 -0
- echidnae_javascript-0.3.0/PKG-INFO +144 -0
- echidnae_javascript-0.3.0/README.md +127 -0
- echidnae_javascript-0.3.0/RELEASING.md +3 -0
- echidnae_javascript-0.3.0/docs/compatibility.md +119 -0
- echidnae_javascript-0.3.0/docs/compiler-async.md +101 -0
- echidnae_javascript-0.3.0/docs/compiler-browser.md +145 -0
- echidnae_javascript-0.3.0/docs/compiler-conformance.md +64 -0
- echidnae_javascript-0.3.0/docs/compiler-emitter.md +99 -0
- echidnae_javascript-0.3.0/docs/compiler-front-end.md +31 -0
- echidnae_javascript-0.3.0/docs/compiler-language.md +110 -0
- echidnae_javascript-0.3.0/docs/compiler-measurements.md +137 -0
- echidnae_javascript-0.3.0/docs/compiler-modules.md +91 -0
- echidnae_javascript-0.3.0/docs/measurements/2026-10-20-compiler.json +5339 -0
- echidnae_javascript-0.3.0/docs/release-0.2.0.md +48 -0
- echidnae_javascript-0.3.0/examples/browser_text_metrics.py +103 -0
- echidnae_javascript-0.3.0/pyproject.toml +53 -0
- echidnae_javascript-0.3.0/pyproject.toml.orig +44 -0
- echidnae_javascript-0.3.0/scripts/check_distribution_files.py +53 -0
- echidnae_javascript-0.3.0/scripts/compiler_browser_smoke.py +271 -0
- echidnae_javascript-0.3.0/scripts/compiler_conformance.mjs +32 -0
- echidnae_javascript-0.3.0/scripts/compiler_conformance.py +268 -0
- echidnae_javascript-0.3.0/scripts/install_distribution.py +32 -0
- echidnae_javascript-0.3.0/scripts/measure_compiler.mjs +27 -0
- echidnae_javascript-0.3.0/scripts/measure_compiler.py +391 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/__init__.py +27 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_array.py +338 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_browser/browser-host.mjs +165 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_browser/browser-protocol.mjs +111 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_browser/browser-worker.mjs +117 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_compiler_runtime.py +466 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_json.py +114 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_math.py +109 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_number.py +92 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_object.py +184 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_string.py +170 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/_values.py +195 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/browser.py +60 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/compiler.py +473 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/emitter.py +300 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/modules.py +273 -0
- echidnae_javascript-0.3.0/src/echidnae/javascript/py.typed +0 -0
- echidnae_javascript-0.3.0/tests/fixtures/browser_protocol.mjs +38 -0
- echidnae_javascript-0.3.0/tests/fixtures/compiler_contract.json +91 -0
- echidnae_javascript-0.3.0/tests/fixtures/compiler_parity.json +166 -0
- echidnae_javascript-0.3.0/tests/fixtures/conformance.mjs +100 -0
- echidnae_javascript-0.3.0/tests/fixtures/licenses/SHIMIFY-LICENSE.txt +21 -0
- echidnae_javascript-0.3.0/tests/test_array.py +159 -0
- echidnae_javascript-0.3.0/tests/test_compiler_async.py +152 -0
- echidnae_javascript-0.3.0/tests/test_compiler_browser.py +91 -0
- echidnae_javascript-0.3.0/tests/test_compiler_conformance.py +29 -0
- echidnae_javascript-0.3.0/tests/test_compiler_contract.py +29 -0
- echidnae_javascript-0.3.0/tests/test_compiler_emitter.py +166 -0
- echidnae_javascript-0.3.0/tests/test_compiler_errors.py +77 -0
- echidnae_javascript-0.3.0/tests/test_compiler_frontend.py +103 -0
- echidnae_javascript-0.3.0/tests/test_compiler_measurements.py +72 -0
- echidnae_javascript-0.3.0/tests/test_compiler_modules.py +162 -0
- echidnae_javascript-0.3.0/tests/test_conformance.py +124 -0
- echidnae_javascript-0.3.0/tests/test_integration.py +26 -0
- echidnae_javascript-0.3.0/tests/test_json.py +62 -0
- echidnae_javascript-0.3.0/tests/test_object.py +91 -0
- echidnae_javascript-0.3.0/tests/test_primitives.py +132 -0
- echidnae_javascript-0.3.0/tests/test_values.py +67 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Add the binding-aware source compiler, deterministic ES module emitter and original-source diagnostics/maps.
|
|
6
|
+
- Compile explicitly supplied local modules and re-exports with selected helper and notice closure.
|
|
7
|
+
- Add lazy coroutine/Promise awaits and named browser worker/host capabilities with stop/restart.
|
|
8
|
+
- Verify the approved corpus across CPython, Node and Chromium and record scoped payload/startup/memory measurements.
|
|
9
|
+
- Preserve the echidnae.javascript runtime namespace and existing Fetch/JSON dependency ranges.
|
|
10
|
+
|
|
11
|
+
## 0.1.0
|
|
12
|
+
|
|
13
|
+
- Introduce the case-sensitive `echidnae.javascript` namespace with Object, sparse Array,
|
|
14
|
+
UTF-16 String methods, Number, Boolean, selected Math functions and JSON.
|
|
15
|
+
- Add undefined, truthiness, conversion, equality and parsing helpers.
|
|
16
|
+
- Depend on standalone echidnae-fetch 0.2 and echidnae-json 0.1; expose
|
|
17
|
+
Fetch and Promise without duplicating their implementations.
|
|
18
|
+
- Document the supported compatibility subset and future translation direction.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wispsy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: echidnae-javascript
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: JavaScript-style Python values and a bounded Python-to-JavaScript compiler
|
|
5
|
+
Author: ellainng
|
|
6
|
+
Author-email: ellainng <299958882+ellainng@users.noreply.github.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE.md
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Requires-Dist: echidnae-fetch>=0.2.1,<0.3.0
|
|
12
|
+
Requires-Dist: echidnae-json>=0.1.1,<0.2.0
|
|
13
|
+
Requires-Python: >=3.14
|
|
14
|
+
Project-URL: Repository, https://github.com/wispsy/echidnae
|
|
15
|
+
Project-URL: Issues, https://github.com/wispsy/echidnae/issues
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# echidnae-javascript
|
|
19
|
+
|
|
20
|
+
JavaScript-style objects, methods and functions for Python 3.14+, using the
|
|
21
|
+
shared `echidnae.javascript` namespace. An alpha compatibility layer with a
|
|
22
|
+
documented subset of ECMAScript behavior.
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
python -m pip install echidnae-javascript==0.3.0
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from echidnae.javascript import Array, JSON, Math, Object, String, undefined
|
|
30
|
+
|
|
31
|
+
people = JSON.parse('[{"name":"Ada","score":8},{"name":"Lin","score":6}]')
|
|
32
|
+
names = people.filter(lambda person: person.score >= 7).map(
|
|
33
|
+
lambda person: person.name.toUpperCase()
|
|
34
|
+
)
|
|
35
|
+
assert names.join(", ") == "ADA"
|
|
36
|
+
|
|
37
|
+
profile = Object({"name": String("Ada"), "scores": Array.of(8, 6)})
|
|
38
|
+
assert profile.missing is undefined
|
|
39
|
+
assert profile.scores.reduce(lambda total, score: total + score, 0) == 14
|
|
40
|
+
assert Math.round(2.5) == 3
|
|
41
|
+
assert JSON.stringify(profile) == '{"name":"Ada","scores":[8,6]}'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Explicit `Object`, `Array`, `String` and `Number` values expose JavaScript names
|
|
45
|
+
and behavior. Ordinary Python literals and operators retain Python semantics.
|
|
46
|
+
Objects and arrays compare by identity and remain truthy when empty. Use
|
|
47
|
+
`Boolean(value)` or `truthy(value)` when testing JavaScript truthiness of values
|
|
48
|
+
that might include Python containers.
|
|
49
|
+
|
|
50
|
+
## Standalone packages
|
|
51
|
+
|
|
52
|
+
Installation includes two independently useful dependencies:
|
|
53
|
+
|
|
54
|
+
| Distribution | Import | Purpose |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| `echidnae-fetch>=0.2.1,<0.3.0` | `echidnae.fetch` | Standard-library HTTP Fetch and Promise APIs |
|
|
57
|
+
| `echidnae-json>=0.1.1,<0.2.0` | `JSON` | Python-friendly JSON parsing, serialization and dot traversal |
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import asyncio
|
|
61
|
+
from echidnae.fetch import fetch
|
|
62
|
+
from echidnae.javascript import echidnae.json as JSON
|
|
63
|
+
|
|
64
|
+
async def main():
|
|
65
|
+
response = await fetch("https://example.com/api/people")
|
|
66
|
+
if not response.ok:
|
|
67
|
+
raise RuntimeError(f"HTTP {response.status}")
|
|
68
|
+
people = JSON.parse(await response.text())
|
|
69
|
+
return people
|
|
70
|
+
|
|
71
|
+
# Run against your own JSON endpoint:
|
|
72
|
+
# people = asyncio.run(main())
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`echidnae.javascript.fetch`, `Promise`, `Headers`, `Request`, `Response` and `FetchError`
|
|
76
|
+
are the same objects exported by `echidnae.fetch`. Fetch 0.2.0 changes the old
|
|
77
|
+
`from javascript import fetch` spelling to `from echidnae.fetch import fetch`.
|
|
78
|
+
|
|
79
|
+
`response.json()` retains Fetch's standalone `JSONObject`/list result. Use
|
|
80
|
+
`echidnae.javascript.JSON.parse(await response.text())` for runtime Object/Array/String
|
|
81
|
+
values. Standalone `import echidnae.json as JSON` preserves Python integers and containers;
|
|
82
|
+
`from echidnae.javascript import echidnae.json as JSON` uses binary64 numbers and JavaScript serialization
|
|
83
|
+
rules for its supported subset.
|
|
84
|
+
|
|
85
|
+
## Supported surface
|
|
86
|
+
|
|
87
|
+
Core data objects and sparse arrays; UTF-16 String methods; Number predicates and
|
|
88
|
+
prefix parsers; Boolean conversion; selected Math functions; JSON; and the
|
|
89
|
+
standalone Fetch/Promise APIs. See the complete
|
|
90
|
+
[compatibility matrix](docs/compatibility.md) for method lists and limits.
|
|
91
|
+
|
|
92
|
+
Python keywords require `Array.from_`, `Object.is_`, and `Promise.finally_`.
|
|
93
|
+
`None` represents `null`; `undefined` is a separate singleton. Array bracket
|
|
94
|
+
indices follow JavaScript rules: `values[-1]` is a named property, and
|
|
95
|
+
`values.at(-1)` accesses the last element. `Array(3)` creates three holes;
|
|
96
|
+
`Array.of(3)` creates one element containing 3.
|
|
97
|
+
|
|
98
|
+
Version 0.3.0 retains a bounded Python-to-JavaScript compiler: a
|
|
99
|
+
[binding-aware front end](docs/compiler-front-end.md), [ES module emitter](docs/compiler-emitter.md),
|
|
100
|
+
[local-module compiler](docs/compiler-modules.md), [async profile](docs/compiler-async.md)
|
|
101
|
+
and [browser worker/host target](docs/compiler-browser.md). Python parses source
|
|
102
|
+
at build time; generated modules and selected helpers execute on the client.
|
|
103
|
+
The separate pocket-python interpreter will parse newly entered Python in the browser.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from echidnae.javascript.emitter import compile_source
|
|
107
|
+
|
|
108
|
+
artifact = compile_source("def count(text):\n return len(text)", filename="counter.py")
|
|
109
|
+
# artifact.files contains emitted echidnae.javascript, source map and provenance notice.
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
This alpha supports the explicit [compiler language](docs/compiler-language.md),
|
|
113
|
+
not arbitrary Python dependencies or complete ECMAScript. Prototypes, descriptors,
|
|
114
|
+
Date, RegExp, Map/Set, typed arrays and unlisted APIs remain future work. See
|
|
115
|
+
[0.2.0 release notes](docs/release-0.2.0.md), the [implementation plan](IMPLEMENTATION_PLAN.md),
|
|
116
|
+
[issues](https://github.com/wispsy/echidnae/issues) and
|
|
117
|
+
[Project](https://github.com/orgs/wispsy/projects/11).
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
uv sync
|
|
123
|
+
uv run python -m unittest discover -s tests -v
|
|
124
|
+
uv build
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Node.js 24 runs the native ECMAScript differential fixture. That test is skipped
|
|
128
|
+
when Node is absent locally; CI and release builds require it. Runtime code
|
|
129
|
+
needs only Python and the two declared companions. Tests make no external
|
|
130
|
+
network requests.
|
|
131
|
+
|
|
132
|
+
The [compiler emitter](docs/compiler-emitter.md) produces deterministic
|
|
133
|
+
ES modules for the approved single-module Python profile. The compiler APIs are included in the 0.3.0 distribution.
|
|
134
|
+
|
|
135
|
+
The explicit [async compiler profile](docs/compiler-async.md) adds lazy coroutines,
|
|
136
|
+
awaited Promise values, callbacks and context cancellation. The [browser target](docs/compiler-browser.md) adds named DOM controls, callbacks,
|
|
137
|
+
native Fetch text and worker stop/restart.
|
|
138
|
+
|
|
139
|
+
Build the local [text_metrics browser example](docs/compiler-browser.md#run-the-example)
|
|
140
|
+
with `uv run python examples/browser_text_metrics.py --output build/browser-text-metrics`.
|
|
141
|
+
It uses our emitted modules and helpers in a worker; source parsing remains the
|
|
142
|
+
separate independent-interpreter milestone.
|
|
143
|
+
|
|
144
|
+
The compiler has a versioned [CPython/Node/browser parity suite](docs/compiler-conformance.md) with typed results, source-map error checks and explicit unsupported boundaries.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# echidnae-javascript
|
|
2
|
+
|
|
3
|
+
JavaScript-style objects, methods and functions for Python 3.14+, using the
|
|
4
|
+
shared `echidnae.javascript` namespace. An alpha compatibility layer with a
|
|
5
|
+
documented subset of ECMAScript behavior.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
python -m pip install echidnae-javascript==0.3.0
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from echidnae.javascript import Array, JSON, Math, Object, String, undefined
|
|
13
|
+
|
|
14
|
+
people = JSON.parse('[{"name":"Ada","score":8},{"name":"Lin","score":6}]')
|
|
15
|
+
names = people.filter(lambda person: person.score >= 7).map(
|
|
16
|
+
lambda person: person.name.toUpperCase()
|
|
17
|
+
)
|
|
18
|
+
assert names.join(", ") == "ADA"
|
|
19
|
+
|
|
20
|
+
profile = Object({"name": String("Ada"), "scores": Array.of(8, 6)})
|
|
21
|
+
assert profile.missing is undefined
|
|
22
|
+
assert profile.scores.reduce(lambda total, score: total + score, 0) == 14
|
|
23
|
+
assert Math.round(2.5) == 3
|
|
24
|
+
assert JSON.stringify(profile) == '{"name":"Ada","scores":[8,6]}'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Explicit `Object`, `Array`, `String` and `Number` values expose JavaScript names
|
|
28
|
+
and behavior. Ordinary Python literals and operators retain Python semantics.
|
|
29
|
+
Objects and arrays compare by identity and remain truthy when empty. Use
|
|
30
|
+
`Boolean(value)` or `truthy(value)` when testing JavaScript truthiness of values
|
|
31
|
+
that might include Python containers.
|
|
32
|
+
|
|
33
|
+
## Standalone packages
|
|
34
|
+
|
|
35
|
+
Installation includes two independently useful dependencies:
|
|
36
|
+
|
|
37
|
+
| Distribution | Import | Purpose |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| `echidnae-fetch>=0.2.1,<0.3.0` | `echidnae.fetch` | Standard-library HTTP Fetch and Promise APIs |
|
|
40
|
+
| `echidnae-json>=0.1.1,<0.2.0` | `JSON` | Python-friendly JSON parsing, serialization and dot traversal |
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import asyncio
|
|
44
|
+
from echidnae.fetch import fetch
|
|
45
|
+
from echidnae.javascript import echidnae.json as JSON
|
|
46
|
+
|
|
47
|
+
async def main():
|
|
48
|
+
response = await fetch("https://example.com/api/people")
|
|
49
|
+
if not response.ok:
|
|
50
|
+
raise RuntimeError(f"HTTP {response.status}")
|
|
51
|
+
people = JSON.parse(await response.text())
|
|
52
|
+
return people
|
|
53
|
+
|
|
54
|
+
# Run against your own JSON endpoint:
|
|
55
|
+
# people = asyncio.run(main())
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`echidnae.javascript.fetch`, `Promise`, `Headers`, `Request`, `Response` and `FetchError`
|
|
59
|
+
are the same objects exported by `echidnae.fetch`. Fetch 0.2.0 changes the old
|
|
60
|
+
`from javascript import fetch` spelling to `from echidnae.fetch import fetch`.
|
|
61
|
+
|
|
62
|
+
`response.json()` retains Fetch's standalone `JSONObject`/list result. Use
|
|
63
|
+
`echidnae.javascript.JSON.parse(await response.text())` for runtime Object/Array/String
|
|
64
|
+
values. Standalone `import echidnae.json as JSON` preserves Python integers and containers;
|
|
65
|
+
`from echidnae.javascript import echidnae.json as JSON` uses binary64 numbers and JavaScript serialization
|
|
66
|
+
rules for its supported subset.
|
|
67
|
+
|
|
68
|
+
## Supported surface
|
|
69
|
+
|
|
70
|
+
Core data objects and sparse arrays; UTF-16 String methods; Number predicates and
|
|
71
|
+
prefix parsers; Boolean conversion; selected Math functions; JSON; and the
|
|
72
|
+
standalone Fetch/Promise APIs. See the complete
|
|
73
|
+
[compatibility matrix](docs/compatibility.md) for method lists and limits.
|
|
74
|
+
|
|
75
|
+
Python keywords require `Array.from_`, `Object.is_`, and `Promise.finally_`.
|
|
76
|
+
`None` represents `null`; `undefined` is a separate singleton. Array bracket
|
|
77
|
+
indices follow JavaScript rules: `values[-1]` is a named property, and
|
|
78
|
+
`values.at(-1)` accesses the last element. `Array(3)` creates three holes;
|
|
79
|
+
`Array.of(3)` creates one element containing 3.
|
|
80
|
+
|
|
81
|
+
Version 0.3.0 retains a bounded Python-to-JavaScript compiler: a
|
|
82
|
+
[binding-aware front end](docs/compiler-front-end.md), [ES module emitter](docs/compiler-emitter.md),
|
|
83
|
+
[local-module compiler](docs/compiler-modules.md), [async profile](docs/compiler-async.md)
|
|
84
|
+
and [browser worker/host target](docs/compiler-browser.md). Python parses source
|
|
85
|
+
at build time; generated modules and selected helpers execute on the client.
|
|
86
|
+
The separate pocket-python interpreter will parse newly entered Python in the browser.
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from echidnae.javascript.emitter import compile_source
|
|
90
|
+
|
|
91
|
+
artifact = compile_source("def count(text):\n return len(text)", filename="counter.py")
|
|
92
|
+
# artifact.files contains emitted echidnae.javascript, source map and provenance notice.
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
This alpha supports the explicit [compiler language](docs/compiler-language.md),
|
|
96
|
+
not arbitrary Python dependencies or complete ECMAScript. Prototypes, descriptors,
|
|
97
|
+
Date, RegExp, Map/Set, typed arrays and unlisted APIs remain future work. See
|
|
98
|
+
[0.2.0 release notes](docs/release-0.2.0.md), the [implementation plan](IMPLEMENTATION_PLAN.md),
|
|
99
|
+
[issues](https://github.com/wispsy/echidnae/issues) and
|
|
100
|
+
[Project](https://github.com/orgs/wispsy/projects/11).
|
|
101
|
+
|
|
102
|
+
## Development
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
uv sync
|
|
106
|
+
uv run python -m unittest discover -s tests -v
|
|
107
|
+
uv build
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Node.js 24 runs the native ECMAScript differential fixture. That test is skipped
|
|
111
|
+
when Node is absent locally; CI and release builds require it. Runtime code
|
|
112
|
+
needs only Python and the two declared companions. Tests make no external
|
|
113
|
+
network requests.
|
|
114
|
+
|
|
115
|
+
The [compiler emitter](docs/compiler-emitter.md) produces deterministic
|
|
116
|
+
ES modules for the approved single-module Python profile. The compiler APIs are included in the 0.3.0 distribution.
|
|
117
|
+
|
|
118
|
+
The explicit [async compiler profile](docs/compiler-async.md) adds lazy coroutines,
|
|
119
|
+
awaited Promise values, callbacks and context cancellation. The [browser target](docs/compiler-browser.md) adds named DOM controls, callbacks,
|
|
120
|
+
native Fetch text and worker stop/restart.
|
|
121
|
+
|
|
122
|
+
Build the local [text_metrics browser example](docs/compiler-browser.md#run-the-example)
|
|
123
|
+
with `uv run python examples/browser_text_metrics.py --output build/browser-text-metrics`.
|
|
124
|
+
It uses our emitted modules and helpers in a worker; source parsing remains the
|
|
125
|
+
separate independent-interpreter milestone.
|
|
126
|
+
|
|
127
|
+
The compiler has a versioned [CPython/Node/browser parity suite](docs/compiler-conformance.md) with typed results, source-map error checks and explicit unsupported boundaries.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# v0.1.0 compatibility
|
|
2
|
+
|
|
3
|
+
This is a selected ECMAScript-compatible runtime API implemented in Python.
|
|
4
|
+
Method names and the tested behaviors below follow the
|
|
5
|
+
[ECMAScript specification](https://tc39.es/ecma262/). It is not a complete language
|
|
6
|
+
implementation. The native Node.js fixture checks the adopted subset, rather
|
|
7
|
+
than asserting general Test262 conformance.
|
|
8
|
+
|
|
9
|
+
## Supported API
|
|
10
|
+
|
|
11
|
+
| Surface | Implemented members |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| Values | `undefined`, `null`, `NaN`, `Infinity`, `typeof`, `truthy`, `strictEqual`, global `isNaN`, global `isFinite` |
|
|
14
|
+
| `Object` | Mapping/empty construction, dot/bracket data properties, deletion, missing `undefined`, `keys`, `values`, `entries`, `assign`, `fromEntries`, `hasOwn`, `is_`, `toString` |
|
|
15
|
+
| `Array` | Numeric-length/element construction, `of`, iterable `from_`, `isArray`, `length`, bracket access/deletion, `at`, `push`, `pop`, `shift`, `unshift`, `slice`, `splice`, `concat`, `join`, `toString`, `includes`, `indexOf`, `lastIndexOf` |
|
|
16
|
+
| Array callbacks | `map`, `filter`, `forEach`, `some`, `every`, `find`, `findIndex`, `findLast`, `findLastIndex`, `reduce`, `reduceRight` |
|
|
17
|
+
| Array mutation/iteration | `reverse`, `fill`, `sort`, `keys`, `values`, `entries`, Python iteration |
|
|
18
|
+
| `String` | Conversion, `length`, bracket code units, `at`, `charAt`, `charCodeAt`, `codePointAt`, `slice`, `substring`, `indexOf`, `lastIndexOf`, `includes`, `startsWith`, `endsWith`, `split`, `concat`, `repeat`, `trim`, `trimStart`, `trimEnd`, `toLowerCase`, `toUpperCase`, `toString`, `valueOf`, `fromCharCode`, `fromCodePoint` |
|
|
19
|
+
| `Number` | Conversion, `isNaN`, `isFinite`, `isInteger`, `isSafeInteger`, `parseInt`, `parseFloat`, decimal `toString`, `valueOf`, `EPSILON`, `MAX_SAFE_INTEGER`, `MIN_SAFE_INTEGER`, `MAX_VALUE`, `MIN_VALUE`, `NaN`, `POSITIVE_INFINITY`, `NEGATIVE_INFINITY` |
|
|
20
|
+
| `Boolean` | Primitive conversion returning a Python bool |
|
|
21
|
+
| `Math` | `abs`, `floor`, `ceil`, `trunc`, `round`, `sign`, `min`, `max`, `sqrt`, `pow`, `random`; `PI`, `E`, `LN2`, `LN10`, `LOG2E`, `LOG10E`, `SQRT1_2`, `SQRT2` |
|
|
22
|
+
| `JSON` | `parse(text)`, `stringify(value, replacer=undefined, space=undefined)`, `JSONDecodeError` |
|
|
23
|
+
| Global parsing | `parseInt`, `parseFloat` |
|
|
24
|
+
| Companions | `fetch`, `FetchError`, `Headers`, `Request`, `Response`, `Promise`, re-exported unchanged from `echidnae.fetch` |
|
|
25
|
+
|
|
26
|
+
## Data model and Python boundaries
|
|
27
|
+
|
|
28
|
+
- `Object` stores own enumerable writable data properties. Keys convert to
|
|
29
|
+
strings. Array-index keys enumerate numerically before other keys in insertion
|
|
30
|
+
order. Deleting and re-adding a non-index key moves it to the end.
|
|
31
|
+
- `Object()`/`Object(None)` create empty objects; `Object(existing)` returns the
|
|
32
|
+
existing Object. Other construction accepts a Python mapping. Primitive
|
|
33
|
+
boxing and prototype/descriptor operations are unsupported.
|
|
34
|
+
- Object-to-primitive conversion uses the built-in data-object representation.
|
|
35
|
+
Custom `valueOf`/`toString` conversion hooks and Symbol.toPrimitive are not
|
|
36
|
+
implemented.
|
|
37
|
+
- Objects preserve supplied child values; passing a nested Python dict/list
|
|
38
|
+
does not recursively convert it. JSON parsing creates runtime containers.
|
|
39
|
+
- Own Object keys shadow ordinary Python attributes. Use `Object.keys(obj)`
|
|
40
|
+
for static methods and brackets for special names such as `__class__`.
|
|
41
|
+
Missing ordinary attributes return `undefined`; Python `hasattr` therefore
|
|
42
|
+
cannot test property presence. Use `Object.hasOwn` or `key in obj`.
|
|
43
|
+
- Arrays store holes separately from explicit undefined values. Length changes
|
|
44
|
+
truncate or expand sparsely. Callback methods skip holes where ECMAScript does;
|
|
45
|
+
find methods and includes observe holes as undefined. `Object.hasOwn(array, i)`
|
|
46
|
+
distinguishes them. `length` is an own, non-enumerable property.
|
|
47
|
+
- Use bracket notation for named Array properties; arbitrary dot property
|
|
48
|
+
assignment and overriding Array methods are outside this subset. Python `in`
|
|
49
|
+
tests property presence, matching JavaScript `in`; use `includes` for values.
|
|
50
|
+
- `Array.from_` accepts Python iterables, including runtime arrays and strings.
|
|
51
|
+
JavaScript array-like objects, custom iterators/Symbol protocols, `thisArg`,
|
|
52
|
+
subclass species and `Symbol.isConcatSpreadable` are not implemented. `concat`
|
|
53
|
+
spreads runtime Array values; ordinary Python lists remain single elements.
|
|
54
|
+
- Callbacks receive JavaScript's arguments, truncated to their inspectable Python
|
|
55
|
+
positional arity. Zero-argument and variadic callbacks work. Uninspectable
|
|
56
|
+
callables receive all arguments; wrap them in a lambda if needed. Keyword-only
|
|
57
|
+
callback parameters and JavaScript `this` binding are unsupported. Exceptions
|
|
58
|
+
propagate once without retrying the callback.
|
|
59
|
+
- `sort` is stable and uses UTF-16 lexicographic order by default. Undefined
|
|
60
|
+
elements follow defined elements; holes follow undefined. Comparators may
|
|
61
|
+
return a number; mutating the sorted array from its comparator is unsupported.
|
|
62
|
+
- String methods and brackets index UTF-16 code units. String iteration visits
|
|
63
|
+
code points. Python `len(string)` and inherited str methods/operators retain
|
|
64
|
+
Python semantics; use `.length` for JavaScript length. Case conversion uses
|
|
65
|
+
Python's Unicode tables, which can differ from a JavaScript engine's version.
|
|
66
|
+
- `Number` is a float subclass with binary64 conversion. Plain Python integers,
|
|
67
|
+
arithmetic, division, modulo, comparisons, `and`/`or`, `==`, container literals
|
|
68
|
+
and inherited methods retain Python behavior. Use explicit helpers for
|
|
69
|
+
JavaScript semantics. No operator rewriting or automatic primitive boxing is
|
|
70
|
+
provided. `Boolean` does not create boxed Boolean objects.
|
|
71
|
+
- Methods can return native Python primitives, including Array `join` and Math
|
|
72
|
+
results. Wrap such results with `String` or `Number` to call their JavaScript
|
|
73
|
+
methods; Python does not automatically box primitive values.
|
|
74
|
+
- Decimal number strings use Python's shortest float representation adjusted to
|
|
75
|
+
JavaScript exponent/fixed-format thresholds. Tested ordinary values agree;
|
|
76
|
+
rare shortest-decimal tie choices may differ between Python and ECMAScript.
|
|
77
|
+
Other number radices and `toFixed`/`toPrecision` are not implemented.
|
|
78
|
+
- Errors use Python `TypeError`, `ValueError` and `JSONDecodeError`; no full
|
|
79
|
+
ECMAScript Error hierarchy or matching message text is promised. Invalid array
|
|
80
|
+
lengths, repeat counts and code points raise ValueError. Invalid JSON numeric
|
|
81
|
+
constants raise ValueError. Unsupported overloads raise TypeError or
|
|
82
|
+
NotImplementedError.
|
|
83
|
+
|
|
84
|
+
## JSON boundaries
|
|
85
|
+
|
|
86
|
+
`echidnae.javascript.JSON.parse` creates Object, Array and String values, and binary64
|
|
87
|
+
Python floats for numbers. Negative zero and integer rounding follow the number
|
|
88
|
+
model. It uses the standard-library decoder's numeric hooks because standalone
|
|
89
|
+
`JSON.parse` intentionally preserves Python integers. The companion's serializer
|
|
90
|
+
provides string escaping; its public decoder exception type is shared.
|
|
91
|
+
|
|
92
|
+
`stringify` emits compact JSON by default, orders object keys, writes non-finite
|
|
93
|
+
numbers as null, omits undefined/callable object properties, and writes them as
|
|
94
|
+
null in arrays. Top-level undefined/callables return undefined. Shared references
|
|
95
|
+
are allowed; cycles raise TypeError. A numeric/string `space` is capped at ten
|
|
96
|
+
characters. Lone surrogates are escaped. Plain Python mappings/lists/tuples are
|
|
97
|
+
accepted as a convenience.
|
|
98
|
+
|
|
99
|
+
Revivers, replacer functions/property lists, `toJSON` hooks, symbols and BigInt
|
|
100
|
+
are unsupported. A non-null replacer or callable own toJSON hook raises
|
|
101
|
+
NotImplementedError. Byte input is a standalone JSON extension and is rejected
|
|
102
|
+
by the runtime facade. The facade does not change standalone `import echidnae.json as JSON` or
|
|
103
|
+
Fetch's `response.json()` result types.
|
|
104
|
+
|
|
105
|
+
## Fetch and Promise boundaries
|
|
106
|
+
|
|
107
|
+
The [standalone Fetch documentation](https://github.com/wispsy/echidnae/tree/main/packages/python/echidnae-fetch)
|
|
108
|
+
is the complete contract. Core HTTP(S) requests, buffered bodies, headers,
|
|
109
|
+
redirects, promises and await work. Browser policies, streaming, abort, cookies
|
|
110
|
+
and browser globals are not provided. Promise callbacks use a background Python
|
|
111
|
+
thread, not JavaScript microtask scheduling. Rejections use Python exceptions;
|
|
112
|
+
handlers return values or Promise objects, rather than raw Python coroutines.
|
|
113
|
+
|
|
114
|
+
## Future translation
|
|
115
|
+
|
|
116
|
+
The runtime deliberately keeps recognizable call shapes, but a Python program
|
|
117
|
+
using it is not automatically safe to translate. The future translator must
|
|
118
|
+
resolve bindings and validate an approved Python AST subset. It must diagnose
|
|
119
|
+
unsupported operators and Python-only constructs before emitting JavaScript.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Compiled async profile
|
|
2
|
+
|
|
3
|
+
The 0.2.0 APIs `parse_source`, `compile_source` and `compile_modules`
|
|
4
|
+
accept `async_enabled=True`. Without it, async syntax remains rejected. Published
|
|
5
|
+
0.1.0 artifacts predate these compiler APIs. Single-module artifacts identify
|
|
6
|
+
`python-browser-async/1` and ABI `python-browser-async-esm/1`; local-module artifacts
|
|
7
|
+
identify `python-browser-modules-async/1` and ABI
|
|
8
|
+
`python-browser-modules-async-esm/1`. These are explicit extensions of the
|
|
9
|
+
[source language](compiler-language.md) and [module contract](compiler-modules.md).
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from echidnae.javascript import Promise
|
|
13
|
+
|
|
14
|
+
async def main():
|
|
15
|
+
value = await Promise.resolve(9007199254740993)
|
|
16
|
+
print(value + 1)
|
|
17
|
+
return value
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Compile this source with the async flag, import its generated `createModule`,
|
|
21
|
+
then use `await createModule().main()` in JavaScript. An exported async function
|
|
22
|
+
returns a native Promise, including for invalid arguments and cancellation.
|
|
23
|
+
Python integers, strings and tuples keep their adopted runtime representation;
|
|
24
|
+
no implicit Number conversion is added. Synchronous exports returning an adopted
|
|
25
|
+
Promise also expose a native Promise. Other synchronous exports remain synchronous.
|
|
26
|
+
|
|
27
|
+
## Coroutine and Promise behavior
|
|
28
|
+
|
|
29
|
+
Top-level plain `async def` functions support the existing positional parameters,
|
|
30
|
+
immutable defaults, ordinary control flow and return values. Calling one inside
|
|
31
|
+
compiled Python creates a lazy, single-use coroutine. Its body begins when
|
|
32
|
+
awaited. Arguments/defaults are bound when called. Awaiting the same coroutine
|
|
33
|
+
twice raises RuntimeError; a Promise can be awaited repeatedly. Await in defaults,
|
|
34
|
+
module initialization or a synchronous function is rejected. Async generators,
|
|
35
|
+
async iteration/context managers, asyncio task APIs, gather and top-level await
|
|
36
|
+
are deferred. Unawaited coroutines have no execution side effect; no finalizer
|
|
37
|
+
warning is promised.
|
|
38
|
+
|
|
39
|
+
The approved async JavaScript registry adds `Promise.resolve(value)`,
|
|
40
|
+
`Promise.reject(TypeError(message))` and `promise.then(on_fulfilled, on_rejected)`.
|
|
41
|
+
Registry imports/aliases resolve by binding identity. A handler is a supported
|
|
42
|
+
plain synchronous Python function or None; omitted/None handlers forward outcomes.
|
|
43
|
+
Each handler receives one argument and is called once. A returned adopted Promise
|
|
44
|
+
is chained; a raised adopted exception rejects the chain without retrying the
|
|
45
|
+
handler. Async callbacks and arbitrary thenables are rejected. Promise constructors,
|
|
46
|
+
catch/finally, all/race and general native Promise inputs remain deferred.
|
|
47
|
+
Coroutines must be awaited before passing them as arguments; async functions
|
|
48
|
+
cannot return an unawaited coroutine or Promise as their final value.
|
|
49
|
+
|
|
50
|
+
Source locations survive async rejection, imported calls and callbacks. Explicit
|
|
51
|
+
builtin TypeError and existing runtime errors retain their Python names and
|
|
52
|
+
messages. Unexpected host rejections become a bounded RuntimeError rather than
|
|
53
|
+
exposing host internals. Synchronous compiled calls retain depth 128; at most 128
|
|
54
|
+
async coroutine bodies may be active in one context. This bound also limits
|
|
55
|
+
concurrent active bodies and is not CPython's recursion limit.
|
|
56
|
+
|
|
57
|
+
## Scheduling and cancellation
|
|
58
|
+
|
|
59
|
+
An exported async invocation starts on a JavaScript microtask. Internal coroutine
|
|
60
|
+
creation remains lazy; native async lowering and Promise continuations preserve
|
|
61
|
+
source evaluation order, short circuiting, and callback single invocation.
|
|
62
|
+
Awaited boolean/chained-comparison expressions may add a continuation even on a
|
|
63
|
+
short-circuited path. Awaiting an already fulfilled Promise also crosses a
|
|
64
|
+
microtask checkpoint. CPython's companion Promise uses thread-backed callbacks
|
|
65
|
+
and its asyncio bridge may resume an already completed awaitable without the
|
|
66
|
+
same checkpoint. Timing relative to unrelated tasks or callbacks is therefore
|
|
67
|
+
not a cross-target guarantee. No implicit event loop or Python scheduler is
|
|
68
|
+
embedded in the generated artifact.
|
|
69
|
+
|
|
70
|
+
`createModule({write, signal})` accepts an optional AbortSignal for that context.
|
|
71
|
+
Generated statements, public calls, callbacks and await boundaries check it.
|
|
72
|
+
Cancellation rejects pending exported operations with name AbortError and code
|
|
73
|
+
CANCELLED at a recorded source location. Await listeners are removed on success,
|
|
74
|
+
failure and cancellation. Completed output/other side effects remain committed.
|
|
75
|
+
The signal applies to the whole application context; create a fresh context to
|
|
76
|
+
restart. Signal reasons are not copied into application errors.
|
|
77
|
+
|
|
78
|
+
AbortSignal delivery cannot interrupt busy synchronous execution on its own.
|
|
79
|
+
In a worker, the trusted main thread must retain worker termination as the stop
|
|
80
|
+
path. The [host protocol](https://github.com/wispsy/echidnae/blob/main/docs/browser-host-protocol.md)
|
|
81
|
+
uses session/request IDs, serialized tagged values, exactly one terminal result
|
|
82
|
+
and CANCELLED/TIMEOUT replies. The [browser profile](compiler-browser.md) wraps a pending
|
|
83
|
+
host result as an adopted Promise, forwards cancellation to its request, discards
|
|
84
|
+
stale replies and releases handles. Raw Promise/Event/DOM objects do not cross
|
|
85
|
+
that transport. HOST-01 defines the shared contract; the async-only profile does not itself provide that adapter.
|
|
86
|
+
|
|
87
|
+
## Fetch boundary
|
|
88
|
+
|
|
89
|
+
CPython code continues to use the published `echidnae.fetch.fetch` implementation
|
|
90
|
+
re-exported by `echidnae.javascript`, including its thread-backed Promise and HTTP types.
|
|
91
|
+
Those implementations are not copied into compiled artifacts. `fetch`, Request,
|
|
92
|
+
Response, streaming bodies and response JSON methods remain rejected by this
|
|
93
|
+
compiler profile. The [browser profile](compiler-browser.md) adds the separately granted `fetch/1` text operation,
|
|
94
|
+
lowering to browser-native Fetch through the trusted host with AbortSignal,
|
|
95
|
+
origin/CORS, URL, credential, redirect, size and deadline rules. Its first text
|
|
96
|
+
metrics UI requires no network access. Streaming, async iterables and standalone
|
|
97
|
+
Promise package extraction remain separate extensions.
|
|
98
|
+
|
|
99
|
+
Local fixtures compare awaited values, laziness, defaults, order and callback
|
|
100
|
+
errors with CPython and execute the generated modules in Node. Abort and listener
|
|
101
|
+
cleanup tests use a local AbortController; no external network is needed.
|