From 67689ed82cfae4aa1a8bf5628d73f1211181d332 Mon Sep 17 00:00:00 2001 From: Manu MA Date: Tue, 30 Mar 2021 21:20:00 +0200 Subject: [PATCH] fix(): worker support for safari (#2869) --- src/compiler/bundle/worker-plugin.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/compiler/bundle/worker-plugin.ts b/src/compiler/bundle/worker-plugin.ts index 4dc050cc051..4c7d656228d 100644 --- a/src/compiler/bundle/worker-plugin.ts +++ b/src/compiler/bundle/worker-plugin.ts @@ -196,12 +196,18 @@ const WORKER_SUFFIX = ['.worker.ts', '.worker.tsx', '.worker/index.ts', '.worker const WORKER_HELPER_ID = '@worker-helper'; const GET_TRANSFERABLES = ` +const isInstanceOf = (value, className) => { + const C = globalThis[className]; + return C != null && value instanceof C; +} const getTransferables = (value) => { if (value != null) { - if (value instanceof ArrayBuffer - || value instanceof MessagePort - || value instanceof ImageBitmap - || value instanceof OffscreenCanvas) { + if ( + isInstanceOf(value, "ArrayBuffer") || + isInstanceOf(value, "MessagePort") || + isInstanceOf(value, "ImageBitmap") || + isInstanceOf(value, "OffscreenCanvas") + ) { return [value]; } if (typeof value === "object") {