Bug 1343292 - change return types in GenericPrinter; r=nbp
authorTom Tromey <tom@tromey.com>
Tue, 28 Feb 2017 14:18:40 -0700
changeset 374448 051ef53a3a81d78c0f2088e101a77975035fd9c4
parent 374447 362a5654bf6b83ecea81d7ba38771736efc48639
child 374449 47ca6f095807f0e652fbfa028a78e2ef28c8bfa2
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs1343292
milestone54.0a1
Bug 1343292 - change return types in GenericPrinter; r=nbp MozReview-Commit-ID: 1GJYujhrWj7
js/src/jsopcode.cpp
js/src/jsstr.cpp
js/src/shell/js.cpp
js/src/vm/Printer.cpp
js/src/vm/Printer.h
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -190,25 +190,25 @@ DumpPCCounts(JSContext* cx, HandleScript
 #ifdef DEBUG
     jsbytecode* pc = script->code();
     while (pc < script->codeEnd()) {
         jsbytecode* next = GetNextPc(pc);
 
         if (!Disassemble1(cx, script, pc, script->pcToOffset(pc), true, sp))
             return false;
 
-        if (sp->put("                  {") < 0)
+        if (!sp->put("                  {"))
             return false;
 
         PCCounts* counts = script->maybeGetPCCounts(pc);
         if (double val = counts ? counts->numExec() : 0.0) {
             if (!sp->jsprintf("\"%s\": %.0f", PCCounts::numExecName, val))
                 return false;
         }
-        if (sp->put("}\n") < 0)
+        if (!sp->put("}\n"))
             return false;
 
         pc = next;
     }
 #endif
 
     jit::IonScriptCounts* ionCounts = script->getIonCounts();
     while (ionCounts) {
@@ -1051,82 +1051,82 @@ DisassembleAtPC(JSContext* cx, JSScript*
         return false;
 
     if (showAll) {
         if (!sp->jsprintf("%s:%u\n", script->filename(), unsigned(script->lineno())))
             return false;
     }
 
     if (pc != nullptr) {
-        if (sp->put("    ") < 0)
+        if (!sp->put("    "))
             return false;
     }
     if (showAll) {
-        if (sp->put("sn stack ") < 0)
+        if (!sp->put("sn stack "))
             return false;
     }
-    if (sp->put("loc   ") < 0)
+    if (!sp->put("loc   "))
         return false;
     if (lines) {
-        if (sp->put("line") < 0)
+        if (!sp->put("line"))
             return false;
     }
-    if (sp->put("  op\n") < 0)
+    if (!sp->put("  op\n"))
         return false;
 
     if (pc != nullptr) {
-        if (sp->put("    ") < 0)
+        if (!sp->put("    "))
             return false;
     }
     if (showAll) {
-        if (sp->put("-- ----- ") < 0)
+        if (!sp->put("-- ----- "))
             return false;
     }
-    if (sp->put("----- ") < 0)
+    if (!sp->put("----- "))
         return false;
     if (lines) {
-        if (sp->put("----") < 0)
+        if (!sp->put("----"))
             return false;
     }
-    if (sp->put("  --\n") < 0)
+    if (!sp->put("  --\n"))
         return false;
 
     jsbytecode* next = script->code();
     jsbytecode* end = script->codeEnd();
     while (next < end) {
         if (next == script->main()) {
-            if (sp->put("main:\n") < 0)
+            if (!sp->put("main:\n"))
                 return false;
         }
         if (pc != nullptr) {
-            if (sp->put(pc == next ? "--> " : "    ") < 0)
+            if (!sp->put(pc == next ? "--> " : "    "))
                 return false;
         }
         if (showAll) {
             jssrcnote* sn = GetSrcNote(cx, script, next);
             if (sn) {
                 MOZ_ASSERT(!SN_IS_TERMINATOR(sn));
                 jssrcnote* next = SN_NEXT(sn);
                 while (!SN_IS_TERMINATOR(next) && SN_DELTA(next) == 0) {
                     if (!sp->jsprintf("%02u\n    ", SN_TYPE(sn)))
                         return false;
                     sn = next;
                     next = SN_NEXT(sn);
                 }
                 if (!sp->jsprintf("%02u ", SN_TYPE(sn)))
                     return false;
             } else {
-                if (sp->put("   ") < 0)
+                if (!sp->put("   "))
                     return false;
             }
             if (parser.isReachable(next)) {
                 if (!sp->jsprintf("%05u ", parser.stackDepthAtPC(next)))
                     return false;
             } else {
-                if (sp->put("      ") < 0)
+                if (!sp->put("      "))
                     return false;
             }
         }
         unsigned len = Disassemble1(cx, script, next, script->pcToOffset(next), lines,
                                     &parser, sp);
         if (!len)
             return false;
 
@@ -1371,30 +1371,33 @@ Disassemble1(JSContext* cx, HandleScript
         if (stackDumped)
             return true;
         stackDumped = true;
 
         size_t after = sp->stringEnd() - sp->string();
         MOZ_ASSERT(after >= before);
 
         static const size_t stack_column = 40;
-        for (size_t i = after - before; i < stack_column - 1; i++)
-            sp->put(" ");
-
-        sp->put(" # ");
+        for (size_t i = after - before; i < stack_column - 1; i++) {
+            if (!sp->put(" "))
+                return false;
+        }
+
+        if (!sp->put(" # "))
+            return false;
 
         if (!parser->isReachable(pc)) {
-            if (sp->put("!!! UNREACHABLE !!!") < 0)
+            if (!sp->put("!!! UNREACHABLE !!!"))
                 return false;
         } else {
             uint32_t depth = parser->stackDepthAfterPC(pc);
 
             for (uint32_t i = 0; i < depth; i++) {
                 if (i) {
-                    if (sp->put(" ") < 0)
+                    if (!sp->put(" "))
                         return false;
                 }
 
                 const OffsetAndDefIndex& offsetAndDefIndex
                     = parser->offsetForStackOperandAfterPC(script->pcToOffset(pc), i);
                 // This will decompile the stack for the same PC many times.
                 // We'll avoid optimizing it since this is a testing function
                 // and it won't be worth managing cached expression here.
@@ -1846,17 +1849,17 @@ ExpressionDecompiler::decompilePC(jsbyte
       case JSOP_FALSE:
         return write(js_false_str);
       case JSOP_ZERO:
       case JSOP_ONE:
       case JSOP_INT8:
       case JSOP_UINT16:
       case JSOP_UINT24:
       case JSOP_INT32:
-        return sprinter.printf("%d", GetBytecodeInteger(pc)) >= 0;
+        return sprinter.printf("%d", GetBytecodeInteger(pc));
       case JSOP_STRING:
         return quote(loadAtom(pc), '"');
       case JSOP_SYMBOL: {
         unsigned i = uint8_t(pc[1]);
         MOZ_ASSERT(i < JS::WellKnownSymbolLimit);
         if (i < JS::WellKnownSymbolLimit)
             return write(cx->names().wellKnownSymbolDescriptions()[i]);
         break;
@@ -1967,17 +1970,17 @@ ExpressionDecompiler::decompilePC(jsbyte
 
           case JSOP_CLASSHERITAGE:
             if (defIndex == 0)
                 return write("FUNCPROTO");
             MOZ_ASSERT(defIndex == 1);
             return write("OBJPROTO");
 
           case JSOP_DOUBLE:
-            return sprinter.printf("%lf", script->getConst(GET_UINT32_INDEX(pc)).toDouble()) >= 0;
+            return sprinter.printf("%lf", script->getConst(GET_UINT32_INDEX(pc)).toDouble());
 
           case JSOP_EXCEPTION:
             return write("EXCEPTION");
 
           case JSOP_FINALLY:
             if (defIndex == 0)
                 return write("THROWING");
             MOZ_ASSERT(defIndex == 1);
@@ -2127,25 +2130,25 @@ ExpressionDecompiler::init()
         return false;
 
     return true;
 }
 
 bool
 ExpressionDecompiler::write(const char* s)
 {
-    return sprinter.put(s) >= 0;
+    return sprinter.put(s);
 }
 
 bool
 ExpressionDecompiler::write(JSString* str)
 {
     if (str == cx->names().dotThis)
         return write("this");
-    return sprinter.putString(str) >= 0;
+    return sprinter.putString(str);
 }
 
 bool
 ExpressionDecompiler::quote(JSString* s, uint32_t quote)
 {
     return QuoteString(&sprinter, s, quote) != nullptr;
 }
 
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -4016,17 +4016,17 @@ js::PutEscapedStringImpl(char* buffer, s
             MOZ_ASSERT(n <= bufferSize);
             if (n != bufferSize) {
                 buffer[n] = c;
             } else {
                 buffer[n] = '\0';
                 buffer = nullptr;
             }
         } else if (out) {
-            if (out->put(&c, 1) < 0)
+            if (!out->put(&c, 1))
                 return size_t(-1);
         }
         n++;
     }
   stop:
     if (buffer)
         buffer[n] = '\0';
     return n;
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2527,20 +2527,20 @@ UpdateSwitchTableBounds(JSContext* cx, H
 
     *start = script->pcToOffset(pc);
     *end = *start + (unsigned)(n * jmplen);
 }
 
 static MOZ_MUST_USE bool
 SrcNotes(JSContext* cx, HandleScript script, Sprinter* sp)
 {
-    if (sp->put("\nSource notes:\n") < 0 ||
+    if (!sp->put("\nSource notes:\n") ||
         !sp->jsprintf("%4s %4s %5s %6s %-8s %s\n",
                       "ofs", "line", "pc", "delta", "desc", "args") ||
-        sp->put("---- ---- ----- ------ -------- ------\n") < 0)
+        !sp->put("---- ---- ----- ------ -------- ------\n"))
     {
         return false;
     }
 
     unsigned offset = 0;
     unsigned colspan = 0;
     unsigned lineno = script->lineno();
     jssrcnote* notes = script->notes();
@@ -2638,17 +2638,17 @@ SrcNotes(JSContext* cx, HandleScript scr
             MOZ_ASSERT(JSOp(script->code()[offset]) == JSOP_TRY);
             if (!sp->jsprintf(" offset to jump %u", unsigned(GetSrcNoteOffset(sn, 0))))
                 return false;
             break;
 
           default:
             MOZ_ASSERT_UNREACHABLE("unrecognized srcnote");
         }
-        if (sp->put("\n") < 0)
+        if (!sp->put("\n"))
             return false;
     }
 
     return true;
 }
 
 static bool
 Notes(JSContext* cx, unsigned argc, Value* vp)
@@ -2696,17 +2696,17 @@ TryNoteName(JSTryNoteKind kind)
 }
 
 static MOZ_MUST_USE bool
 TryNotes(JSContext* cx, HandleScript script, Sprinter* sp)
 {
     if (!script->hasTrynotes())
         return true;
 
-    if (sp->put("\nException table:\nkind             stack    start      end\n") < 0)
+    if (!sp->put("\nException table:\nkind             stack    start      end\n"))
         return false;
 
     JSTryNote* tn = script->trynotes()->vector;
     JSTryNote* tnlimit = tn + script->trynotes()->length;
     do {
         uint32_t startOff = script->pcToOffset(script->main()) + tn->start;
         if (!sp->jsprintf(" %-14s %6u %8u %8u\n",
                           TryNoteName(static_cast<JSTryNoteKind>(tn->kind)),
@@ -2719,17 +2719,17 @@ TryNotes(JSContext* cx, HandleScript scr
 }
 
 static MOZ_MUST_USE bool
 ScopeNotes(JSContext* cx, HandleScript script, Sprinter* sp)
 {
     if (!script->hasScopeNotes())
         return true;
 
-    if (sp->put("\nScope notes:\n   index   parent    start      end\n") < 0)
+    if (!sp->put("\nScope notes:\n   index   parent    start      end\n"))
         return false;
 
     ScopeNoteArray* notes = script->scopeNotes();
     for (uint32_t i = 0; i < notes->length; i++) {
         const ScopeNote* note = &notes->vector[i];
         if (note->index == ScopeNote::NoScopeIndex) {
             if (!sp->jsprintf("%8s ", "(none)"))
                 return false;
@@ -2750,51 +2750,51 @@ ScopeNotes(JSContext* cx, HandleScript s
     return true;
 }
 
 static MOZ_MUST_USE bool
 DisassembleScript(JSContext* cx, HandleScript script, HandleFunction fun,
                   bool lines, bool recursive, bool sourceNotes, Sprinter* sp)
 {
     if (fun) {
-        if (sp->put("flags:") < 0)
+        if (!sp->put("flags:"))
             return false;
         if (fun->isLambda()) {
-            if (sp->put(" LAMBDA") < 0)
+            if (!sp->put(" LAMBDA"))
                 return false;
         }
         if (fun->needsCallObject()) {
-            if (sp->put(" NEEDS_CALLOBJECT") < 0)
+            if (!sp->put(" NEEDS_CALLOBJECT"))
                 return false;
         }
         if (fun->needsExtraBodyVarEnvironment()) {
-            if (sp->put(" NEEDS_EXTRABODYVARENV") < 0)
+            if (!sp->put(" NEEDS_EXTRABODYVARENV"))
                 return false;
         }
         if (fun->needsNamedLambdaEnvironment()) {
-            if (sp->put(" NEEDS_NAMEDLAMBDAENV") < 0)
+            if (!sp->put(" NEEDS_NAMEDLAMBDAENV"))
                 return false;
         }
         if (fun->isConstructor()) {
-            if (sp->put(" CONSTRUCTOR") < 0)
+            if (!sp->put(" CONSTRUCTOR"))
                 return false;
         }
         if (script->isExprBody()) {
-            if (sp->put(" EXPRESSION_CLOSURE") < 0)
+            if (!sp->put(" EXPRESSION_CLOSURE"))
                 return false;
         }
         if (fun->isSelfHostedBuiltin()) {
-            if (sp->put(" SELF_HOSTED") < 0)
+            if (!sp->put(" SELF_HOSTED"))
                 return false;
         }
         if (fun->isArrow()) {
-            if (sp->put(" ARROW") < 0)
+            if (!sp->put(" ARROW"))
                 return false;
         }
-        if (sp->put("\n") < 0)
+        if (!sp->put("\n"))
             return false;
     }
 
     if (!Disassemble(cx, script, lines, sp))
         return false;
     if (sourceNotes) {
         if (!SrcNotes(cx, script, sp))
             return false;
@@ -2804,28 +2804,28 @@ DisassembleScript(JSContext* cx, HandleS
     if (!ScopeNotes(cx, script, sp))
         return false;
 
     if (recursive && script->hasObjects()) {
         ObjectArray* objects = script->objects();
         for (unsigned i = 0; i != objects->length; ++i) {
             JSObject* obj = objects->vector[i];
             if (obj->is<JSFunction>()) {
-                if (sp->put("\n") < 0)
+                if (!sp->put("\n"))
                     return false;
 
                 RootedFunction fun(cx, &obj->as<JSFunction>());
                 if (fun->isInterpreted()) {
                     RootedScript script(cx, JSFunction::getOrCreateScript(cx, fun));
                     if (script) {
                         if (!DisassembleScript(cx, script, fun, lines, recursive, sourceNotes, sp))
                             return false;
                     }
                 } else {
-                    if (sp->put("[native code]\n") < 0)
+                    if (!sp->put("[native code]\n"))
                         return false;
                 }
             }
         }
     }
 
     return true;
 }
@@ -5497,17 +5497,17 @@ class SprintOptimizationTypeInfoOp : pub
                   const char* location, const Maybe<unsigned>& lineno) override
     {
         if (hadError_)
             return;
 
         do {
             if (!startedTypes_) {
                 startedTypes_ = true;
-                if (sp->put("{\"typeset\": [") < 0)
+                if (!sp->put("{\"typeset\": ["))
                     break;
             }
 
             if (!sp->jsprintf("{\"keyedBy\":\"%s\"", keyedBy))
                 break;
 
             if (name) {
                 if (!sp->jsprintf(",\"name\":\"%s\"", name))
@@ -5519,17 +5519,17 @@ class SprintOptimizationTypeInfoOp : pub
                 PutEscapedString(buf, mozilla::ArrayLength(buf), location, strlen(location), '"');
                 if (!sp->jsprintf(",\"location\":%s", buf))
                     break;
             }
             if (lineno.isSome()) {
                 if (!sp->jsprintf(",\"line\":%u", *lineno))
                     break;
             }
-            if (sp->put("},") < 0)
+            if (!sp->put("},"))
                 break;
 
             return;
         } while (false);
 
         hadError_ = true;
     }
 
@@ -5537,22 +5537,22 @@ class SprintOptimizationTypeInfoOp : pub
         if (hadError_)
             return;
 
         do {
             if (startedTypes_) {
                 // Clear trailing ,
                 if ((*sp)[sp->getOffset() - 1] == ',')
                     (*sp)[sp->getOffset() - 1] = ' ';
-                if (sp->put("],") < 0)
+                if (!sp->put("],"))
                     break;
 
                 startedTypes_ = false;
             } else {
-                if (sp->put("{") < 0)
+                if (!sp->put("{"))
                     break;
             }
 
             if (!sp->jsprintf("\"site\":\"%s\",\"mirType\":\"%s\"},",
                               TrackedTypeSiteString(site), mirType))
             {
                 break;
             }
@@ -5636,17 +5636,17 @@ ReflectTrackedOptimizations(JSContext* c
 
     Sprinter sp(cx);
     if (!sp.init())
         return false;
 
     const jit::IonTrackedOptimizationsRegionTable* regions =
         entry.ionEntry().trackedOptimizationsRegionTable();
 
-    if (sp.put("{\"regions\": [") < 0)
+    if (!sp.put("{\"regions\": ["))
         return false;
 
     for (uint32_t i = 0; i < regions->numEntries(); i++) {
         jit::IonTrackedOptimizationsRegion region = regions->entry(i);
         jit::IonTrackedOptimizationsRegion::RangeIterator iter = region.ranges();
         while (iter.more()) {
             uint32_t startOffset, endOffset;
             uint8_t index;
@@ -5666,53 +5666,53 @@ ReflectTrackedOptimizations(JSContext* c
                              script->filename(), script->lineno(), script->pcToOffset(pc), index,
                              iter.more() ? "," : ""))
             {
                 return false;
             }
         }
     }
 
-    if (sp.put("],") < 0)
-        return false;
-
-    if (sp.put("\"opts\": [") < 0)
+    if (!sp.put("],"))
+        return false;
+
+    if (!sp.put("\"opts\": ["))
         return false;
 
     for (uint8_t i = 0; i < entry.ionEntry().numOptimizationAttempts(); i++) {
         if (!sp.jsprintf("%s{\"typeinfo\":[", i == 0 ? "" : ","))
             return false;
 
         SprintOptimizationTypeInfoOp top(&sp);
         jit::IonTrackedOptimizationsTypeInfo::ForEachOpAdapter adapter(top);
         entry.trackedOptimizationTypeInfo(i).forEach(adapter, entry.allTrackedTypes());
         if (top.hadError())
             return false;
 
         // Clear the trailing ,
         if (sp[sp.getOffset() - 1] == ',')
             sp[sp.getOffset() - 1] = ' ';
 
-        if (sp.put("],\"attempts\":[") < 0)
+        if (!sp.put("],\"attempts\":["))
             return false;
 
         SprintOptimizationAttemptsOp aop(&sp);
         entry.trackedOptimizationAttempts(i).forEach(aop);
         if (aop.hadError())
             return false;
 
         // Clear the trailing ,
         if (sp[sp.getOffset() - 1] == ',')
             sp[sp.getOffset() - 1] = ' ';
 
-        if (sp.put("]}") < 0)
-            return false;
-    }
-
-    if (sp.put("]}") < 0)
+        if (!sp.put("]}"))
+            return false;
+    }
+
+    if (!sp.put("]}"))
         return false;
 
     if (sp.hadOutOfMemory())
         return false;
 
     RootedString str(cx, JS_NewStringCopyZ(cx, sp.string()));
     if (!str)
         return false;
--- a/js/src/vm/Printer.cpp
+++ b/js/src/vm/Printer.cpp
@@ -36,42 +36,42 @@ GenericPrinter::reportOutOfMemory()
 }
 
 bool
 GenericPrinter::hadOutOfMemory() const
 {
     return hadOOM_;
 }
 
-int
+bool
 GenericPrinter::printf(const char* fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
-    int i = vprintf(fmt, va);
+    bool r = vprintf(fmt, va);
     va_end(va);
-    return i;
+    return r;
 }
 
-int
+bool
 GenericPrinter::vprintf(const char* fmt, va_list ap)
 {
     // Simple shortcut to avoid allocating strings.
     if (strchr(fmt, '%') == nullptr)
         return put(fmt);
 
     char* bp;
     bp = JS_vsmprintf(fmt, ap);      /* XXX vsaprintf */
     if (!bp) {
         reportOutOfMemory();
-        return -1;
+        return false;
     }
-    int i = put(bp);
+    bool r = put(bp);
     js_free(bp);
-    return i;
+    return r;
 }
 
 const size_t Sprinter::DefaultSize = 64;
 
 bool
 Sprinter::realloc_(size_t newSize)
 {
     MOZ_ASSERT(newSize > (size_t) offset);
@@ -166,87 +166,85 @@ Sprinter::reserve(size_t len)
             return nullptr;
     }
 
     char* sb = base + offset;
     offset += len;
     return sb;
 }
 
-int
+bool
 Sprinter::put(const char* s, size_t len)
 {
     InvariantChecker ic(this);
 
     const char* oldBase = base;
     const char* oldEnd = base + size;
 
-    ptrdiff_t oldOffset = offset;
     char* bp = reserve(len);
     if (!bp)
-        return -1;
+        return false;
 
     /* s is within the buffer already */
     if (s >= oldBase && s < oldEnd) {
         /* buffer was realloc'ed */
         if (base != oldBase)
             s = stringAt(s - oldBase);  /* this is where it lives now */
         memmove(bp, s, len);
     } else {
         js_memcpy(bp, s, len);
     }
 
     bp[len] = 0;
-    return oldOffset;
+    return true;
 }
 
-int
+bool
 Sprinter::vprintf(const char* fmt, va_list ap)
 {
     InvariantChecker ic(this);
 
     do {
         va_list aq;
         va_copy(aq, ap);
         int i = vsnprintf(base + offset, size - offset, fmt, aq);
         va_end(aq);
         if (i > -1 && (size_t) i < size - offset) {
             offset += i;
-            return i;
+            return true;
         }
     } while (realloc_(size * 2));
 
-    return -1;
+    return false;
 }
 
-int
+bool
 Sprinter::putString(JSString* s)
 {
     InvariantChecker ic(this);
 
     size_t length = s->length();
     size_t size = length;
 
-    ptrdiff_t oldOffset = offset;
     char* buffer = reserve(size);
     if (!buffer)
-        return -1;
+        return false;
 
     JSLinearString* linear = s->ensureLinear(context);
     if (!linear)
-        return -1;
+        return false;
 
     JS::AutoCheckCannotGC nogc;
     if (linear->hasLatin1Chars())
         PodCopy(reinterpret_cast<Latin1Char*>(buffer), linear->latin1Chars(nogc), length);
     else
         DeflateStringToBuffer(nullptr, linear->twoByteChars(nogc), length, buffer, &size);
 
     buffer[size] = 0;
-    return oldOffset;
+    return true;
 }
 
 ptrdiff_t
 Sprinter::getOffset() const
 {
     return offset;
 }
 
@@ -268,17 +266,17 @@ Sprinter::jsprintf(const char* format, .
 
     UniquePtr<char, JS::FreePolicy> chars(JS_vsmprintf(format, ap));      /* XXX vsaprintf */
     va_end(ap);
     if (!chars) {
         reportOutOfMemory();
         return false;
     }
 
-    return put(chars.get()) >= 0;
+    return put(chars.get());
 }
 
 const char js_EscapeMap[] = {
     '\b', 'b',
     '\f', 'f',
     '\n', 'n',
     '\r', 'r',
     '\t', 't',
@@ -353,17 +351,17 @@ QuoteString(Sprinter* sp, const mozilla:
             return nullptr;
     }
 
     /*
      * If we haven't Sprint'd anything yet, Sprint an empty string so that
      * the return below gives a valid result.
      */
     if (offset == sp->getOffset()) {
-        if (sp->put("") < 0)
+        if (!sp->put(""))
             return nullptr;
     }
 
     return sp->stringAt(offset);
 }
 
 char*
 QuoteString(Sprinter* sp, JSString* str, char16_t quote)
@@ -437,49 +435,49 @@ void
 Fprinter::finish()
 {
     MOZ_ASSERT(file_);
     if (init_)
         fclose(file_);
     file_ = nullptr;
 }
 
-int
+bool
 Fprinter::put(const char* s, size_t len)
 {
     MOZ_ASSERT(file_);
     int i = fwrite(s, len, 1, file_);
     if (size_t(i) != len) {
         reportOutOfMemory();
-        return -1;
+        return false;
     }
-    return i;
+    return true;
 }
 
-int
+bool
 Fprinter::printf(const char* fmt, ...)
 {
     MOZ_ASSERT(file_);
     va_list ap;
     va_start(ap, fmt);
-    int i = vfprintf(file_, fmt, ap);
-    if (i == -1)
+    bool r = vfprintf(file_, fmt, ap);
+    if (!r)
         reportOutOfMemory();
     va_end(ap);
-    return i;
+    return r;
 }
 
-int
+bool
 Fprinter::vprintf(const char* fmt, va_list ap)
 {
     MOZ_ASSERT(file_);
-    int i = vfprintf(file_, fmt, ap);
-    if (i == -1)
+    bool r = vfprintf(file_, fmt, ap);
+    if (!r)
         reportOutOfMemory();
-    return i;
+    return r;
 }
 
 LSprinter::LSprinter(LifoAlloc* lifoAlloc)
   : alloc_(lifoAlloc),
     head_(nullptr),
     tail_(nullptr),
     unused_(0)
 { }
@@ -505,17 +503,17 @@ void
 LSprinter::clear()
 {
     head_ = nullptr;
     tail_ = nullptr;
     unused_ = 0;
     hadOOM_ = false;
 }
 
-int
+bool
 LSprinter::put(const char* s, size_t len)
 {
     // Compute how much data will fit in the current chunk.
     size_t existingSpaceWrite = 0;
     size_t overflow = len;
     if (unused_ > 0 && tail_) {
         existingSpaceWrite = std::min(unused_, len);
         overflow = len - existingSpaceWrite;
@@ -526,17 +524,17 @@ LSprinter::put(const char* s, size_t len
     Chunk* last = nullptr;
     if (overflow > 0) {
         allocLength = AlignBytes(sizeof(Chunk) + overflow, js::detail::LIFO_ALLOC_ALIGN);
 
         LifoAlloc::AutoFallibleScope fallibleAllocator(alloc_);
         last = reinterpret_cast<Chunk*>(alloc_->alloc(allocLength));
         if (!last) {
             reportOutOfMemory();
-            return -1;
+            return false;
         }
     }
 
     // All fallible operations complete: now fill up existing space, then
     // overflow space in any new chunk.
     MOZ_ASSERT(existingSpaceWrite + overflow == len);
 
     if (existingSpaceWrite > 0) {
@@ -569,45 +567,45 @@ LSprinter::put(const char* s, size_t len
 
         PodCopy(tail_->end() - unused_, s, overflow);
 
         MOZ_ASSERT(unused_ >= overflow);
         unused_ -= overflow;
     }
 
     MOZ_ASSERT(len <= INT_MAX);
-    return int(len);
+    return true;
 }
 
-int
+bool
 LSprinter::printf(const char* fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
-    int i = vprintf(fmt, va);
+    bool r = vprintf(fmt, va);
     va_end(va);
-    return i;
+    return r;
 }
 
-int
+bool
 LSprinter::vprintf(const char* fmt, va_list ap)
 {
     // Simple shortcut to avoid allocating strings.
     if (strchr(fmt, '%') == nullptr)
         return put(fmt);
 
     char* bp;
     bp = JS_vsmprintf(fmt, ap);      /* XXX vsaprintf */
     if (!bp) {
         reportOutOfMemory();
-        return -1;
+        return false;
     }
-    int i = put(bp);
+    bool r = put(bp);
     js_free(bp);
-    return i;
+    return r;
 }
 
 void
 LSprinter::reportOutOfMemory()
 {
     if (hadOOM_)
         return;
     hadOOM_ = true;
--- a/js/src/vm/Printer.h
+++ b/js/src/vm/Printer.h
@@ -30,27 +30,27 @@ class LifoAlloc;
 class GenericPrinter
 {
   protected:
     bool                  hadOOM_;     // whether reportOutOfMemory() has been called.
 
     GenericPrinter();
 
   public:
-    // Puts |len| characters from |s| at the current position and return an offset to
-    // the beginning of this new data.
-    virtual int put(const char* s, size_t len) = 0;
+    // Puts |len| characters from |s| at the current position and
+    // return true on success, false on failure.
+    virtual bool put(const char* s, size_t len) = 0;
 
-    inline int put(const char* s) {
+    inline bool put(const char* s) {
         return put(s, strlen(s));
     }
 
     // Prints a formatted string into the buffer.
-    virtual int printf(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3);
-    virtual int vprintf(const char* fmt, va_list ap);
+    virtual bool printf(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3);
+    virtual bool vprintf(const char* fmt, va_list ap);
 
     // Report that a string operation failed to get the memory it requested. The
     // first call to this function calls JS_ReportOutOfMemory, and sets this
     // Sprinter's outOfMemory flag; subsequent calls do nothing.
     virtual void reportOutOfMemory();
 
     // Return true if this Sprinter ran out of memory.
     virtual bool hadOutOfMemory() const;
@@ -103,30 +103,30 @@ class Sprinter final : public GenericPri
     // Returns the char at offset |off|.
     char& operator[](size_t off);
 
     // Attempt to reserve len + 1 space (for a trailing nullptr byte). If the
     // attempt succeeds, return a pointer to the start of that space and adjust the
     // internal content. The caller *must* completely fill this space on success.
     char* reserve(size_t len);
 
-    // Puts |len| characters from |s| at the current position and return an offset to
-    // the beginning of this new data.
-    virtual int put(const char* s, size_t len) override;
-    using GenericPrinter::put; // pick up |inline int put(const char* s);|
+    // Puts |len| characters from |s| at the current position and
+    // return true on success, false on failure.
+    virtual bool put(const char* s, size_t len) override;
+    using GenericPrinter::put; // pick up |inline bool put(const char* s);|
 
     // Format the given format/arguments as if by JS_vsmprintf, then put it.
     // Return true on success, else return false and report an error (typically
     // OOM).
     MOZ_MUST_USE bool jsprintf(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3);
 
     // Prints a formatted string into the buffer.
-    virtual int vprintf(const char* fmt, va_list ap) override;
+    virtual bool vprintf(const char* fmt, va_list ap) override;
 
-    int putString(JSString* str);
+    bool putString(JSString* str);
 
     ptrdiff_t getOffset() const;
 
     // Report that a string operation failed to get the memory it requested. The
     // first call to this function calls JS_ReportOutOfMemory, and sets this
     // Sprinter's outOfMemory flag; subsequent calls do nothing.
     virtual void reportOutOfMemory() override;
 };
@@ -147,24 +147,24 @@ class Fprinter final : public GenericPri
     MOZ_MUST_USE bool init(const char* path);
     void init(FILE* fp);
     bool isInitialized() const {
         return file_ != nullptr;
     }
     void flush();
     void finish();
 
-    // Puts |len| characters from |s| at the current position and return an
-    // offset to the beginning of this new data.
-    virtual int put(const char* s, size_t len) override;
-    using GenericPrinter::put; // pick up |inline int put(const char* s);|
+    // Puts |len| characters from |s| at the current position and
+    // return true on success, false on failure.
+    virtual bool put(const char* s, size_t len) override;
+    using GenericPrinter::put; // pick up |inline bool put(const char* s);|
 
     // Prints a formatted string into the buffer.
-    virtual int printf(const char* fmt, ...) override MOZ_FORMAT_PRINTF(2, 3);
-    virtual int vprintf(const char* fmt, va_list ap) override;
+    virtual bool printf(const char* fmt, ...) override MOZ_FORMAT_PRINTF(2, 3);
+    virtual bool vprintf(const char* fmt, va_list ap) override;
 };
 
 // LSprinter, is similar to Sprinter except that instead of using an
 // JSContext to allocate strings, it use a LifoAlloc as a backend for the
 // allocation of the chunk of the string.
 class LSprinter final : public GenericPrinter
 {
   private:
@@ -193,24 +193,24 @@ class LSprinter final : public GenericPr
 
     // Copy the content of the chunks into another printer, such that we can
     // flush the content of this printer to a file.
     void exportInto(GenericPrinter& out) const;
 
     // Drop the current string, and let them be free with the LifoAlloc.
     void clear();
 
-    // Puts |len| characters from |s| at the current position and return an
-    // offset to the beginning of this new data.
-    virtual int put(const char* s, size_t len) override;
-    using GenericPrinter::put; // pick up |inline int put(const char* s);|
+    // Puts |len| characters from |s| at the current position and
+    // return true on success, false on failure.
+    virtual bool put(const char* s, size_t len) override;
+    using GenericPrinter::put; // pick up |inline bool put(const char* s);|
 
     // Prints a formatted string into the buffer.
-    virtual int printf(const char* fmt, ...) override MOZ_FORMAT_PRINTF(2, 3);
-    virtual int vprintf(const char* fmt, va_list ap) override;
+    virtual bool printf(const char* fmt, ...) override MOZ_FORMAT_PRINTF(2, 3);
+    virtual bool vprintf(const char* fmt, va_list ap) override;
 
     // Report that a string operation failed to get the memory it requested. The
     // first call to this function calls JS_ReportOutOfMemory, and sets this
     // Sprinter's outOfMemory flag; subsequent calls do nothing.
     virtual void reportOutOfMemory() override;
 
     // Return true if this Sprinter ran out of memory.
     virtual bool hadOutOfMemory() const override;