Bug 701735 - xpc_qsJsvalToWcharStr shouldn't const_cast; r=bz
authorMs2ger <ms2ger@gmail.com>
Wed, 16 Nov 2011 08:50:18 +0100
changeset 81932 f5beb767294529015f4ecc8aa8d3091ae35d6882
parent 81931 086dea3f0bad7b61eaee5a476b86b05202aea115
child 81933 178a3e2dc3f00c078dfbdaaa70291287577ac0ba
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs701735
milestone11.0a1
Bug 701735 - xpc_qsJsvalToWcharStr shouldn't const_cast; r=bz
js/xpconnect/src/XPCQuickStubs.cpp
js/xpconnect/src/XPCQuickStubs.h
js/xpconnect/src/codegen.py
js/xpconnect/src/qsgen.py
--- a/js/xpconnect/src/XPCQuickStubs.cpp
+++ b/js/xpconnect/src/XPCQuickStubs.cpp
@@ -1,11 +1,10 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
@@ -996,17 +995,17 @@ xpc_qsJsvalToCharStr(JSContext *cx, jsva
     } else {
         if (!(str = JS_ValueToString(cx, v)))
             return false;
     }
     return !!bytes->encode(cx, str);
 }
 
 JSBool
-xpc_qsJsvalToWcharStr(JSContext *cx, jsval v, jsval *pval, PRUnichar **pstr)
+xpc_qsJsvalToWcharStr(JSContext *cx, jsval v, jsval *pval, const PRUnichar **pstr)
 {
     JSString *str;
 
     if (JSVAL_IS_STRING(v)) {
         str = JSVAL_TO_STRING(v);
     } else if (JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v)) {
         *pstr = NULL;
         return JS_TRUE;
@@ -1015,18 +1014,17 @@ xpc_qsJsvalToWcharStr(JSContext *cx, jsv
             return JS_FALSE;
         *pval = STRING_TO_JSVAL(str);  // Root the new string.
     }
 
     const jschar *chars = JS_GetStringCharsZ(cx, str);
     if (!chars)
         return JS_FALSE;
 
-    // XXXbz this is casting away constness too...  That seems like a bad idea.
-    *pstr = const_cast<jschar *>(chars);
+    *pstr = static_cast<const PRUnichar *>(chars);
     return JS_TRUE;
 }
 
 JSBool
 xpc_qsStringToJsval(JSContext *cx, nsString &str, jsval *rval)
 {
     // From the T_DOMSTRING case in XPCConvert::NativeData2JS.
     if (str.IsVoid()) {
--- a/js/xpconnect/src/XPCQuickStubs.h
+++ b/js/xpconnect/src/XPCQuickStubs.h
@@ -462,17 +462,17 @@ struct xpc_qsSelfRef
  * @param bytes
  *     Out. On success it receives the converted string unless v is null or
  *     undefinedin which case bytes->ptr() remains null.
  */
 JSBool
 xpc_qsJsvalToCharStr(JSContext *cx, jsval v, JSAutoByteString *bytes);
 
 JSBool
-xpc_qsJsvalToWcharStr(JSContext *cx, jsval v, jsval *pval, PRUnichar **pstr);
+xpc_qsJsvalToWcharStr(JSContext *cx, jsval v, jsval *pval, const PRUnichar **pstr);
 
 
 /** Convert an nsString to jsval, returning JS_TRUE on success.
  *  Note, the ownership of the string buffer may be moved from str to rval.
  *  If that happens, str will point to an empty string after this call.
  */
 JSBool
 xpc_qsStringToJsval(JSContext *cx, nsString &str, jsval *rval);
--- a/js/xpconnect/src/codegen.py
+++ b/js/xpconnect/src/codegen.py
@@ -165,17 +165,17 @@ argumentUnboxingTemplates = {
 
     'string':
         "    JSAutoByteString ${name}_bytes;\n"
         "    if (!xpc_qsJsvalToCharStr(cx, ${argVal}, &${name}_bytes))\n"
         "        return JS_FALSE;\n"
         "    char *${name} = ${name}_bytes.ptr();\n",
 
     'wstring':
-        "    PRUnichar *${name};\n"
+        "    const PRUnichar *${name};\n"
         "    if (!xpc_qsJsvalToWcharStr(cx, ${argVal}, ${argPtr}, &${name}))\n"
         "        return JS_FALSE;\n",
 
     '[cstring]':
         "    xpc_qsACString ${name}(cx, ${argVal}, ${argPtr});\n"
         "    if (!${name}.IsValid())\n"
         "        return JS_FALSE;\n",
 
--- a/js/xpconnect/src/qsgen.py
+++ b/js/xpconnect/src/qsgen.py
@@ -483,17 +483,17 @@ argumentUnboxingTemplates = {
 
     'string':
         "    JSAutoByteString ${name}_bytes;\n"
         "    if (!xpc_qsJsvalToCharStr(cx, ${argVal}, &${name}_bytes))\n"
         "        return JS_FALSE;\n"
         "    char *${name} = ${name}_bytes.ptr();\n",
 
     'wstring':
-        "    PRUnichar *${name};\n"
+        "    const PRUnichar *${name};\n"
         "    if (!xpc_qsJsvalToWcharStr(cx, ${argVal}, ${argPtr}, &${name}))\n"
         "        return JS_FALSE;\n",
 
     '[cstring]':
         "    xpc_qsACString ${name}(cx, ${argVal}, ${argPtr});\n"
         "    if (!${name}.IsValid())\n"
         "        return JS_FALSE;\n",