From bb364b05243f7250ebbdf90216d72e52081b2f48 Mon Sep 17 00:00:00 2001 From: Andrea Giammarchi Date: Fri, 9 Jun 2023 20:51:51 +0200 Subject: [PATCH] Shared array buffer missing error (#1518) Improve error reporting around SharedArrayBuffer --- pyscript.core/esm/worker/_template.js | 13 +++++++++++++ pyscript.core/package.json | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pyscript.core/esm/worker/_template.js b/pyscript.core/esm/worker/_template.js index 1f55c412..990f3d6c 100644 --- a/pyscript.core/esm/worker/_template.js +++ b/pyscript.core/esm/worker/_template.js @@ -9,6 +9,19 @@ import coincident from "coincident/structured"; import { registry } from "../runtimes.js"; import { getRuntime, getRuntimeID } from "../loader.js"; +// bails out out of the box with a native/meaningful error +// in case the SharedArrayBuffer is not available +try { + new SharedArrayBuffer(4); +} catch (_) { + throw new Error( + [ + "Unable to use SharedArrayBuffer due insecure environment.", + "Please read requirements in MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements", + ].join("\n"), + ); +} + let engine, run, runtimeEvent; const add = (type, fn) => { addEventListener( diff --git a/pyscript.core/package.json b/pyscript.core/package.json index 5666aa7a..9d197a27 100644 --- a/pyscript.core/package.json +++ b/pyscript.core/package.json @@ -50,6 +50,6 @@ "coincident": "^0.2.3" }, "worker": { - "blob": "sha256-m8uF2bNB691FtVIpuDfAT/avUolqZRQwO9tD3r88+6A=" + "blob": "sha256-LhH/RqqHJJNjYkIoMjALOt1xdneBHAyy+jgMKO07Mx0=" } }