Implement DOM Level 3 UserData API

RESOLVED FIXED

Status

()

Core
DOM: Core & HTML
RESOLVED FIXED
13 years ago
5 years ago

People

(Reporter: peterv, Assigned: peterv)

Tracking

({dev-doc-complete})

Trunk
dev-doc-complete
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 4 obsolete attachments)

(Assignee)

Description

13 years ago
 
(Assignee)

Updated

13 years ago
Depends on: 264309
(Assignee)

Comment 1

13 years ago
Created attachment 166151 [details] [diff] [review]
WIP

May still crash and leak.
(Assignee)

Comment 2

13 years ago
Created attachment 172568 [details] [diff] [review]
v1

This doesn't leak. Last remaining problem: we call the handler twice on
importNode (because it does a cloneNode internally). Not sure how to fix it
yet.
Attachment #166151 - Attachment is obsolete: true
(Assignee)

Comment 3

13 years ago
Created attachment 173906 [details] [diff] [review]
v2
Attachment #172568 - Attachment is obsolete: true
Attachment #173906 - Flags: review?(bugmail)
I'll try to start looking at this this weekend
(Assignee)

Updated

12 years ago
Depends on: 251025
(Assignee)

Comment 5

12 years ago
Created attachment 195743 [details] [diff] [review]
v2.1
Attachment #173906 - Attachment is obsolete: true
(Assignee)

Updated

12 years ago
Attachment #173906 - Flags: review?(bugmail)
(Assignee)

Updated

12 years ago
Attachment #195743 - Flags: superreview?(jst)
Attachment #195743 - Flags: review?(jst)

Comment 6

12 years ago
Comment on attachment 195743 [details] [diff] [review]
v2.1

> #define NS_IDOCUMENT_IID      \
>@@ -778,6 +780,39 @@ public:
>    */
>   virtual void NotifyURIVisitednessChanged(nsIURI* aURI) = 0;
> 
>+  nsresult SetUserData(const nsISupports *aObject, const nsAString &aKey,
>+                       nsIVariant *aData, nsIDOMUserDataHandler *aHandler,
>+                       nsIVariant **aResult)
>+  {
>+    nsCOMPtr<nsIAtom> key = do_GetAtom(aKey);
>+    if (!key) {
>+      return NS_ERROR_OUT_OF_MEMORY;
>+    }
>+
>+    return SetUserData(aObject, key, aData, aHandler, aResult);
>+  }
>+  virtual nsresult SetUserData(const nsISupports *aObject, nsIAtom *aKey,
>+                               nsIVariant *aData,
>+                               nsIDOMUserDataHandler *aHandler,
>+                               nsIVariant **aResult) = 0;
>+  nsresult GetUserData(nsISupports *aObject, const nsAString &aKey,
>+                       nsIVariant **aResult)
>+  {
>+    nsCOMPtr<nsIAtom> key = do_GetAtom(aKey);
>+    if (!key) {
>+      return NS_ERROR_OUT_OF_MEMORY;
>+    }
>+
>+    return GetUserData(aObject, key, aResult);
>+  }
>+  virtual nsresult GetUserData(const nsISupports *aObject, nsIAtom *aKey,
>+                               nsIVariant **aResult) = 0;
>+  virtual void CallUserDataHandler(PRUint16 aOperation,
>+                                   const nsISupports *aObject,
>+                                   nsIDOMNode *aSource, nsIDOMNode *aDest) = 0;
>+  virtual void TransferUserData(const nsISupports *aObject,
>+                                nsIDocument *aDestination) = 0;
>+

Could you add some documentation about these methods.
(In reply to comment #6)

> Could you add some documentation about these methods.

http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-getUserData
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-setUserData
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#UserDataHandler

Comment 8

12 years ago
(In reply to comment #7)
> (In reply to comment #6)
> 
> > Could you add some documentation about these methods.
> 
>
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-getUserData
>
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-setUserData
> http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#UserDataHandler
> 

Those links applies to the methods in
http://lxr.mozilla.org/seamonkey/source/dom/public/idl/core/nsIDOM3Node.idl#82
etc. But I'd like to see comments what the methods in nsIDocument are doing
(not nsIDOM3Document, not nsIDOM3Node, but nsIDocument) ;)
(Assignee)

Comment 9

12 years ago
Created attachment 199167 [details] [diff] [review]
v2.2
(Assignee)

Updated

12 years ago
Attachment #195743 - Attachment is obsolete: true
Attachment #199167 - Flags: superreview?(jst)
Attachment #199167 - Flags: review?(jst)
(Assignee)

Updated

12 years ago
Attachment #195743 - Flags: superreview?(jst)
Attachment #195743 - Flags: review?(jst)
Comment on attachment 199167 [details] [diff] [review]
v2.2

- In CallHandler() (in nsDocument.cpp):

+  nsresult rv = handlerData->mDocument->GetUserData(object, aKey,
+                                                    getter_AddRefs(data));
+  if (NS_SUCCEEDED(rv)) {
+    nsAutoString key;
+    aKey->ToString(key);
+    handler->Handle(handlerData->mOperation, key, data, handlerData->mSource,
+                    handlerData->mDest);

Shouldn't the condition for getting in here be if (data), or if (NS_SUCCEEDED(rv) && data)? Seems like GetUserData() always returns NS_OK, even if there is no data (as it IMO should)...

r+sr=jst
Attachment #199167 - Flags: superreview?(jst)
Attachment #199167 - Flags: superreview+
Attachment #199167 - Flags: review?(jst)
Attachment #199167 - Flags: review+
(Assignee)

Comment 11

12 years ago
(In reply to comment #10)
> (From update of attachment 199167 [details] [diff] [review] [edit])
> - In CallHandler() (in nsDocument.cpp):
> 
> +  nsresult rv = handlerData->mDocument->GetUserData(object, aKey,
> +                                                    getter_AddRefs(data));
> +  if (NS_SUCCEEDED(rv)) {
> +    nsAutoString key;
> +    aKey->ToString(key);
> +    handler->Handle(handlerData->mOperation, key, data, handlerData->mSource,
> +                    handlerData->mDest);
> 
> Shouldn't the condition for getting in here be if (data), or if
> (NS_SUCCEEDED(rv) && data)? Seems like GetUserData() always returns NS_OK, even
> if there is no data (as it IMO should)...

I made sure that we only set a handler if we've set data, so I added an assertion here instead.
I also changed the IIDs for nsIContent, nsIDocument and nsIDOMUserDataHandler.
Status: NEW → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → FIXED

Updated

12 years ago
Depends on: 314075

Comment 12

12 years ago
Caused a crash [@ nsPropertyTable::DeleteAllPropertiesFor] in bug 314075?
Depends on: 324871
I'd like to have tests written for this.  Examples of setUserData() and getUserData() are not easy to find, even on codesearch.google.com.  A search on lxr shows only glazou's composer code is using it, and he's not setting any UserDataHandler objects in his calls.
Flags: in-testsuite?
(Assignee)

Comment 14

11 years ago
There are at least some tests in the W3C DOM testsuite.

Updated

11 years ago
Keywords: dev-doc-needed
I'm not sure how or where to document these; there's very, very little information available about them.  Can someone point me in the direction of where to actually find those tests in the testsuite?  I don't happen to know where it is.
(Assignee)

Comment 16

10 years ago
http://dev.w3.org/cvsweb/2001/DOM-Test-Suite/tests/level3/core/ contains some of the raw tests (look for files that contain userdata). I personally don't have the html versions of the tests anymore and we haven't imported the DOM Level 3 Core tests into our testsuite yet. I'll see if I can generate just the UserData ones.

Some spec links:

http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-getUserData
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-setUserData
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#UserDataHandler
Yeah, I'm looking at that Java code now.  I guess I'll sit down and do some HTML/JS code myself for this.

Updated

9 years ago
Component: DOM: Core → DOM: Core & HTML
QA Contact: ian → general

Comment 18

8 years ago
FWIW:
https://developer.mozilla.org/en/DOM/Node.setUserData
https://developer.mozilla.org/en/DOM/Node.getUserData

Didn't proof-read those pages though.
The following pages are in a good shape with at least some little examples:
https://developer.mozilla.org/en/DOM/UserDataHandler
https://developer.mozilla.org/en/DOM/DOMUserData
https://developer.mozilla.org/en/DOM/Node.getUserData
https://developer.mozilla.org/en/DOM/Node.setUserData

Marking this as completed finally.
Keywords: dev-doc-needed → dev-doc-complete
Flags: in-testsuite?
You need to log in before you can comment on or make changes to this bug.