Closed Bug 389739 (flock9108) Opened 17 years ago Closed 12 years ago

XMLHttpRequest readyState does not define constants

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
minor

Tracking

()

RESOLVED DUPLICATE of bug 649133
mozilla6

People

(Reporter: mattwillis, Unassigned)

Details

Attachments

(1 file, 4 obsolete files)

The readyState integers for XMLHttpRequest are not defined as constants but are instead listed in a comment in the IDL.

This leads to code like this:

  this.req = CC[XMLHTTPREQUEST_CONTRACTID].
             createInstance(CI.nsIXMLHttpRequest);
  this.req.QueryInterface(CI.nsIJSXMLHttpRequest);
  this.req.open("GET", aUrl, true);
  var req = this.req;
  this.req.onreadystatechange = function (aEvt) {
    if (req.readyState == 4) {
      try {

We should move the values from the comments into constants for the readyStates.  This makes the code more readable and gets rid of some "magic numbers".
Attachment #274057 - Flags: review?(bzbarsky)
Alias: flock9018
Alias: flock9018 → flock9108
Status: NEW → ASSIGNED
How does this align with the W3C spec for this stuff?
In particular, I'd rather not introduce constants that would not interoperate with other UAs...
Good call.  They're named differently than the original comment in the idl.  I'll make a new patch using the W3C terms.

See http://www.w3.org/TR/XMLHttpRequest/#xmlhttprequest

Assignee: nobody → lilmatt
Attachment #274057 - Attachment is obsolete: true
Attachment #274075 - Flags: review?(bzbarsky)
Attachment #274057 - Flags: review?(bzbarsky)
Attached patch rev2 - Removes stupidity (obsolete) — Splinter Review
Shortens constant names since "XMLHTTPREQUEST" is included in CI.nsIXMLHttpRequest.

Also makes them unsigned shorts
Attachment #274075 - Attachment is obsolete: true
Attachment #274079 - Flags: review?(bzbarsky)
Attachment #274075 - Flags: review?(bzbarsky)
Attachment #274079 - Attachment is obsolete: true
Attachment #274082 - Flags: review?(bzbarsky)
Attachment #274079 - Flags: review?(bzbarsky)
Comment on attachment 274082 [details] [diff] [review]
rev3 - Use exact terms from spec per bz

Thanks!
Attachment #274082 - Flags: superreview+
Attachment #274082 - Flags: review?(bzbarsky)
Attachment #274082 - Flags: review+
Flags: in-testsuite?
Attachment #274082 - Attachment is obsolete: true
Attachment #274109 - Flags: review?(bzbarsky)
Comment on attachment 274109 [details] [diff] [review]
rev4 - Includes missing implementation

Isn't "short" PRUint16?  Check the generated header from this IDL?
Comment on attachment 274109 [details] [diff] [review]
rev4 - Includes missing implementation

Removing review request.  I will try again after I get sleep.
Attachment #274109 - Flags: review?(bzbarsky)
Please note that SENT has been renamed to HEADERS_RECEIVED in the editor's draft: http://dev.w3.org/cvsweb/~checkout~/2006/webapi/XMLHttpRequest/Overview.html?content-type=text/html;%20charset=utf-8
fantasai told me that OPEN clashed with open() because IDLs are not case-sensitive. I'm not really sure what a better name would be though. READY, maybe?
(In reply to comment #12)
Microsoft previously used "LOADING"
http://msdn2.microsoft.com/en-us/library/ms753800.aspx

however they appear to now follow the draft:
http://msdn2.microsoft.com/en-us/library/ms534361.aspx

Perhaps we could simply prepend "READYSTATE_" to the constants?  IMO doing so makes them more readable in code as it explicity indicates these are readyState values.
  (ex: "XMLHttpRequest::READYSTATE_OPEN" vs."XMLHttpRequest::OPEN")

I wouldn't trust Microsoft documentation. It is inaccurate. (Microsoft employees admitted as much which is part of the reason that SENT hsa been renamed to HEADERS_RECEIVED for instance.)

Prepending it with READYSTATE_ is not consistent with similar APIs (such as HTMLMediaElement from HTML 5 or various DOM features) so I would rather not do that. The names should be as concise and accurate as possible, imo.
Given that all the names except LOADING are past-tense, why not OPENED?
Cool, UNSENT, OPENED, HEADERS_RECEIVED, LOADING and DONE it is.
FWIW, the editor's draft mentioned in comment 11 has been updated to reflect this change.
Was fixed in bug 649133.
Assignee: mattwillis → nobody
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Component: XML → DOM: Mozilla Extensions
QA Contact: xml → general
Resolution: --- → DUPLICATE
Target Milestone: --- → mozilla6
Component: DOM: Mozilla Extensions → DOM
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: