Sandbox: Make window.monaco and window.Prism available for plugins inside the sandbox (#74977)

* Sandbox: Make `window.monaco` available for plugins inside the sandbox

* Add Prism as an endowment

* Fix typo
This commit is contained in:
Esteban Beltran 2023-09-18 10:45:09 +02:00 committed by GitHub
parent dfd6134ff1
commit c7b6ac065a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,6 +80,15 @@ async function doImportPluginModuleInSandbox(meta: PluginMeta): Promise<System.M
// window.locationSandbox. In the future `window.location` could be a proxy if we
// want to intercept calls to it.
locationSandbox: window.location,
get monaco() {
// `window.monaco` may be undefined when invoked. However, plugins have long
// accessed it directly, aware of this possibility.
return Reflect.get(window, 'monaco');
},
get Prism() {
// Similar to `window.monaco`, `window.Prism` may be undefined when invoked.
return Reflect.get(window, 'Prism');
},
// Plugins builds use the AMD module system. Their code consists
// of a single function call to `define()` that internally contains all the plugin code.
// This is that `define` function the plugin will call.