fix sheet conversion in Chrome
by instantiating SharedArrayBuffers in a more portable waypull/1/head
parent
1247ed0b6b
commit
c6fefd73d8
|
@ -72,8 +72,31 @@ define([
|
|||
return JSONSortify(obj);
|
||||
};
|
||||
|
||||
/* Chrome 92 dropped support for SharedArrayBuffer in cross-origin contexts
|
||||
where window.crossOriginIsolated is false.
|
||||
|
||||
Their blog (https://blog.chromium.org/2021/02/restriction-on-sharedarraybuffers.html)
|
||||
isn't clear about why they're doing this, but since it's related to site-isolation
|
||||
it seems they're trying to do vague security things.
|
||||
|
||||
In any case, there seems to be a workaround where you can still create them
|
||||
by using `new WebAssembly.Memory({shared: true, ...})` instead of `new SharedArrayBuffer`.
|
||||
|
||||
This seems unreliable, but it's better than not being able to export, since
|
||||
we actively rely on postMessage between iframes and therefore can't afford
|
||||
to opt for full isolation.
|
||||
*/
|
||||
var supportsSharedArrayBuffers = function () {
|
||||
try {
|
||||
return Object.prototype.toString.call(new WebAssembly.Memory({shared: true, initial: 0, maximum: 0}).buffer) === '[object SharedArrayBuffer]';
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
var supportsXLSX = function () {
|
||||
return !(typeof(Atomics) === "undefined" || typeof (SharedArrayBuffer) === "undefined" || typeof(WebAssembly) === 'undefined');
|
||||
return !(typeof(Atomics) === "undefined" || !supportsSharedArrayBuffers() /* || typeof (SharedArrayBuffer) === "undefined" */ || typeof(WebAssembly) === 'undefined');
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
function SUPPORTS_SHARED_MEMORY() {
|
||||
return typeof(SharedArrayBuffer) !== 'undefined';
|
||||
}
|
||||
|
||||
|
||||
// Support for growable heap + pthreads, where the buffer may change, so JS views
|
||||
// must be updated.
|
||||
function GROWABLE_HEAP_STORE_I8(ptr, value) {
|
||||
|
@ -1030,7 +1035,7 @@ if (ENVIRONMENT_IS_PTHREAD) {
|
|||
"maximum": 1073741824 / WASM_PAGE_SIZE,
|
||||
"shared": true
|
||||
});
|
||||
if (!(wasmMemory.buffer instanceof SharedArrayBuffer)) {
|
||||
if (Object.prototype.toString.call(wasmMemory.buffer) !== '[object SharedArrayBuffer]') {
|
||||
err("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag");
|
||||
if (ENVIRONMENT_HAS_NODE) {
|
||||
console.log("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)");
|
||||
|
@ -2161,7 +2166,7 @@ var PThread = {
|
|||
}),
|
||||
receiveObjectTransfer: (function(data) {}),
|
||||
allocateUnusedWorkers: (function(numWorkers, onFinishedLoading) {
|
||||
if (typeof SharedArrayBuffer === "undefined") return;
|
||||
if (!SUPPORTS_SHARED_MEMORY()) return;
|
||||
var workers = [];
|
||||
var numWorkersToCreate = numWorkers;
|
||||
if (PThread.preallocatedWorkers.length > 0) {
|
||||
|
@ -2276,7 +2281,7 @@ var PThread = {
|
|||
}
|
||||
}),
|
||||
createNewWorkers: (function(numWorkers) {
|
||||
if (typeof SharedArrayBuffer === "undefined") return [];
|
||||
if (!SUPPORTS_SHARED_MEMORY()) return [];
|
||||
var pthreadMainJs = "x2t.worker.js";
|
||||
pthreadMainJs = locateFile(pthreadMainJs);
|
||||
var newWorkers = [];
|
||||
|
@ -5683,7 +5688,7 @@ function _emscripten_get_sbrk_ptr() {
|
|||
}
|
||||
Module["_emscripten_get_sbrk_ptr"] = _emscripten_get_sbrk_ptr;
|
||||
function _emscripten_has_threading_support() {
|
||||
return typeof SharedArrayBuffer !== "undefined";
|
||||
return SUPPORTS_SHARED_MEMORY();
|
||||
}
|
||||
Module["_emscripten_has_threading_support"] = _emscripten_has_threading_support;
|
||||
function _emscripten_is_main_browser_thread() {
|
||||
|
@ -6761,7 +6766,7 @@ function _pthread_self() {
|
|||
}
|
||||
Module["_pthread_self"] = _pthread_self;
|
||||
function _pthread_create(pthread_ptr, attr, start_routine, arg) {
|
||||
if (typeof SharedArrayBuffer === "undefined") {
|
||||
if (!SUPPORTS_SHARED_MEMORY()) {
|
||||
err("Current environment does not support SharedArrayBuffer, pthreads are not available!");
|
||||
return 6;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue