Bug 784893 - Rename the event's .socket attribute to .target; remove "on" prefix from event names. r=jonas
authorDonovan Preston <dpreston@mozilla.com>
Wed, 17 Oct 2012 22:29:58 -0400
changeset 110631 67f8d99d80fb6a29987b1e03f6bd0e4e451646a1
parent 110630 0d10847ab5481533d6055923ef3597147be7db82
child 110632 0883b53129b9f7767ec1f25304fd37163186f624
push id23704
push useremorley@mozilla.com
push dateThu, 18 Oct 2012 17:12:58 +0000
treeherdermozilla-central@3779eb3f036f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonas
bugs784893
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 784893 - Rename the event's .socket attribute to .target; remove "on" prefix from event names. r=jonas
dom/network/interfaces/nsIDOMTCPSocket.idl
dom/network/src/TCPSocket.js
dom/network/src/TCPSocketParentIntermediary.js
--- a/dom/network/interfaces/nsIDOMTCPSocket.idl
+++ b/dom/network/interfaces/nsIDOMTCPSocket.idl
@@ -205,26 +205,26 @@ interface nsITCPSocketInternal : nsISupp
  * and the data associated with the event (if any).
  */
 
 [scriptable, uuid(0f2abcca-b483-4539-a3e8-345707f75c44)]
 interface nsITCPSocketEvent : nsISupports {
   /**
    * The socket object which produced this event.
    */
-  readonly attribute nsIDOMTCPSocket socket;
+  readonly attribute nsIDOMTCPSocket target;
 
   /**
    * The type of this event. One of:
    *
-   * onopen
-   * onerror
-   * ondata
-   * ondrain
-   * onclose
+   * open
+   * error
+   * data
+   * drain
+   * close
    */
   readonly attribute DOMString type;
 
   /**
    * The data related to this event, if any. In the ondata callback,
    * data will be the bytes read from the network; if the binaryType
    * of the socket was "arraybuffer", this value will be of type Uint8Array;
    * otherwise, it will be a normal JavaScript string.
--- a/dom/network/src/TCPSocket.js
+++ b/dom/network/src/TCPSocket.js
@@ -44,31 +44,31 @@ function LOG(msg) {
 }
 
 /*
  * nsITCPSocketEvent object
  */
 
 function TCPSocketEvent(type, sock, data) {
   this._type = type;
-  this._socket = sock;
+  this._target = sock;
   this._data = data;
 }
 
 TCPSocketEvent.prototype = {
   __exposedProps__: {
     type: 'r',
-    socket: 'r',
+    target: 'r',
     data: 'r'
   },
   get type() {
     return this._type;
   },
-  get socket() {
-    return this._socket;
+  get target() {
+    return this._target;
   },
   get data() {
     return this._data;
   }
 }
 
 /*
  * nsIDOMTCPSocket object
@@ -228,43 +228,43 @@ TCPSocket.prototype = {
       onStopRequest: function ts_output_onStopRequest(request, context, status) {
         self._asyncCopierActive = false;
         self._multiplexStream.removeStream(0);
 
         if (status) {
           self._readyState = kCLOSED;
           let err = new Error("Connection closed while writing: " + status);
           err.status = status;
-          self.callListener("onerror", err);
-          self.callListener("onclose");
+          self.callListener("error", err);
+          self.callListener("close");
           return;
         }
 
         if (self._multiplexStream.count) {
           self._ensureCopying();
         } else {
           if (self._waitingForDrain) {
             self._waitingForDrain = false;
-            self.callListener("ondrain");
+            self.callListener("drain");
           }
           if (self._readyState === kCLOSING) {
             self._socketOutputStream.close();
             self._readyState = kCLOSED;
-            self.callListener("onclose");
+            self.callListener("close");
           }
         }
       }
     }, null);
   },
 
   callListener: function ts_callListener(type, data) {
-    if (!this[type])
+    if (!this["on" + type])
       return;
 
-    this[type].call(null, new TCPSocketEvent(type, this, data || ""));
+    this["on" + type].call(null, new TCPSocketEvent(type, this, data || ""));
   },
 
   /* nsITCPSocketInternal methods */
   callListenerError: function ts_callListenerError(type, message, filename,
                                                    lineNumber, columnNumber) {
     this.callListener(type, new Error(message, filename, lineNumber, columnNumber));
   },
 
@@ -514,17 +514,17 @@ TCPSocket.prototype = {
     }
   },
 
   // nsITransportEventSink (Triggered by transport.setEventSink)
   onTransportStatus: function ts_onTransportStatus(
     transport, status, progress, max) {
     if (status === Ci.nsISocketTransport.STATUS_CONNECTED_TO) {
       this._readyState = kOPEN;
-      this.callListener("onopen");
+      this.callListener("open");
 
       this._inputStreamPump = new InputStreamPump(
         this._socketInputStream, -1, -1, 0, 0, false
       );
 
       while (this._suspendCount--) {
         this._inputStreamPump.suspend();
       }
@@ -534,17 +534,17 @@ TCPSocket.prototype = {
   },
 
   // nsIAsyncInputStream (Triggered by _socketInputStream.asyncWait)
   // Only used for detecting connection refused
   onInputStreamReady: function ts_onInputStreamReady(input) {
     try {
       input.available();
     } catch (e) {
-      this.callListener("onerror", new Error("Connection refused"));
+      this.callListener("error", new Error("Connection refused"));
     }
   },
 
   // nsIRequestObserver (Triggered by _inputStreamPump.asyncRead)
   onStartRequest: function ts_onStartRequest(request, context) {
   },
 
   // nsIRequestObserver (Triggered by _inputStreamPump.asyncRead)
@@ -562,31 +562,31 @@ TCPSocket.prototype = {
       return;
     }
 
     this._readyState = kCLOSED;
 
     if (status) {
       let err = new Error("Connection closed: " + status);
       err.status = status;
-      this.callListener("onerror", err);
+      this.callListener("error", err);
     }
 
-    this.callListener("onclose");
+    this.callListener("close");
   },
 
   // nsIStreamListener (Triggered by _inputStreamPump.asyncRead)
   onDataAvailable: function ts_onDataAvailable(request, context, inputStream, offset, count) {
     if (this._binaryType === "arraybuffer") {
       let ua = this.useWin ? new this.useWin.Uint8Array(count)
                            : new Uint8Array(count);
       ua.set(this._inputStreamBinary.readByteArray(count));
-      this.callListener("ondata", ua);
+      this.callListener("data", ua);
     } else {
-      this.callListener("ondata", this._inputStreamScriptable.read(count));
+      this.callListener("data", this._inputStreamScriptable.read(count));
     }
   },
 
   classID: Components.ID("{cda91b22-6472-11e1-aa11-834fec09cd0a}"),
 
   classInfo: XPCOMUtils.generateCI({
     classID: Components.ID("{cda91b22-6472-11e1-aa11-834fec09cd0a}"),
     contractID: "@mozilla.org/tcp-socket;1",
@@ -612,17 +612,17 @@ TCPSocket.prototype = {
 
 function SecurityCallbacks(socket) {
   this._socket = socket;
 }
 
 SecurityCallbacks.prototype = {
   notifyCertProblem: function sc_notifyCertProblem(socketInfo, status,
                                                    targetSite) {
-    this._socket.callListener("onerror", status);
+    this._socket.callListener("error", status);
     this._socket.close();
     return true;
   },
 
   getInterface: function sc_getInterface(iid) {
     return this.QueryInterface(iid);
   },
 
--- a/dom/network/src/TCPSocketParentIntermediary.js
+++ b/dom/network/src/TCPSocketParentIntermediary.js
@@ -21,19 +21,19 @@ TCPSocketParentIntermediary.prototype = 
     let socket = this._socket = baseSocket.open(aHost, aPort,
                                                 {useSSL: aUseSSL,
                                                 binaryType: aBinaryType});
     if (!socket)
       return null;
 
     // Create handlers for every possible callback that attempt to trigger
     // corresponding callbacks on the child object.
-    ["onopen", "ondrain", "ondata", "onerror", "onclose"].forEach(
+    ["open", "drain", "data", "error", "close"].forEach(
       function(p) {
-        socket[p] = function(data) {
+        socket["on" + p] = function(data) {
           aParentSide.sendCallback(p, data.data, socket.readyState,
                                    socket.bufferedAmount);
         };
       }
     );
 
     return socket;
   },