Skip to content
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

[SameObject]/[NewObject] on Promise-type attributes should be allowed #71

Open
travisleithead opened this issue Oct 29, 2015 · 12 comments

Comments

@travisleithead
Copy link
Member

Because Promise types are reference types, the [SameObject] extended attribute should be permitted for use with them. In the current spec, they are forbidden by the restriction:

4.3.15. SameObject

The [SameObject] extended attribute MUST NOT be used on anything other than a read only attribute whose type is an interface type or object.

(Unless Promise is to be understood as an interface type.)

@heycam
Copy link
Collaborator

heycam commented Oct 29, 2015

Sounds reasonable. What about linking it to http://heycam.github.io/webidl/#dfn-object-type and then adding promise types to that definition?

@bzbarsky
Copy link
Collaborator

[NewObject] has the same issue; see https://www.w3.org/Bugs/Public/show_bug.cgi?id=27605

@dontcallmedom
Copy link
Contributor

I believe [SameObject] should also be applicable to union of interface types; the Service Worker spec certainly assumes that to be true.

@jungkees
Copy link
Contributor

Ping? :)

@domenic domenic changed the title Promise type on an attribute should be allowed [SameObject]/[NewObject] on Promise-type attributes should be allowed Oct 22, 2016
@domenic
Copy link
Member

domenic commented Oct 22, 2016

In https://www.w3.org/Bugs/Public/show_bug.cgi?id=27605#c1 @bzbarsky notes that this should not just be extended to promise types, but also

It should be allowed if the return value is any object type. Specifically, any interface type, "object", a promise, an Error, a DOMException, any buffer source type, or a union of types on which [NewObject] is allowed.

tobie added a commit to tobie/webidl that referenced this issue Oct 27, 2016
Update [SameObject] and [NewObject] to rely on it.

Fixes whatwg#71
Fixes https://www.w3.org/Bugs/Public/show_bug.cgi?id=27605
@annevk
Copy link
Member

annevk commented Aug 23, 2017

Note that due to #217 promise getters cannot use [SameObject], ever.

@kainino0x
Copy link

Seems the spec is clear that promise getters can't use [SameObject] and can use [NewObject]. I've filed a separate issue #1077 for non-promise objects since those aren't covered by the title of this issue. Seems that covers everything and this issue could be closed now.

I do have one related thought though:
Should promise getters be required to use [NewObject]? IIUC that's the behavior, and having [NewObject] would document the behavior much more clearly.

@bathos
Copy link
Contributor

bathos commented Dec 16, 2021

Should promise getters be required to use [NewObject]?

Was this meant to say [SameObject]? [NewObject] is only defined for operations and I assumed this was because that behavior is very problematic in practice for attributes. Neither is permitted by a Promise attribute.

Although there is at least one existing quirk where this doesn't hold (valueAsDate), attribute getters that cause SameValue(foo.bar, foo.bar) to always be false (i.e., with no other code in between) tend to break JS expectations, sometimes catastrophically (e.g. the old Angular diffing algorithm).

"Can use [NewObject]" isn't true for any attribute currently, regardless of its type. [SameObject] does work with attributes but specifically forbids Promise types. AFAIK it's for "fully permanent" values, i.e. never changing regardless of application state, not just never changing across consecutive accesses.

@kainino0x
Copy link

Was this meant to say [SameObject]? [NewObject] is only defined for operations and I assumed this was because that behavior is very problematic in practice for attributes. Neither is permitted by a Promise attribute.

No, I meant [NewObject]. (The title of the issue made me think attributes could have [NewObject].) I guess my understanding was overly simplified if even Promise typed attributes can indeed return the same Promise object multiple times. And it makes sense that they can.

In that case I think this issue can be closed as obsolete since it sounds like there are no outstanding changes to be made, wrt the title/original topic of this issue. #1077 tracks the issue about unions/objects/etc that was previously raised as a tangent of this issue.

@bathos
Copy link
Contributor

bathos commented Dec 16, 2021

Both of these extended attributes are a bit odd in that they are "pure" annotations describing high level API behavior. They have no corresponding effects in any Web IDL algorithms. They seemingly don't meet Web IDL's own definition for what an extended attribute is because they don't control behaviors that are specific to particular language bindings. That definition is likely just outdated, but like ... if you have found any of this confusing, you're right :)

@bzbarsky
Copy link
Collaborator

they don't control behaviors that are specific to particular language bindings.

They actually can, though not in obvious ways. For example, in some JITs they inform things like common subexpression elimination behavior.

@bathos
Copy link
Contributor

bathos commented Dec 17, 2021

That makes sense. The distinction I meant to highlight was that they describe universal properties of the operation/attribute behavior itself. Contrast e.g. PutForwards, which is defined only in terms of ES binding behavior, where any other binding (unless given its own rules for interpretting that EA) just sees a readonly attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

10 participants