-
Notifications
You must be signed in to change notification settings - Fork 28
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
Are DOM Promises intended to be inherited from in user code? #71
Comments
It'll eventually be possible, but currently engines haven't really progressed so far to make host objects subclassable. |
Is there anything the specs can say to make this more possible? Or do the specs already say that they should be subclassable, and implementations just haven't caught up? |
I think implementing @@create hasn't happened yet and will take a long time. Once that's done there might be some further work spec-wise, but that's far away. |
I don't think |
@domenic Promises have hidden internal state, do they not? If so, to do sub classing the instance must be created with the correct internal structure. |
Oh right! I didn't consider it is the same as any other host object. I guess we can use |
@arv right, they certainly do, but currently those engines create this internal state inside the non-stratified constructor (at least, that's what it seems like reading http://src.chromium.org/viewvc/blink/trunk/Source/bindings/v8/custom/V8PromiseCustom.cpp?pathrev=153560#1284). Later the allocation and initialization steps will be stratified, but I don't see why you can't derive from the current version and call |
@domenic That would not be consistent with ES6. ES6 have [[Call]] throw if the internal data field is not present. See for example http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.14.1.1 , the 3rd step.
If we allowed |
Ah, I see now. Thanks. :( |
Please correct me if I'm wrong but does this mean that in the foreseeable future native (e.g: browser) Promise implementations will not support subclassing? I guess I will just have to feature detect and replace these limited implementations by a shim?
|
I just tried the implementation in Chromium 30 and Firefox Nightly and both throw an error when trying to use prototype delegation with them.
Chromium throws
TypeError: DOM object constructor cannot be called as a function
when trying to usePromise.call
.Firefox throws when calling
then
in the subclassed promise:TypeError: 'then' called on an object that does not implement interface Promise.
Is this by design?
__proto__
works but... you know.The text was updated successfully, but these errors were encountered: