Bug 1454207 - Part 2: Renames |ValueToPrintable| to |ValueToPrintableLatin1|, in preparation for introducing a new function |ValueToPrintableUtf8| r?arai draft
authorZhang Junzhi <zjz@zjz.name>
Sun, 15 Apr 2018 13:09:22 +0800
changeset 782453 ea833b6e508f38dae42920feb5585770ac264e42
parent 782452 51141aeb3880cf889e1c9bafd406d03310f07976
child 782454 68746d7b25bdc3462bb4e3cabfe6819414bee42b
push id106540
push userbmo:zjz@zjz.name
push dateMon, 16 Apr 2018 05:23:38 +0000
reviewersarai
bugs1454207
milestone61.0a1
Bug 1454207 - Part 2: Renames |ValueToPrintable| to |ValueToPrintableLatin1|, in preparation for introducing a new function |ValueToPrintableUtf8| r?arai MozReview-Commit-ID: CXTbJnKZMiH
js/src/vm/BytecodeUtil.cpp
js/src/vm/EnvironmentObject.cpp
js/src/vm/Interpreter.cpp
js/src/vm/JSContext.cpp
js/src/vm/StringType.cpp
js/src/vm/StringType.h
--- a/js/src/vm/BytecodeUtil.cpp
+++ b/js/src/vm/BytecodeUtil.cpp
@@ -1172,17 +1172,17 @@ ToDisassemblySource(JSContext* cx, Handl
         if (obj.is<RegExpObject>()) {
             JSString* source = obj.as<RegExpObject>().toString(cx);
             if (!source)
                 return false;
             return bytes->encodeLatin1(cx, source);
         }
     }
 
-    return !!ValueToPrintable(cx, v, bytes, true);
+    return !!ValueToPrintableLatin1(cx, v, bytes, true);
 }
 
 static bool
 ToDisassemblySource(JSContext* cx, HandleScope scope, JSAutoByteString* bytes)
 {
     UniqueChars source = JS_smprintf("%s {", ScopeKindString(scope->kind()));
     if (!source) {
         ReportOutOfMemory(cx);
--- a/js/src/vm/EnvironmentObject.cpp
+++ b/js/src/vm/EnvironmentObject.cpp
@@ -1413,17 +1413,17 @@ LiveEnvironmentVal::staticAsserts()
 /*****************************************************************************/
 
 namespace {
 
 static void
 ReportOptimizedOut(JSContext* cx, HandleId id)
 {
     JSAutoByteString printable;
-    if (ValueToPrintable(cx, IdToValue(id), &printable)) {
+    if (ValueToPrintableLatin1(cx, IdToValue(id), &printable)) {
         JS_ReportErrorNumberLatin1(cx, GetErrorMessage, nullptr, JSMSG_DEBUG_OPTIMIZED_OUT,
                                    printable.ptr());
     }
 }
 
 /*
  * DebugEnvironmentProxy is the handler for DebugEnvironmentProxy proxy
  * objects. Having a custom handler (rather than trying to reuse js::Wrapper)
--- a/js/src/vm/Interpreter.cpp
+++ b/js/src/vm/Interpreter.cpp
@@ -5061,17 +5061,17 @@ js::NewArrayOperationWithTemplate(JSCont
 }
 
 void
 js::ReportRuntimeLexicalError(JSContext* cx, unsigned errorNumber, HandleId id)
 {
     MOZ_ASSERT(errorNumber == JSMSG_UNINITIALIZED_LEXICAL ||
                errorNumber == JSMSG_BAD_CONST_ASSIGN);
     JSAutoByteString printable;
-    if (ValueToPrintable(cx, IdToValue(id), &printable))
+    if (ValueToPrintableLatin1(cx, IdToValue(id), &printable))
         JS_ReportErrorNumberLatin1(cx, GetErrorMessage, nullptr, errorNumber, printable.ptr());
 }
 
 void
 js::ReportRuntimeLexicalError(JSContext* cx, unsigned errorNumber, HandlePropertyName name)
 {
     RootedId id(cx, NameToId(name));
     ReportRuntimeLexicalError(cx, errorNumber, id);
--- a/js/src/vm/JSContext.cpp
+++ b/js/src/vm/JSContext.cpp
@@ -879,17 +879,17 @@ js::ReportErrorNumberUCArray(JSContext* 
 
     return warning;
 }
 
 void
 js::ReportIsNotDefined(JSContext* cx, HandleId id)
 {
     JSAutoByteString printable;
-    if (!ValueToPrintable(cx, IdToValue(id), &printable))
+    if (!ValueToPrintableLatin1(cx, IdToValue(id), &printable))
         return;
     JS_ReportErrorNumberLatin1(cx, GetErrorMessage, nullptr, JSMSG_NOT_DEFINED, printable.ptr());
 }
 
 void
 js::ReportIsNotDefined(JSContext* cx, HandlePropertyName name)
 {
     RootedId id(cx, NameToId(name));
--- a/js/src/vm/StringType.cpp
+++ b/js/src/vm/StringType.cpp
@@ -1904,17 +1904,18 @@ JSString::fillWithRepresentatives(JSCont
     MOZ_ASSERT(index == 22);
     return true;
 }
 
 
 /*** Conversions *********************************************************************************/
 
 const char*
-js::ValueToPrintable(JSContext* cx, const Value& vArg, JSAutoByteString* bytes, bool asSource)
+js::ValueToPrintableLatin1(JSContext* cx, const Value& vArg, JSAutoByteString* bytes,
+                           bool asSource)
 {
     RootedValue v(cx, vArg);
     JSString* str;
     if (asSource)
         str = ValueToSource(cx, v);
     else
         str = ToString<CanGC>(cx, v);
     if (!str)
--- a/js/src/vm/StringType.h
+++ b/js/src/vm/StringType.h
@@ -1583,19 +1583,25 @@ HasSubstringAt(JSLinearString* text, JSL
 JSString*
 SubstringKernel(JSContext* cx, HandleString str, int32_t beginInt, int32_t lengthInt);
 
 
 /*** Conversions *********************************************************************************/
 
 /*
  * Convert a value to a printable C string.
+ *
+ * As the function name implies, any characters in a converted printable string will be Latin1
+ * characters. If there are any non-Latin1 characters in the original value, then those characters
+ * will be changed to Unicode escape sequences(I.e. \udddd, dddd are 4 hex digits) in the printable
+ * string.
  */
 extern const char*
-ValueToPrintable(JSContext* cx, const Value&, JSAutoByteString* bytes, bool asSource = false);
+ValueToPrintableLatin1(JSContext* cx, const Value&, JSAutoByteString* bytes,
+                       bool asSource = false);
 
 /*
  * Convert a non-string value to a string, returning null after reporting an
  * error, otherwise returning a new string reference.
  */
 template <AllowGC allowGC>
 extern JSString*
 ToStringSlow(JSContext* cx, typename MaybeRooted<Value, allowGC>::HandleType arg);