patrickkettner / cookie-change-events

small extension to document.cookie that allows for event listeners
https://patrickkettner.github.io/cookie-change-events/
Other
22 stars 3 forks source link

Need to update the `Document` interface #4

Closed arronei closed 7 years ago

arronei commented 7 years ago

You need to update the Document interface and update the way cookie works.

[Exposed=Window]
partial interface Document {
    attribute Cookie cookie;
}
arronei commented 7 years ago

Note: I am not sure how this is going to work for interop. You might need to do this...

attribute (USVString or Cookie) cookie;

arronei commented 7 years ago
dictionary CookieInit {
    USVString name;
    required USVString value;
    DOMString expirationDate;
};

[Exposed=Window]
[Constructor(CookieInit cookieInitDict)]
interface Cookie {
    readonly attribute USVString name;
    attribute USVString value;
    readonly attribute USVString domain;
    readonly attribute USVString path;
    readonly attribute boolean secure;
    readonly attribute boolean session;
    attribute DOMString expirationDate;
    stringifier USVString;
};

[Exposed=Window]
interface CookieJar{
    stringifier attribute USVString value;
    maplike<USVString, Cookie>;
};

partial interface Document {
    [PutForwards=value] attribute CookieJar cookie;
};
arronei commented 7 years ago

Another option for the maplike<USVString, Cookie>; in the CookieJar would be to use a setlike; this would give you the add() method you would rather have instead of the set() method.

arronei commented 7 years ago

I am thinking more about this and I think it would be great to be able to access the new Cookie object by the [] notation. You would not be able to set using that notation.

document.cookie["foo"]; would get you the full Cookie object for "foo".

you would have to add to CookieJar: getter Cookie (USVString name);

patrickkettner commented 7 years ago

@arronei thinking about this a bit more after our chat, and the only way I would be comfortable with this would feel correct would be if I could do both

document.cookie["foo"] = "bar"

and

document.cookie["foo"].expirationDate = Date.now()
arronei commented 7 years ago

setter USVString (Cookie or USVString);

patrickkettner commented 7 years ago

This was fixed in cfad667