Skip to content

Coincident rewrite - A single roundtrip version (unbuffered) #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.js.map

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions docs/toml-CkEFU7ly.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/toml-CkEFU7ly.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/zip-DPXsOtR5.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions docs/zip-DXp-b1fY.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/zip-DXp-b1fY.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/zip-DxlTOqbw.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/zip-DxlTOqbw.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion esm/interpreter/_python.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as JSON from '@ungap/structured-clone/json';
import * as FLATTED from '@webreflection/coincident/flatted';
const JSON = { parse: FLATTED.decode, stringify: FLATTED.encode };

import { fetchFiles, fetchJSModules, fetchPaths } from './_utils.js';
import { IDBMapSync, dedent } from '../utils.js';
import { io } from './_io.js';
Expand Down
2 changes: 1 addition & 1 deletion esm/interpreter/pyodide.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const indexURLs = new WeakMap();

export default {
type,
module: (version = '0.27.4') =>
module: (version = '0.27.5') =>
`https://cdn.jsdelivr.net/pyodide/v${version}/full/pyodide.mjs`,
async engine({ loadPyodide }, config, url, baseURL) {
// apply override ASAP then load foreign code
Expand Down
24 changes: 13 additions & 11 deletions esm/worker/_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import IDBMap from '@webreflection/idb-map';
import IDBMapSync from '@webreflection/idb-map/sync';

import * as JSON from '@ungap/structured-clone/json';
import coincident from 'coincident/window/worker';
import { decoder } from '@webreflection/coincident/flatted/decoder';
import coincident from '@webreflection/coincident/window/worker';

import { assign, create, createFunction, createOverload, createResolved, dispatch, registerJSModules } from '../utils.js';
import createJSModules from './js_modules.js';
Expand All @@ -33,21 +33,23 @@ const add = (type, fn) => {
);
};

const { parse, stringify } = JSON;

const { proxy: sync, sync: syncMainAndWorker, polyfill, window, isWindowProxy } = await coincident({
parse,
stringify,
const {
proxy: sync,
native,
window,
isWindowProxy
} = await coincident({
decoder,
transform: value => transform ? transform(value) : value
});

const xworker = {
// propagate the fact SharedArrayBuffer is polyfilled
polyfill,
polyfill: !native,
// allows synchronous utilities between this worker and the main thread
sync,
// allow access to the main thread world whenever it's possible
window: syncMainAndWorker ? window : null,
window: native ? window : null,
// allow introspection for foreign (main thread) refrences
isWindowProxy,
// standard worker related events / features
Expand Down Expand Up @@ -126,7 +128,7 @@ add('message', ({ data: { options, config: baseURL, configURL, code, hooks } })
// there's no way to query the DOM, use foreign CustomEvent and so on
// in case there's no SharedArrayBuffer around.
let CustomEvent, document, notify, currentScript = null, target = '';
if (syncMainAndWorker) {
if (native) {
({ CustomEvent, document } = window);
currentScript = id && document.getElementById(id) || null;
notify = kind => dispatch(currentScript, custom || type, kind, true, CustomEvent);
Expand Down Expand Up @@ -216,7 +218,7 @@ add('message', ({ data: { options, config: baseURL, configURL, code, hooks } })
add('error');
add('message');
add('messageerror');
if (syncMainAndWorker) {
if (native) {
addEventListener('py:progress', ({ type, detail }) => {
window.dispatchEvent(new window.CustomEvent(type, { detail }));
});
Expand Down
2 changes: 1 addition & 1 deletion node.importmap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"imports": {
"http://pyodide": "./test/mocked/pyodide.mjs",
"https://cdn.jsdelivr.net/pyodide/v0.27.4/full/pyodide.mjs": "./test/mocked/pyodide.mjs",
"https://cdn.jsdelivr.net/pyodide/v0.27.5/full/pyodide.mjs": "./test/mocked/pyodide.mjs",
"https://cdn.jsdelivr.net/npm/@micropython/[email protected]/micropython.mjs": "./test/mocked/micropython.mjs",
"./3rd-party/toml.js": "./test/mocked/toml.mjs"
}
Expand Down
Loading
Loading