-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Separating constructor and new? #193
Comments
This is what I came up with. It does not require any impl-side changes. exports.webidlNew = (globalObject, typeName, implModule) => {
if (globalObject[utils.ctorRegistrySymbol] === undefined) {
throw new Error('Internal error: invalid global object');
}
const ctor = globalObject[utils.ctorRegistrySymbol][typeName];
if (ctor === undefined) {
throw new Error(`Internal error: constructor ${typeName} is not installed on the passed global object`);
}
const obj = Object.create(ctor.prototype);
Object.defineProperty(obj, utils.implSymbol, {
value: Object.create(implModule.implementation.prototype),
configurable: true
});
obj[utils.implSymbol][utils.wrapperSymbol] = obj;
return obj[utils.implSymbol];
}; The arguments would change (to just globalObject, I think) if we exported this from the generated file. And we'd want to do some work to deduplicate the contents of this function with create/createImpl/setup. But it seems to work. Naming it |
How do you call the impl constructor after creating an object with |
You don't; you fill in the slots manually. See for example https://whatpr.org/streams/1035.html#acquire-readable-stream-byob-reader vs. https://whatpr.org/streams/1035.html#default-reader-constructor . |
I'm trying to implement whatwg/streams#1035 and running into the issue that we don't have a way to invoke the Web IDL new operation without also invoking the impl constructor.
The impl constructor is what backs the wrapper constructor. But in specs we have two different paths for creating platform objects:
new PlatformObject()
from JS code runs these stepsPlatformObject
" and then initialize them directly.We don't currently have a way of doing the latter.
I'll probably investigate with some patches locally in the streams repo, but this issue can track upstreaming them.
The text was updated successfully, but these errors were encountered: