Skip to content

Commit 2e5da7c

Browse files
Merge pull request #136 from pyscript/coincident-v4
Updated coincident to its latest v4
2 parents fa3e02c + b33717a commit 2e5da7c

16 files changed

+133
-130
lines changed

docs/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import s from"https://cdn.jsdelivr.net/npm/sabayon/dist/polyfill.js";if(!globalThis.crossOriginIsolated){const{isArray:r}=Array,t=s=>s.length&&"object"==typeof s[0]&&null!==s[0];globalThis.Blob=class extends Blob{constructor(s,...e){t(e)&&"text/javascript"===e[0].type&&r(s)&&"string"==typeof s.at(0)&&(s[0]=s[0].replace(/^\/\*@\*\//,'import "https://cdn.jsdelivr.net/npm/sabayon/dist/polyfill.js";')),super(s,...e)}},globalThis.Worker=class extends Worker{constructor(r,...e){if(t(e)){const r=e[0].serviceWorker||e[0].service_worker;r&&s(r)}super(r,...e)}}}
1+

docs/toml-CkEFU7ly.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,3 @@ const parse = toml => {
100100
/* c8 ignore stop */
101101

102102
export { parse };
103-
//# sourceMappingURL=toml-CkEFU7ly.js.map

docs/toml-DiUM0_qs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/zip-CAMAhqMX.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/zip-CAMAhqMX.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/interpreter/_python.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as FLATTED from 'coincident/flatted';
2-
const JSON = { parse: FLATTED.decode, stringify: FLATTED.encode };
1+
import * as DIRECT from 'reflected-ffi/direct';
2+
const JSON = { parse: DIRECT.decode, stringify: DIRECT.encode };
33

44
import { fetchFiles, fetchJSModules, fetchPaths } from './_utils.js';
55
import { IDBMapSync, dedent } from '../utils.js';

esm/interpreter/webr.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
import { create } from 'gc-hook';
21
import { dedent } from '../utils.js';
32
import { fetchFiles, fetchJSModules, fetchPaths } from './_utils.js';
43
import { io, stdio } from './_io.js';
54

65
const type = 'webr';
76
const r = new WeakMap();
7+
const fr = new FinalizationRegistry(fn => fn());
88

99
// REQUIRES INTEGRATION TEST
1010
/* c8 ignore start */
1111
const run = async (interpreter, code) => {
1212
const { shelter, destroy, io } = r.get(interpreter);
1313
const { output, result } = await shelter.captureR(dedent(code));
1414
for (const { type, data } of output) io[type](data);
15-
// this is a double proxy but it's OK as the consumer
16-
// of the result here needs to invoke explicitly a conversion
17-
// or trust the `(await p.toJs()).values` returns what's expected.
18-
return create(result, destroy, { token: false });
15+
fr.register(result, destroy);
16+
return result;
1917
};
2018

2119
export default {

esm/service-worker.js

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
import sabayon from 'https://cdn.jsdelivr.net/npm/sabayon/dist/polyfill.js';
1+
// Let's avoid 404s *but* this should not be needed anymore*
22

3-
// ignore browsers that already support SharedArrayBuffer
4-
if (!globalThis.crossOriginIsolated) {
5-
const { isArray } = Array;
6-
const isOptions = args => args.length && typeof args[0] === 'object' && args[0] !== null;
3+
// import sabayon from 'https://cdn.jsdelivr.net/npm/sabayon/dist/polyfill.js';
74

8-
// early patch Blob to inject sabayon polyfill for service-worker
9-
globalThis.Blob = class extends Blob {
10-
constructor(blobParts, ...args) {
11-
if (
12-
isOptions(args) &&
13-
args[0].type === 'text/javascript' &&
14-
isArray(blobParts) &&
15-
typeof blobParts.at(0) === 'string'
16-
) {
17-
blobParts[0] = blobParts[0].replace(
18-
/^\/\*@\*\//,
19-
'import "https://cdn.jsdelivr.net/npm/sabayon/dist/polyfill.js";'
20-
);
21-
}
22-
super(blobParts, ...args);
23-
}
24-
};
5+
// // ignore browsers that already support SharedArrayBuffer
6+
// if (!globalThis.crossOriginIsolated) {
7+
// const { isArray } = Array;
8+
// const isOptions = args => args.length && typeof args[0] === 'object' && args[0] !== null;
259

26-
// early patch Worker to bootstrap sabayon for service-worker
27-
globalThis.Worker = class extends Worker {
28-
constructor(url, ...args) {
29-
if (isOptions(args)) {
30-
const sw = args[0].serviceWorker || args[0].service_worker;
31-
if (sw) sabayon(sw);
32-
}
33-
super(url, ...args);
34-
}
35-
};
36-
}
10+
// // early patch Blob to inject sabayon polyfill for service-worker
11+
// globalThis.Blob = class extends Blob {
12+
// constructor(blobParts, ...args) {
13+
// if (
14+
// isOptions(args) &&
15+
// args[0].type === 'text/javascript' &&
16+
// isArray(blobParts) &&
17+
// typeof blobParts.at(0) === 'string'
18+
// ) {
19+
// blobParts[0] = blobParts[0].replace(
20+
// /^\/\*@\*\//,
21+
// 'import "https://cdn.jsdelivr.net/npm/sabayon/dist/polyfill.js";'
22+
// );
23+
// }
24+
// super(blobParts, ...args);
25+
// }
26+
// };
27+
28+
// // early patch Worker to bootstrap sabayon for service-worker
29+
// globalThis.Worker = class extends Worker {
30+
// constructor(url, ...args) {
31+
// if (isOptions(args)) {
32+
// const sw = args[0].serviceWorker || args[0].service_worker;
33+
// if (sw) sabayon(sw);
34+
// }
35+
// super(url, ...args);
36+
// }
37+
// };
38+
// }

esm/worker/_template.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import IDBMap from '@webreflection/idb-map';
88
import IDBMapSync from '@webreflection/idb-map/sync';
99

10-
import { decoder } from 'coincident/flatted/decoder';
1110
import coincident from 'coincident/window/worker';
1211

1312
import { assign, create, createFunction, createOverload, createResolved, dispatch, registerJSModules } from '../utils.js';
@@ -35,22 +34,23 @@ const add = (type, fn) => {
3534

3635
const {
3736
proxy: sync,
37+
sync: polyfill,
3838
native,
3939
window,
40-
isWindowProxy
40+
isWindowProxy,
41+
ffi,
4142
} = await coincident({
42-
decoder,
4343
transfer: false,
4444
transform: value => transform ? transform(value) : value
4545
});
4646

4747
const xworker = {
4848
// propagate the fact SharedArrayBuffer is polyfilled
49-
polyfill: !native,
49+
polyfill,
5050
// allows synchronous utilities between this worker and the main thread
5151
sync,
5252
// allow access to the main thread world whenever it's possible
53-
window: native ? window : null,
53+
window: (native || polyfill) ? window : null,
5454
// allow introspection for foreign (main thread) refrences
5555
isWindowProxy,
5656
// standard worker related events / features
@@ -129,7 +129,7 @@ add('message', ({ data: { options, config: baseURL, configURL, code, hooks } })
129129
// there's no way to query the DOM, use foreign CustomEvent and so on
130130
// in case there's no SharedArrayBuffer around.
131131
let CustomEvent, document, notify, currentScript = null, target = '';
132-
if (native) {
132+
if (native || polyfill) {
133133
({ CustomEvent, document } = window);
134134
currentScript = id && document.getElementById(id) || null;
135135
notify = kind => dispatch(currentScript, custom || type, kind, true, CustomEvent);
@@ -147,6 +147,7 @@ add('message', ({ data: { options, config: baseURL, configURL, code, hooks } })
147147
currentScript,
148148
config: resolved.config,
149149
js_modules: JSModules,
150+
ffi,
150151
get target() {
151152
if (!target && currentScript) {
152153
if (tag === 'SCRIPT') {
@@ -219,7 +220,7 @@ add('message', ({ data: { options, config: baseURL, configURL, code, hooks } })
219220
add('error');
220221
add('message');
221222
add('messageerror');
222-
if (native) {
223+
if (native || polyfill) {
223224
addEventListener('py:progress', ({ type, detail }) => {
224225
window.dispatchEvent(new window.CustomEvent(type, { detail }));
225226
});

esm/worker/class.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export default (...args) =>
3737
const [ config ] = getConfigURLAndType(options.config, options.configURL);
3838

3939
const serviceWorker = options?.serviceWorker || options?.service_worker;
40-
const worker = xworker({ serviceWorker });
40+
const worker = xworker({
41+
serviceWorker,
42+
reflected_ffi_timeout: globalThis.reflected_ffi_timeout ?? -1,
43+
});
4144
const { postMessage } = worker;
4245
const isHook = this instanceof Hook;
4346

@@ -62,6 +65,9 @@ export default (...args) =>
6265
defineProperties(worker, {
6366
sync: { value: sync },
6467
ready: { value: resolver.promise },
68+
ffi: {
69+
direct: worker.direct,
70+
},
6571
postMessage: {
6672
value: (data, ...rest) => bootstrap.then(
6773
() => postMessage.call(worker, data, ...rest),

esm/worker/hook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import toJSONCallback from 'to-json-callback';
1+
import toJSONCallback from 'reflected-ffi/to-json-callback';
22

33
import { dedent } from '../utils.js';
44
import { js as jsHooks, code as codeHooks } from '../hooks.js';

0 commit comments

Comments
 (0)