Bug 912442 - Part 4: move buf specific contants into Buf itself. r=allstars.chh
authorVicamo Yang <vyang@mozilla.com>
Sat, 14 Sep 2013 00:12:25 +0200
changeset 160077 dac3d1df51cfaa87a8186073742f34229484639f
parent 160076 d30b98249891db40f667fc9c39b87c41052363fa
child 160078 e026125d26387223cca1acd75cf11366cc3b5a55
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersallstars
bugs912442
milestone26.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 912442 - Part 4: move buf specific contants into Buf itself. r=allstars.chh
dom/system/gonk/ril_worker.js
dom/system/gonk/tests/test_ril_worker_buf.js
dom/system/gonk/worker_buf.js
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -48,23 +48,16 @@ let GLOBAL = this;
 
 if (!this.debug) {
   // Debugging stub that goes nowhere.
   this.debug = function debug(message) {
     dump("RIL Worker[" + CLIENT_ID + "]: " + message + "\n");
   };
 }
 
-const INT32_MAX   = 2147483647;
-const UINT8_SIZE  = 1;
-const UINT16_SIZE = 2;
-const UINT32_SIZE = 4;
-
-const PDU_HEX_OCTET_SIZE = 4;
-
 const DEFAULT_EMERGENCY_NUMBERS = ["112", "911"];
 
 // Timeout value for emergency callback mode.
 const EMERGENCY_CB_MODE_TIMEOUT_MS = 300000;  // 5 mins = 300000 ms.
 
 const ICC_MAX_LINEAR_FIXED_RECORDS = 0xfe;
 
 // MMI match groups
@@ -3971,17 +3964,17 @@ let RIL = {
     let options = {
       pid: message.pid,
       dcs: message.dcs,
       encoding: message.encoding,
     };
     Buf.newParcel(REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, options);
 
     Buf.seekIncoming(-1 * (Buf.getCurrentParcelSize() - Buf.getReadAvailable()
-                           - 2 * UINT32_SIZE)); // Skip response_type & request_type.
+                           - 2 * Buf.UINT32_SIZE)); // Skip response_type & request_type.
     let messageStringLength = Buf.readUint32(); // In semi-octets
     let smscLength = GsmPDUHelper.readHexOctet(); // In octets, inclusive of TOA
     let tpduLength = (messageStringLength / 2) - (smscLength + 1); // In octets
 
     // Device identities: 4 bytes
     // Address: 0 or (2 + smscLength)
     // SMS TPDU: (2 or 3) + tpduLength
     let berLen = 4 +
@@ -4004,27 +3997,27 @@ let RIL = {
     GsmPDUHelper.writeHexOctet(0x02);
     GsmPDUHelper.writeHexOctet(STK_DEVICE_ID_NETWORK);
     GsmPDUHelper.writeHexOctet(STK_DEVICE_ID_SIM);
 
     // Address-TLV
     if (smscLength) {
       GsmPDUHelper.writeHexOctet(COMPREHENSIONTLV_TAG_ADDRESS);
       GsmPDUHelper.writeHexOctet(smscLength);
-      Buf.copyIncomingToOutgoing(PDU_HEX_OCTET_SIZE * smscLength);
+      Buf.copyIncomingToOutgoing(Buf.PDU_HEX_OCTET_SIZE * smscLength);
     }
 
     // SMS TPDU-TLV
     GsmPDUHelper.writeHexOctet(COMPREHENSIONTLV_TAG_SMS_TPDU |
                                COMPREHENSIONTLV_FLAG_CR);
     if (tpduLength > 127) {
       GsmPDUHelper.writeHexOctet(0x81);
     }
     GsmPDUHelper.writeHexOctet(tpduLength);
-    Buf.copyIncomingToOutgoing(PDU_HEX_OCTET_SIZE * tpduLength);
+    Buf.copyIncomingToOutgoing(Buf.PDU_HEX_OCTET_SIZE * tpduLength);
 
     // Write 2 string delimitors for the total string length must be even.
     Buf.writeStringDelimiter(0);
 
     Buf.sendParcel();
   },
 
   /**
@@ -4063,61 +4056,61 @@ let RIL = {
     GsmPDUHelper.writeHexOctet(options.dcs);
     // 6. TP-UDL
     if (options.encoding == PDU_DCS_MSG_CODING_7BITS_ALPHABET) {
       GsmPDUHelper.writeHexOctet(Math.floor(responsePduLen * 8 / 7));
     } else {
       GsmPDUHelper.writeHexOctet(responsePduLen);
     }
     // TP-UD
-    Buf.copyIncomingToOutgoing(PDU_HEX_OCTET_SIZE * responsePduLen);
+    Buf.copyIncomingToOutgoing(Buf.PDU_HEX_OCTET_SIZE * responsePduLen);
     // Write 2 string delimitors for the total string length must be even.
     Buf.writeStringDelimiter(0);
 
     Buf.sendParcel();
   },
 
   /**
    * @param message A decoded SMS-DELIVER message.
    */
   writeSmsToSIM: function writeSmsToSIM(message) {
     Buf.newParcel(REQUEST_WRITE_SMS_TO_SIM);
 
     // Write EFsms Status
     Buf.writeUint32(EFSMS_STATUS_FREE);
 
     Buf.seekIncoming(-1 * (Buf.getCurrentParcelSize() - Buf.getReadAvailable()
-                           - 2 * UINT32_SIZE)); // Skip response_type & request_type.
+                           - 2 * Buf.UINT32_SIZE)); // Skip response_type & request_type.
     let messageStringLength = Buf.readUint32(); // In semi-octets
     let smscLength = GsmPDUHelper.readHexOctet(); // In octets, inclusive of TOA
     let pduLength = (messageStringLength / 2) - (smscLength + 1); // In octets
 
     // 1. Write PDU first.
     if (smscLength > 0) {
-      Buf.seekIncoming(smscLength * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming(smscLength * Buf.PDU_HEX_OCTET_SIZE);
     }
     // Write EFsms PDU string length
     Buf.writeUint32(2 * pduLength); // In semi-octets
     if (pduLength) {
-      Buf.copyIncomingToOutgoing(PDU_HEX_OCTET_SIZE * pduLength);
+      Buf.copyIncomingToOutgoing(Buf.PDU_HEX_OCTET_SIZE * pduLength);
     }
     // Write 2 string delimitors for the total string length must be even.
     Buf.writeStringDelimiter(0);
 
     // 2. Write SMSC
     // Write EFsms SMSC string length
     Buf.writeUint32(2 * (smscLength + 1)); // Plus smscLength itself, in semi-octets
     // Write smscLength
     GsmPDUHelper.writeHexOctet(smscLength);
     // Write TOA & SMSC Address
     if (smscLength) {
       Buf.seekIncoming(-1 * (Buf.getCurrentParcelSize() - Buf.getReadAvailable()
-                             - 2 * UINT32_SIZE // Skip response_type, request_type.
-                             - 2 * PDU_HEX_OCTET_SIZE)); // Skip messageStringLength & smscLength.
-      Buf.copyIncomingToOutgoing(PDU_HEX_OCTET_SIZE * smscLength);
+                             - 2 * Buf.UINT32_SIZE // Skip response_type, request_type.
+                             - 2 * Buf.PDU_HEX_OCTET_SIZE)); // Skip messageStringLength & smscLength.
+      Buf.copyIncomingToOutgoing(Buf.PDU_HEX_OCTET_SIZE * smscLength);
     }
     // Write 2 string delimitors for the total string length must be even.
     Buf.writeStringDelimiter(0);
 
     Buf.sendParcel();
   },
 
   /**
@@ -6578,17 +6571,17 @@ let GsmPDUHelper = {
         }
       } else if (octet == PDU_NL_EXTENDED_ESCAPE) {
         escapeFound = true;
       } else {
         ret += langTable[octet];
       }
     }
 
-    Buf.seekIncoming((numOctets - i) * PDU_HEX_OCTET_SIZE);
+    Buf.seekIncoming((numOctets - i) * Buf.PDU_HEX_OCTET_SIZE);
     return ret;
   },
 
   /**
    * Write GSM 8-bit unpacked octets.
    *
    * @param numOctets   Number of total octets to be writen, including trailing
    *                    0xff.
@@ -6690,17 +6683,17 @@ let GsmPDUHelper = {
           if (code == 0xffff) {
             i += 2;
             break;
           }
           str += String.fromCharCode(code);
         }
 
         // Skip trailing 0xff
-        Buf.seekIncoming((numOctets - i) * PDU_HEX_OCTET_SIZE);
+        Buf.seekIncoming((numOctets - i) * Buf.PDU_HEX_OCTET_SIZE);
         break;
       case 0x81: // Fall through
       case 0x82:
         /**
          * +------+-----+--------+-----+-----+-----+--------+------+
          * | 0x81 | len | offset | Ch1 | Ch2 | ... | Ch_len | 0xff |
          * +------+-----+--------+-----+-----+-----+--------+------+
          *
@@ -6744,24 +6737,24 @@ let GsmPDUHelper = {
               count++;
               if (this.readHexOctet() & 0x80) {
                 gotUCS2 = 1;
                 break;
               }
             }
             // Unread.
             // +1 for the GSM alphabet indexed at i,
-            Buf.seekIncoming(-1 * (count + 1) * PDU_HEX_OCTET_SIZE);
+            Buf.seekIncoming(-1 * (count + 1) * Buf.PDU_HEX_OCTET_SIZE);
             str += this.read8BitUnpackedToString(count + 1 - gotUCS2);
             i += count - gotUCS2;
           }
         }
 
         // Skipping trailing 0xff
-        Buf.seekIncoming((numOctets - len - headerLen) * PDU_HEX_OCTET_SIZE);
+        Buf.seekIncoming((numOctets - len - headerLen) * Buf.PDU_HEX_OCTET_SIZE);
         break;
     }
     return str;
   },
 
   /**
    * Read 1 + UDHL octets and construct user data header.
    *
@@ -7021,17 +7014,17 @@ let GsmPDUHelper = {
     let length = Buf.readUint32();
 
     let alphaLen = recordSize - ADN_FOOTER_SIZE_BYTES;
     let alphaId = this.readAlphaIdentifier(alphaLen);
 
     let number = this.readNumberWithLength();
 
     // Skip 2 unused octets, CCP and EXT1.
-    Buf.seekIncoming(2 * PDU_HEX_OCTET_SIZE);
+    Buf.seekIncoming(2 * Buf.PDU_HEX_OCTET_SIZE);
     Buf.readStringDelimiter(length);
 
     let contact = null;
     if (alphaId || number) {
       contact = {alphaId: alphaId,
                  number: number};
     }
     return contact;
@@ -7083,17 +7076,17 @@ let GsmPDUHelper = {
     let temp;
     // Read the 1st octet to determine the encoding.
     if ((temp = GsmPDUHelper.readHexOctet()) == 0x80 ||
          temp == 0x81 ||
          temp == 0x82) {
       numOctets--;
       return this.readICCUCS2String(temp, numOctets);
     } else {
-      Buf.seekIncoming(-1 * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming(-1 * Buf.PDU_HEX_OCTET_SIZE);
       return this.read8BitUnpackedToString(numOctets);
     }
   },
 
   /**
    * Write Alpha Identifier.
    *
    * @param numOctets
@@ -7187,19 +7180,19 @@ let GsmPDUHelper = {
     let number;
     let numLen = this.readHexOctet();
     if (numLen != 0xff) {
       if (numLen > ADN_MAX_BCD_NUMBER_BYTES) {
         throw new Error("invalid length of BCD number/SSC contents - " + numLen);
       }
 
       number = this.readDiallingNumber(numLen);
-      Buf.seekIncoming((ADN_MAX_BCD_NUMBER_BYTES - numLen) * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming((ADN_MAX_BCD_NUMBER_BYTES - numLen) * Buf.PDU_HEX_OCTET_SIZE);
     } else {
-      Buf.seekIncoming(ADN_MAX_BCD_NUMBER_BYTES * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming(ADN_MAX_BCD_NUMBER_BYTES * Buf.PDU_HEX_OCTET_SIZE);
     }
 
     return number;
   },
 
   writeNumberWithLength: function writeNumberWithLength(number) {
     if (number) {
       let numStart = number[0] == "+" ? 1 : 0;
@@ -9855,17 +9848,17 @@ StkCommandParamsFactory[STK_CMD_TIMER_MA
 
 let StkProactiveCmdHelper = {
   retrieve: function retrieve(tag, length) {
     let method = StkProactiveCmdHelper[tag];
     if (typeof method != "function") {
       if (DEBUG) {
         debug("Unknown comprehension tag " + tag.toString(16));
       }
-      Buf.seekIncoming(length * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming(length * Buf.PDU_HEX_OCTET_SIZE);
       return null;
     }
     return method.call(this, length);
   },
 
   /**
    * Command Details.
    *
@@ -10821,17 +10814,17 @@ let ICCIOHelper = {
    * Process a ICC_COMMAND_GET_RESPONSE type command for REQUEST_SIM_IO.
    */
   processICCIOGetResponse: function processICCIOGetResponse(options) {
     let strLen = Buf.readUint32();
 
     // The format is from TS 51.011, clause 9.2.1
 
     // Skip RFU, data[0] data[1]
-    Buf.seekIncoming(2 * PDU_HEX_OCTET_SIZE);
+    Buf.seekIncoming(2 * Buf.PDU_HEX_OCTET_SIZE);
 
     // File size, data[2], data[3]
     options.fileSize = (GsmPDUHelper.readHexOctet() << 8) |
                         GsmPDUHelper.readHexOctet();
 
     // 2 bytes File id. data[4], data[5]
     let fileId = (GsmPDUHelper.readHexOctet() << 8) |
                   GsmPDUHelper.readHexOctet();
@@ -10846,31 +10839,31 @@ let ICCIOHelper = {
       throw new Error("Unexpected file type " + fileType);
     }
 
     // Skip 1 byte RFU, data[7],
     //      3 bytes Access conditions, data[8] data[9] data[10],
     //      1 byte File status, data[11],
     //      1 byte Length of the following data, data[12].
     Buf.seekIncoming(((RESPONSE_DATA_STRUCTURE - RESPONSE_DATA_FILE_TYPE - 1) *
-        PDU_HEX_OCTET_SIZE));
+        Buf.PDU_HEX_OCTET_SIZE));
 
     // Read Structure of EF, data[13]
     let efType = GsmPDUHelper.readHexOctet();
     if (efType != options.type) {
       throw new Error("Expected EF type " + options.type + " but read " + efType);
     }
 
     // Length of a record, data[14].
     // Only available for LINEAR_FIXED and CYCLIC.
     if (efType == EF_TYPE_LINEAR_FIXED || efType == EF_TYPE_CYCLIC) {
       options.recordSize = GsmPDUHelper.readHexOctet();
       options.totalRecords = options.fileSize / options.recordSize;
     } else {
-      Buf.seekIncoming(1 * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming(1 * Buf.PDU_HEX_OCTET_SIZE);
     }
 
     Buf.readStringDelimiter(strLen);
 
     if (options.callback) {
       options.callback(options);
     }
   },
@@ -11253,17 +11246,17 @@ let ICCRecordHelper = {
       let strLen = Buf.readUint32();
       let octetLen = strLen / 2, readLen = 0;
 
       let pbrTlvs = [];
       while (readLen < octetLen) {
         let tag = GsmPDUHelper.readHexOctet();
         if (tag == 0xff) {
           readLen++;
-          Buf.seekIncoming((octetLen - readLen) * PDU_HEX_OCTET_SIZE);
+          Buf.seekIncoming((octetLen - readLen) * Buf.PDU_HEX_OCTET_SIZE);
           break;
         }
 
         let tlvLen = GsmPDUHelper.readHexOctet();
         let tlvs = ICCUtilsHelper.decodeSimTlvs(tlvLen);
         pbrTlvs.push({tag: tag,
                       length: tlvLen,
                       value: tlvs});
@@ -11397,17 +11390,17 @@ let ICCRecordHelper = {
       // Note: The fields marked as C above are mandatort if the file
       //       is not type 1 (as specified in EF_PBR)
       if (fileType == ICC_USIM_TYPE1_TAG) {
         email = GsmPDUHelper.read8BitUnpackedToString(octetLen);
       } else {
         email = GsmPDUHelper.read8BitUnpackedToString(octetLen - 2);
 
         // Consumes the remaining buffer
-        Buf.seekIncoming(2 * PDU_HEX_OCTET_SIZE); // For ADN SFI and Record Identifier
+        Buf.seekIncoming(2 * Buf.PDU_HEX_OCTET_SIZE); // For ADN SFI and Record Identifier
       }
 
       Buf.readStringDelimiter(strLen);
 
       if (onsuccess) {
         onsuccess(email);
       }
     }
@@ -11475,27 +11468,27 @@ let ICCRecordHelper = {
    */
   readANR: function readANR(fileId, fileType, recordNumber, onsuccess, onerror) {
     function callback(options) {
       let strLen = Buf.readUint32();
       let number = null;
       this._anrRecordSize = options.recordSize;
 
       // Skip EF_AAS Record ID.
-      Buf.seekIncoming(1 * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming(1 * Buf.PDU_HEX_OCTET_SIZE);
 
       number = GsmPDUHelper.readNumberWithLength();
 
       // Skip 2 unused octets, CCP and EXT1.
-      Buf.seekIncoming(2 * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming(2 * Buf.PDU_HEX_OCTET_SIZE);
 
       // For Type 2 there are two extra octets.
       if (fileType == ICC_USIM_TYPE2_TAG) {
         // Skip 2 unused octets, ADN SFI and Record Identifier.
-        Buf.seekIncoming(2 * PDU_HEX_OCTET_SIZE);
+        Buf.seekIncoming(2 * Buf.PDU_HEX_OCTET_SIZE);
       }
 
       Buf.readStringDelimiter(strLen);
 
       if (onsuccess) {
         onsuccess(number);
       }
     }
@@ -11582,17 +11575,17 @@ let ICCRecordHelper = {
           // We don't care about its content if its tag is not SPDI nor
           // PLMN_LIST.
           endLoop = true;
           break;
         }
       }
 
       // Consume unread octets.
-      Buf.seekIncoming((octetLen - readLen) * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming((octetLen - readLen) * Buf.PDU_HEX_OCTET_SIZE);
       Buf.readStringDelimiter(strLen);
 
       if (DEBUG) debug("SPDI: " + JSON.stringify(RIL.iccInfoPrivate.SPDI));
       if (ICCUtilsHelper.updateDisplayCondition()) {
         ICCUtilsHelper.handleICCInfoChange();
       }
     }
 
@@ -11758,17 +11751,17 @@ let ICCRecordHelper = {
           (GsmPDUHelper.readHexOctet() << 8) | GsmPDUHelper.readHexOctet();
         // PLMN Network Name Record Identifier
         oplElement.pnnRecordId = GsmPDUHelper.readHexOctet();
         if (DEBUG) {
           debug("OPL: [" + (opl.length + 1) + "]: " + JSON.stringify(oplElement));
         }
         opl.push(oplElement);
       } else {
-        Buf.seekIncoming(5 * PDU_HEX_OCTET_SIZE);
+        Buf.seekIncoming(5 * Buf.PDU_HEX_OCTET_SIZE);
       }
       Buf.readStringDelimiter(strLen);
 
       if (options.p1 < options.totalRecords) {
         ICCIOHelper.loadNextRecord(options);
       } else {
         RIL.iccInfoPrivate.OPL = opl;
       }
@@ -11792,34 +11785,34 @@ let ICCRecordHelper = {
       let readLen = 0;
 
       while (readLen < octetLen) {
         let tlvTag = GsmPDUHelper.readHexOctet();
 
         if (tlvTag == 0xFF) {
           // Unused byte
           readLen++;
-          Buf.seekIncoming((octetLen - readLen) * PDU_HEX_OCTET_SIZE);
+          Buf.seekIncoming((octetLen - readLen) * Buf.PDU_HEX_OCTET_SIZE);
           break;
         }
 
         // Needs this check to avoid initializing twice.
         pnnElement = pnnElement || {};
 
         let tlvLen = GsmPDUHelper.readHexOctet();
 
         switch (tlvTag) {
           case PNN_IEI_FULL_NETWORK_NAME:
             pnnElement.fullName = GsmPDUHelper.readNetworkName(tlvLen);
             break;
           case PNN_IEI_SHORT_NETWORK_NAME:
             pnnElement.shortName = GsmPDUHelper.readNetworkName(tlvLen);
             break;
           default:
-            Buf.seekIncoming(tlvLen * PDU_HEX_OCTET_SIZE);
+            Buf.seekIncoming(tlvLen * Buf.PDU_HEX_OCTET_SIZE);
             break;
         }
 
         readLen += (tlvLen + 2); // +2 for tlvTag and tlvLen
       }
       Buf.readStringDelimiter(strLen);
 
       if (pnnElement) {
@@ -11867,17 +11860,17 @@ let ICCRecordHelper = {
 
       if (readLen == octetLen) {
         // Find free record.
         if (onsuccess) {
           onsuccess(options.p1);
         }
         return;
       } else {
-        Buf.seekIncoming((octetLen - readLen) * PDU_HEX_OCTET_SIZE);
+        Buf.seekIncoming((octetLen - readLen) * Buf.PDU_HEX_OCTET_SIZE);
       }
 
       Buf.readStringDelimiter(strLen);
 
       if (options.p1 < options.totalRecords) {
         ICCIOHelper.loadNextRecord(options);
       } else {
         // No free record found.
@@ -12920,17 +12913,17 @@ let RuimRecordHelper = {
     function callback(options) {
       let strLen = Buf.readUint32();
       let tempOctet = GsmPDUHelper.readHexOctet();
       cdmaHomeSystemId.push(((GsmPDUHelper.readHexOctet() & 0x7f) << 8) | tempOctet);
       tempOctet = GsmPDUHelper.readHexOctet();
       cdmaHomeNetworkId.push(((GsmPDUHelper.readHexOctet() & 0xff) << 8) | tempOctet);
 
       // Consuming the last octet: band class.
-      Buf.seekIncoming(PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming(Buf.PDU_HEX_OCTET_SIZE);
 
       Buf.readStringDelimiter(strLen);
       if (options.p1 < options.totalRecords) {
         ICCIOHelper.loadNextRecord(options);
       } else {
         if (DEBUG) {
           debug("CDMAHome system id: " + JSON.stringify(cdmaHomeSystemId));
           debug("CDMAHome network id: " + JSON.stringify(cdmaHomeNetworkId));
@@ -12977,17 +12970,17 @@ let RuimRecordHelper = {
 
   readSPN: function readSPN() {
     function callback() {
       let strLen = Buf.readUint32();
       let octetLen = strLen / 2;
       let displayCondition = GsmPDUHelper.readHexOctet();
       let codingScheme = GsmPDUHelper.readHexOctet();
       // Skip one octet: language indicator.
-      Buf.seekIncoming(PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming(Buf.PDU_HEX_OCTET_SIZE);
       let readLen = 3;
 
       // SPN String ends up with 0xff.
       let userDataBuffer = [];
 
       while (readLen < octetLen) {
         let octet = GsmPDUHelper.readHexOctet();
         readLen++;
@@ -13013,17 +13006,17 @@ let RuimRecordHelper = {
       }
 
       RIL.iccInfo.spn = CdmaPDUHelper.decodeCdmaPDUMsg(codingScheme, null, msgLen);
       if (DEBUG) {
         debug("CDMA SPN: " + RIL.iccInfo.spn +
               ", Display condition: " + displayCondition);
       }
       RIL.iccInfoPrivate.spnDisplayCondition = displayCondition;
-      Buf.seekIncoming((octetLen - readLen) * PDU_HEX_OCTET_SIZE);
+      Buf.seekIncoming((octetLen - readLen) * Buf.PDU_HEX_OCTET_SIZE);
       Buf.readStringDelimiter(strLen);
     }
 
     ICCIOHelper.loadTransparentEF({fileId: ICC_EF_CSIM_SPN,
                                    callback: callback.bind(this)});
   }
 };
 
--- a/dom/system/gonk/tests/test_ril_worker_buf.js
+++ b/dom/system/gonk/tests/test_ril_worker_buf.js
@@ -28,17 +28,17 @@ function add_test_incoming_parcel(parcel
       parcel = newIncomingParcel(-1,
                                  worker.RESPONSE_TYPE_UNSOLICITED,
                                  worker.REQUEST_VOICE_REGISTRATION_STATE,
                                  [0, 0, 0, 0]);
     }
 
     // supports only requests less or equal than UINT8_MAX(255).
     let buf = worker.Buf;
-    let request = parcel[buf.PARCEL_SIZE_SIZE + worker.UINT32_SIZE];
+    let request = parcel[buf.PARCEL_SIZE_SIZE + buf.UINT32_SIZE];
     worker.RIL[request] = function ril_request_handler() {
       handler(worker);
       worker.postMessage();
     };
 
     worker.onRILMessage(parcel);
 
     // end of incoming parcel's trip, let's do next test.
--- a/dom/system/gonk/worker_buf.js
+++ b/dom/system/gonk/worker_buf.js
@@ -1,32 +1,33 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-const INT32_MAX   = 2147483647;
-const UINT8_SIZE  = 1;
-const UINT16_SIZE = 2;
-const UINT32_SIZE = 4;
 
 /**
  * This object contains helpers buffering incoming data & deconstructing it
  * into parcels as well as buffering outgoing data & constructing parcels.
  * For that it maintains two buffers and corresponding uint8 views, indexes.
  *
  * The incoming buffer is a circular buffer where we store incoming data.
  * As soon as a complete parcel is received, it is processed right away, so
  * the buffer only needs to be large enough to hold one parcel.
  *
  * The outgoing buffer is to prepare outgoing parcels. The index is reset
  * every time a parcel is sent.
  */
 
 let Buf = {
-  PARCEL_SIZE_SIZE: UINT32_SIZE,
+  INT32_MAX: 2147483647,
+  UINT8_SIZE: 1,
+  UINT16_SIZE: 2,
+  UINT32_SIZE: 4,
+  PARCEL_SIZE_SIZE: 4,
+  PDU_HEX_OCTET_SIZE: 4,
 
   incomingBufferLength: 1024,
   incomingBuffer: null,
   incomingBytes: null,
   incomingWriteIndex: 0,
   incomingReadIndex: 0,
   readIncoming: 0,
   readAvailable: 0,
@@ -272,17 +273,17 @@ let Buf = {
     for (let i = 0; i < length; i++) {
       ints.push(this.readUint32());
     }
     return ints;
   },
 
   readString: function readString() {
     let string_len = this.readUint32();
-    if (string_len < 0 || string_len >= INT32_MAX) {
+    if (string_len < 0 || string_len >= this.INT32_MAX) {
       return null;
     }
     let s = "";
     for (let i = 0; i < string_len; i++) {
       s += String.fromCharCode(this.readUint16());
     }
     // Strings are \0\0 delimited, but that isn't part of the length. And
     // if the string length is even, the delimiter is two characters wide.