Here is how to run the demo after you download the zip file containing this gist.
$ node main.mjs
[Function: foo] [Function: foo] [Function: bar] [Function: bar]
This gist shows that the compartment module map doesn't have to be deterministic.
On each subsequent run, the module map resolves to different modules depending on the current seconds on the clock.
Example of executing the same code without recompile before the second run:
trace(`Compartment imported\n`); | |
const XSCompartment = globalThis.Compartment; | |
trace('Compartment.map: ' + Object.keys(XSCompartment.map)+'\n'); | |
// Mappin utility function. | |
// Create the child XS map from the parent XS map. | |
function createXSMap(modules) { | |
// Need to at least allow new compartments to be created. | |
const result = { Compartment: XSCompartment.map.Compartment }; |
A Compartment object abstracts the notion of a distinct global environment, with its own global object, copy of the standard library, but shares the "intrinsics" (standard objects that are not bound to global variables, like the initial value of Object.prototype) with the current execution environment.
class Compartment {
constructor: (
globals : object?, // extra globals added to the global object
modules: object?, // module map, specifier to specifier
) -> object,
/* | |
* Copyright (c) 2019 Moddable Tech, Inc. | |
* | |
* This file is part of the Moddable SDK. | |
* | |
* This work is licensed under the | |
* Creative Commons Attribution 4.0 International License. | |
* To view a copy of this license, visit | |
* <http://creativecommons.org/licenses/by/4.0>. | |
* or send a letter to Creative Commons, PO Box 1866, |
I hereby claim:
To claim this, I am signing this object:
#!/bin/bash | |
# IMPORTANT: You will need to disable SIP aka Rootless in order to fully execute this script, you can reenable it after. | |
# WARNING: It might disable things that you may not like. Please double check the services in the TODISABLE vars. | |
# Get active services: launchctl list | grep -v "\-\t0" | |
# Find a service: grep -lR [service] /System/Library/Launch* /Library/Launch* ~/Library/LaunchAgents | |
# Agents to disable | |
TODISABLE=('com.apple.security.keychainsyncingoveridsproxy' 'com.apple.personad' 'com.apple.passd' 'com.apple.screensharing.MessagesAgent' 'com.apple.CommCenter-osx' 'com.apple.Maps.mapspushd' 'com.apple.Maps.pushdaemon' 'com.apple.photoanalysisd' 'com.apple.telephonyutilities.callservicesd' 'com.apple.AirPlayUIAgent' 'com.apple.AirPortBaseStationAgent' 'com.apple.CalendarAgent' 'com.apple.DictationIM' 'com.apple.iCloudUserNotifications' 'com.apple.familycircled' 'com.apple.familycontrols.useragent' 'com.apple.familynotificationd' 'com.apple.gamed' 'com.apple.icloud.findmydeviced.findmydevi |