Bug 1034627 part 5 - Make quick stubs work with Latin1 strings and nursery strings. r=bz
☠☠ backed out by 1e19958b0386 ☠ ☠
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 11 Jul 2014 16:22:35 +0200
changeset 193594 8f50bc05d3373561b0d0e6a27a063361c0b37970
parent 193593 5e3f42130258a30d1d23bb8321366cecd208be70
child 193595 110fbc2ebc1a74d5aa424c911aebd792550745ce
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs1034627
milestone33.0a1
Bug 1034627 part 5 - Make quick stubs work with Latin1 strings and nursery strings. r=bz
js/xpconnect/src/XPCQuickStubs.cpp
js/xpconnect/src/XPCQuickStubs.h
--- a/js/xpconnect/src/XPCQuickStubs.cpp
+++ b/js/xpconnect/src/XPCQuickStubs.cpp
@@ -417,25 +417,19 @@ xpc_qsDOMString::xpc_qsDOMString(JSConte
     // From the T_DOMSTRING case in XPCConvert::JSData2Native.
     JSString *s = InitOrStringify<traits>(cx, v,
                                           pval, notpassed,
                                           nullBehavior,
                                           undefinedBehavior);
     if (!s)
         return;
 
-    size_t len;
-    const jschar *chars = JS_GetStringCharsZAndLength(cx, s, &len);
-    if (!chars) {
-        mValid = false;
-        return;
-    }
+    nsAutoString *str = new(mBuf) implementation_type();
 
-    new(mBuf) implementation_type(chars, len);
-    mValid = true;
+    mValid = AssignJSString(cx, *str, s);
 }
 
 xpc_qsACString::xpc_qsACString(JSContext *cx, HandleValue v,
                                MutableHandleValue pval, bool notpassed,
                                StringificationBehavior nullBehavior,
                                StringificationBehavior undefinedBehavior)
 {
     typedef implementation_type::char_traits traits;
@@ -466,24 +460,23 @@ xpc_qsACString::xpc_qsACString(JSContext
 xpc_qsAUTF8String::xpc_qsAUTF8String(JSContext *cx, HandleValue v, MutableHandleValue pval, bool notpassed)
 {
     typedef nsCharTraits<char16_t> traits;
     // From the T_UTF8STRING  case in XPCConvert::JSData2Native.
     JSString *s = InitOrStringify<traits>(cx, v, pval, notpassed, eNull, eNull);
     if (!s)
         return;
 
-    size_t len;
-    const char16_t *chars = JS_GetStringCharsZAndLength(cx, s, &len);
-    if (!chars) {
+    nsAutoJSString str;
+    if (!str.init(cx, s)) {
         mValid = false;
         return;
     }
 
-    new(mBuf) implementation_type(chars, len);
+    new(mBuf) implementation_type(str);
     mValid = true;
 }
 
 static nsresult
 getNative(nsISupports *idobj,
           HandleObject obj,
           const nsIID &iid,
           void **ppThis,
--- a/js/xpconnect/src/XPCQuickStubs.h
+++ b/js/xpconnect/src/XPCQuickStubs.h
@@ -276,17 +276,17 @@ protected:
  *
  * The second argument to the constructor is an in-out parameter. It must
  * point to a rooted jsval, such as a JSNative argument or return value slot.
  * The value in the jsval on entry is converted to a string. The constructor
  * may overwrite that jsval with a string value, to protect the characters of
  * the string from garbage collection. The caller must leave the jsval alone
  * for the lifetime of the xpc_qsDOMString.
  */
-class xpc_qsDOMString : public xpc_qsBasicString<nsAString, nsDependentString>
+class xpc_qsDOMString : public xpc_qsBasicString<nsAString, nsAutoString>
 {
 public:
     xpc_qsDOMString(JSContext *cx, JS::HandleValue v,
                     JS::MutableHandleValue pval, bool notpassed,
                     StringificationBehavior nullBehavior,
                     StringificationBehavior undefinedBehavior);
 };