From b2bab632dce2919c2c62146c9a4f97ad54718d09 Mon Sep 17 00:00:00 2001 From: Mark Chambers Date: Wed, 10 Mar 2021 14:23:02 +1300 Subject: [PATCH] fix SharedArrayBuffer when x-origin is enabled, copied from #20831 --- packages/scheduler/src/SchedulerProfiling.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/scheduler/src/SchedulerProfiling.js b/packages/scheduler/src/SchedulerProfiling.js index 810a5be22327..3036476afeeb 100644 --- a/packages/scheduler/src/SchedulerProfiling.js +++ b/packages/scheduler/src/SchedulerProfiling.js @@ -15,13 +15,18 @@ import {NoPriority} from './SchedulerPriorities'; let runIdCounter: number = 0; let mainThreadIdCounter: number = 0; +const isEnabledSharedArrayBuffer = + // $FlowFixMe Flow doesn't know about SharedArrayBuffer + typeof SharedArrayBuffer === 'function' && + // We only use SharedArrayBuffer when cross origin isolation is enabled. + typeof window !== 'undefined' && + window.crossOriginIsolated === true; + const profilingStateSize = 4; export const sharedProfilingBuffer = enableProfiling - ? // $FlowFixMe Flow doesn't know about SharedArrayBuffer - typeof SharedArrayBuffer === 'function' + ? isEnabledSharedArrayBuffer ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) - : // $FlowFixMe Flow doesn't know about ArrayBuffer - typeof ArrayBuffer === 'function' + : typeof ArrayBuffer === 'function' ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : null // Don't crash the init path on IE9 : null;