-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question for champions: Minimum viable module descriptors #55
Comments
If we're going to remove namespace descriptors, I'd want to require a |
Without namespace module descriptors, lifting an arbitrary object into the form of a ModuleExportsNamespace that passes a brand check would be: const makeExports = object => {
const names = Object.getOwnPropertyNames(object);
const record = {
bindings: names.map(name => ({export: name})),
initialize(env) {
for (const name of names) {
env[name] = object[name];
}
},
};
const modules = {
stub: { record },
};
const compartment = new Compartment({ modules });
return compartment.importNow('stub');
} This has exactly the same caveats as |
There are pretty standard conventions in the language for this already, operations like |
However, Object.keys/entries/values only include enumerable string property keys; |
The difference with these methods is they are intentionally specialized towards gettings all own keys, The thing about the other methods is they are all higher level in the regard that they could be implemented in userland using the There are some differences with the various APIs with symbol handling, but like in records that doesn't really apply here because modules don't have symbol keys either. |
For the record, I observe that, if we included support for That suggests that the crux of this issue lies in whether champions prefer to include or exclude this form in the proposal as a value judgement. On the one hand, leaving it out reduces the debatable mass of the proposal without reducing what motivating cases are expressible. Whereas including it invites debate. The other proposed form, So the question is whether the champions feel the complexity is worth the cost. So, for a temperature check, I propose meanings for reaction emojis:
|
The design of the module descriptor type union unfortunately exists on a sliding scale from minimal to ergonomic.
The original design was:
string | namespace
, wherestring
was roughly equivalent to the proposed{ record: string }
andnamespace
was equivalent to{ namespace: ModuleExportsNamespace }
. This did not afford us a position to carryimportMeta
or handle inter-compartment linkage. The SES-shim evolved the API to support an optional “envelope” to handle those cases, and distinguished the envelope from namespace via ModuleExportsNamespace brand check. Our friends at Moddable eventually arrived at the notion of a module descriptor union, which allowed us to simplify this proposal considerably.I believe the minimal design would be
{ record: StaticModuleRecord | SyntheticStaticModuleRecord } | { record: string, loader?: Loader } | { instance: string, loader?: Loader }
. We can recover{ namespace: ModuleExportsNamespace }
from{ instance: string }
and we can recover{ namespace: ^ModuleExportsNamespace }
with a fake compartment andSyntheticStaticModuleRecord
. That is to say, we could remove thenamespace
descriptors: one or even both.@patrick-soquet at Moddable is reluctant to include
{ namespace: ^ModuleExportsNamespace }
, which is equivalent to and has the same drawbacks as creating aSyntheticStaticModuleRecord
that binds exports for all the own enumerable properties of an arbitrary JavaScript object. The ModuleExportsNamespace inside the comaprtment/loader would be different than the one passed. Live bindings would be limited. That is to say, the form is strictly a convenience.I believe I can fairly represent @patrick-soquet’s preference that we also keep a
string
typed descriptor as an abbreviation of{ record: string }
and aModuleExportsNamespace
abbreviation either in addition to or instead of the equivalent{ namespace: ModuleExportsNamespace }
.To that end, I think we should decide on two guiding design principles:
The text was updated successfully, but these errors were encountered: