Bug 1330699 part 11. Add ConvertJSValueTo*String functions that just take a value and hand out a string, without extra complications. r=qdot
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 15 Feb 2017 00:01:37 -0500
changeset 389606 990c9e8d710e20176b02dbcbedbac380265ff4c3
parent 389605 794f653f1de6458ad59fa59fbeb2992fcdaed7e0
child 389607 289f25464d09aa9dc6d8e24d126938725e46f06f
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1330699
milestone54.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 1330699 part 11. Add ConvertJSValueTo*String functions that just take a value and hand out a string, without extra complications. r=qdot
dom/bindings/BindingUtils.cpp
dom/bindings/BindingUtils.h
dom/bindings/Codegen.py
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -2585,42 +2585,42 @@ NonVoidByteStringToJsval(JSContext *cx, 
         return false;
 
     rval.setString(jsStr);
     return true;
 }
 
 
 template<typename T> static void
-NormalizeUSVStringInternal(JSContext* aCx, T& aString)
+NormalizeUSVStringInternal(T& aString)
 {
   char16_t* start = aString.BeginWriting();
   // Must use const here because we can't pass char** to UTF16CharEnumerator as
   // it expects const char**.  Unclear why this is illegal...
   const char16_t* nextChar = start;
   const char16_t* end = aString.Data() + aString.Length();
   while (nextChar < end) {
     uint32_t enumerated = UTF16CharEnumerator::NextChar(&nextChar, end);
     if (enumerated == UCS2_REPLACEMENT_CHAR) {
       int32_t lastCharIndex = (nextChar - start) - 1;
       start[lastCharIndex] = static_cast<char16_t>(enumerated);
     }
   }
 }
 
 void
-NormalizeUSVString(JSContext* aCx, nsAString& aString)
+NormalizeUSVString(nsAString& aString)
 {
-  NormalizeUSVStringInternal(aCx, aString);
+  NormalizeUSVStringInternal(aString);
 }
 
 void
-NormalizeUSVString(JSContext* aCx, binding_detail::FakeString& aString)
+NormalizeUSVString(binding_detail::FakeString& aString)
 {
-  NormalizeUSVStringInternal(aCx, aString);
+  NormalizeUSVStringInternal(aString);
 }
 
 bool
 ConvertJSValueToByteString(JSContext* cx, JS::Handle<JS::Value> v,
                            bool nullable, nsACString& result)
 {
   JS::Rooted<JSString*> s(cx);
   if (v.isString()) {
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -1896,21 +1896,40 @@ ConvertJSValueToString(JSContext* cx, JS
     if (!s) {
       return false;
     }
   }
 
   return AssignJSString(cx, result, s);
 }
 
+template<typename T>
+static inline bool
+ConvertJSValueToString(JSContext* cx, JS::Handle<JS::Value> v, T& result)
+{
+  return ConvertJSValueToString(cx, v, eStringify, eStringify, result);
+}
+
 void
-NormalizeUSVString(JSContext* aCx, nsAString& aString);
+NormalizeUSVString(nsAString& aString);
 
 void
-NormalizeUSVString(JSContext* aCx, binding_detail::FakeString& aString);
+NormalizeUSVString(binding_detail::FakeString& aString);
+
+template<typename T>
+static inline bool
+ConvertJSValueToUSVString(JSContext* cx, JS::Handle<JS::Value> v, T& result)
+{
+  if (!ConvertJSValueToString(cx, v, eStringify, eStringify, result)) {
+    return false;
+  }
+
+  NormalizeUSVString(result);
+  return true;
+}
 
 template<typename T>
 inline bool
 ConvertIdToString(JSContext* cx, JS::HandleId id, T& result, bool& isSymbol)
 {
   if (MOZ_LIKELY(JSID_IS_STRING(id))) {
     if (!AssignJSString(cx, result, JSID_TO_STRING(id))) {
       return false;
@@ -1927,16 +1946,23 @@ ConvertIdToString(JSContext* cx, JS::Han
   isSymbol = false;
   return true;
 }
 
 bool
 ConvertJSValueToByteString(JSContext* cx, JS::Handle<JS::Value> v,
                            bool nullable, nsACString& result);
 
+inline bool
+ConvertJSValueToByteString(JSContext* cx, JS::Handle<JS::Value> v,
+                           nsACString& result)
+{
+  return ConvertJSValueToByteString(cx, v, false, result);
+}
+
 template<typename T>
 void DoTraceSequence(JSTracer* trc, FallibleTArray<T>& seq);
 template<typename T>
 void DoTraceSequence(JSTracer* trc, InfallibleTArray<T>& seq);
 
 // Class used to trace sequences, with specializations for various
 // sequence types.
 template<typename T,
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -5634,17 +5634,17 @@ def getJSToNativeConversionInfo(type, de
             undefinedBehavior = "eNull"
         else:
             undefinedBehavior = "eStringify"
         nullBehavior = treatAs[treatNullAs]
 
         def getConversionCode(varName):
             normalizeCode = ""
             if type.isUSVString():
-                normalizeCode = "NormalizeUSVString(cx, %s);\n" % varName
+                normalizeCode = "NormalizeUSVString(%s);\n" % varName
 
             conversionCode = fill("""
                 if (!ConvertJSValueToString(cx, $${val}, ${nullBehavior}, ${undefinedBehavior}, ${varName})) {
                   $*{exceptionCode}
                 }
                 $*{normalizeCode}
                 """
                 ,