| 43 | constructor() { } |
| 44 | |
| 45 | private _initialize(): void { |
| 46 | if (this._state === AMDModuleImporterState.Uninitialized) { |
| 47 | if (globalThis.define) { |
| 48 | this._state = AMDModuleImporterState.InitializedExternal; |
| 49 | return; |
| 50 | } |
| 51 | } else { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | this._state = AMDModuleImporterState.InitializedInternal; |
| 56 | |
| 57 | globalThis.define = (id: any, dependencies: any, callback: any) => { |
| 58 | if (typeof id !== 'string') { |
| 59 | callback = dependencies; |
| 60 | dependencies = id; |
| 61 | id = null; |
| 62 | } |
| 63 | if (typeof dependencies !== 'object' || !Array.isArray(dependencies)) { |
| 64 | callback = dependencies; |
| 65 | dependencies = null; |
| 66 | } |
| 67 | // if (!dependencies) { |
| 68 | // dependencies = ['require', 'exports', 'module']; |
| 69 | // } |
| 70 | this._defineCalls.push(new DefineCall(id, dependencies, callback)); |
| 71 | }; |
| 72 | |
| 73 | globalThis.define.amd = true; |
| 74 | |
| 75 | if (this._isRenderer) { |
| 76 | this._amdPolicy = globalThis._VSCODE_WEB_PACKAGE_TTP ?? window.trustedTypes?.createPolicy('amdLoader', { |
| 77 | createScriptURL(value: any) { |
| 78 | if (value.startsWith(window.location.origin)) { |
| 79 | return value; |
| 80 | } |
| 81 | if (value.startsWith(`${Schemas.vscodeFileResource}://${VSCODE_AUTHORITY}`)) { |
| 82 | return value; |
| 83 | } |
| 84 | throw new Error(`[trusted_script_src] Invalid script url: ${value}`); |
| 85 | } |
| 86 | }); |
| 87 | } else if (this._isWebWorker) { |
| 88 | this._amdPolicy = globalThis._VSCODE_WEB_PACKAGE_TTP ?? globalThis.trustedTypes?.createPolicy('amdLoader', { |
| 89 | createScriptURL(value: string) { |
| 90 | return value; |
| 91 | } |
| 92 | }); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | public async load<T>(scriptSrc: string): Promise<T> { |
| 97 | this._initialize(); |