diff --git a/Sources/macro.js b/Sources/macro.js index b10446e7b88..fd797061e74 100644 --- a/Sources/macro.js +++ b/Sources/macro.js @@ -1,4 +1,4 @@ -import vtk from './vtk'; +import vtk, { vtkGlobal } from './vtk'; import ClassHierarchy from './Common/Core/ClassHierarchy'; let globalMTime = 0; @@ -33,14 +33,14 @@ consoleMethods.forEach((methodName) => { fakeConsole[methodName] = noOp; }); -global.console = console.hasOwnProperty('log') ? console : fakeConsole; +vtkGlobal.console = console.hasOwnProperty('log') ? console : fakeConsole; const loggerFunctions = { debug: noOp, // Don't print debug by default - error: global.console.error || noOp, - info: global.console.info || noOp, - log: global.console.log || noOp, - warn: global.console.warn || noOp, + error: vtkGlobal.console.error || noOp, + info: vtkGlobal.console.info || noOp, + log: vtkGlobal.console.log || noOp, + warn: vtkGlobal.console.warn || noOp, }; export function setLoggerFunction(name, fn) { diff --git a/Sources/vtk.js b/Sources/vtk.js index 7cb7fb312b7..e2499df60a5 100644 --- a/Sources/vtk.js +++ b/Sources/vtk.js @@ -1,3 +1,7 @@ +import globalThisShim from 'globalthis'; + +export const vtkGlobal = globalThisShim(); // returns native globalThis if compliant + const factoryMapping = { vtkObject: () => null, }; @@ -10,15 +14,15 @@ export default function vtk(obj) { return obj; } if (!obj.vtkClass) { - if (global.console && global.console.error) { - global.console.error('Invalid VTK object'); + if (vtkGlobal.console && vtkGlobal.console.error) { + vtkGlobal.console.error('Invalid VTK object'); } return null; } const constructor = factoryMapping[obj.vtkClass]; if (!constructor) { - if (global.console && global.console.error) { - global.console.error( + if (vtkGlobal.console && vtkGlobal.console.error) { + vtkGlobal.console.error( `No vtk class found for Object of type ${obj.vtkClass}` ); } diff --git a/package-lock.json b/package-lock.json index df1e74d1e09..65ac170f7d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7524,7 +7524,6 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", - "dev": true, "requires": { "object-keys": "^1.0.12" } @@ -9873,7 +9872,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.2.tgz", "integrity": "sha512-ZQnSFO1la8P7auIOQECnm0sSuoMeaSq0EEdXMBFF2QJO4uNcwbyhSgG3MruWNbFTqCLmxVwGOl7LZ9kASvHdeQ==", - "dev": true, "requires": { "define-properties": "^1.1.3" } @@ -15642,8 +15640,7 @@ "object-keys": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", - "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" }, "object-visit": { "version": "1.0.1", diff --git a/package.json b/package.json index 81e3a77a29b..3392a7b6738 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "commander": "6.2.1", "d3-scale": "3.2.4", "gl-matrix": "3.3.0", + "globalthis": "^1.0.2", "jszip": "3.2.0", "pako": "2.0.3", "seedrandom": "3.0.5",