-
-
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
Add doc note about conversion of a value nested in a promise #257
Comments
I'm not sure what you mean by "there is no way to represent a promise value in IDL", or "a return value defined with Web IDL and wrapped in a promise will not be converted when the promise resolve". Could you give a code example? |
This is the description used in the Web IDL specification. I naively expected that an instance of a class defined with IDL and wrapped in a promise, as a return value from a class method also defined with Web IDL, could be returned as an instance of its wrapper class, due to what I remembered from the related section in the My suggestion is just an attempt to clarify that despite the presence of the The related Web IDL ( |
This means there's no syntax for producing promise values, like
Sorry, this is quite hard to follow for me. Could you give a code example of what you wrote in the impl class, what you expected to happen, and what happened instead? |
It's my fault, I'm in a rush to finish this asap. Web IDL:
Implementation class: class CSSStyleSheetImpl {
replace() {
/* not meaningfull */
return Promise.resolve().then(() => {
/* not meaningfull */
return this
/* Workaround: return wrapperForImpl(this) */
})
}
}
module.exports = { implementation: CSSStyleSheetImpl } (Failing) test file: const CSSStyleSheetWrapper = require('wrappers/CSSStyleSheet.js')
describe('CSSStyleSheet.replace()', () => {
it('should return the instance of CSSStyleSheet', async () => {
const styleSheet = CSSStyleSheetWrapper.create(globalThis)
const styleSheetRef = await styleSheet.replace()
expect(styleSheetRef).toBe(styleSheet) // Fails (but expected to succeed)
expect(CSSStyleSheetWrapper.is(styleSheetRef)).toBeTruthy() // Fails (but expected to succeed)
expect(CSSStyleSheetWrapper.isImpl(styleSheetRef)).toBeTruthy() // Success (but not expected)
})
}) |
Here is a reproduction repo for what I'm trying to demonstrate (run I tried to understand why |
Got it, yes, I can see how the docs aren't sufficiently clear here. In fact, looking further it seems like they might just be wrong? I don't see any code for us to handle the The ideal fix for this would be finishing up #108. In the meantime, the way we work around this is to write slightly-more-awkward impl classes, which use wrapperForImpl. E.g. here is an example of manually wrapping a |
Because a
<Promise>
is defined in Web IDL but there is no way to represent a promise value in IDL, a return value defined with Web IDL and wrapped in a promise will not be converted when the promise resolves, therefore I suggest the following modification:The text was updated successfully, but these errors were encountered: