Bug 645416, part 20 - Add JS::Symbol::dump() method for debugging. r=efaust.

--HG--
extra : rebase_source : 2e2539f319593d51876ef39caa0c96800b6d605e
This commit is contained in:
Jason Orendorff 2014-06-23 10:56:52 -05:00
parent 39f62cf523
commit 2412cb39a5
4 changed files with 43 additions and 9 deletions

View File

@ -65,7 +65,7 @@ JSString::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf)
#ifdef DEBUG
void
JSString::dumpChars(const jschar *s, size_t n)
JSString::dumpChars(const jschar *s, size_t n, FILE *fp)
{
if (n == SIZE_MAX) {
n = 0;
@ -73,20 +73,20 @@ JSString::dumpChars(const jschar *s, size_t n)
n++;
}
fputc('"', stderr);
fputc('"', fp);
for (size_t i = 0; i < n; i++) {
if (s[i] == '\n')
fprintf(stderr, "\\n");
fprintf(fp, "\\n");
else if (s[i] == '\t')
fprintf(stderr, "\\t");
fprintf(fp, "\\t");
else if (s[i] >= 32 && s[i] < 127)
fputc(s[i], stderr);
fputc(s[i], fp);
else if (s[i] <= 255)
fprintf(stderr, "\\x%02x", (unsigned int) s[i]);
fprintf(fp, "\\x%02x", (unsigned int) s[i]);
else
fprintf(stderr, "\\u%04x", (unsigned int) s[i]);
fprintf(fp, "\\u%04x", (unsigned int) s[i]);
}
fputc('"', stderr);
fputc('"', fp);
}
void

View File

@ -487,7 +487,7 @@ class JSString : public js::gc::BarrieredCell<JSString>
#ifdef DEBUG
void dump();
static void dumpChars(const jschar *s, size_t len);
static void dumpChars(const jschar *s, size_t len, FILE *fp=stderr);
bool equals(const char *s);
#endif

View File

@ -78,6 +78,34 @@ Symbol::for_(js::ExclusiveContext *cx, HandleString description)
return sym;
}
#ifdef DEBUG
void
Symbol::dump(FILE *fp)
{
if (isWellKnownSymbol()) {
// All the well-known symbol names are ASCII.
const jschar *desc = description_->chars();
size_t len = description_->length();
for (size_t i = 0; i < len; i++)
fputc(char(desc[i]), fp);
} else if (code_ == SymbolCode::InSymbolRegistry || code_ == SymbolCode::UniqueSymbol) {
fputs(code_ == SymbolCode::InSymbolRegistry ? "Symbol.for(" : "Symbol(", fp);
if (description_)
JSString::dumpChars(description_->chars(), description_->length(), fp);
else
fputs("undefined", fp);
fputc(')', fp);
if (code_ == SymbolCode::UniqueSymbol)
fprintf(fp, "@%p", (void *) this);
} else {
fprintf(fp, "<Invalid Symbol code=%u>", unsigned(code_));
}
}
#endif // DEBUG
void
SymbolRegistry::sweep()
{

View File

@ -9,6 +9,8 @@
#include "mozilla/Attributes.h"
#include <stdio.h>
#include "jsalloc.h"
#include "jsapi.h"
@ -51,6 +53,10 @@ class Symbol : public js::gc::BarrieredCell<Symbol>
static inline js::ThingRootKind rootKind() { return js::THING_ROOT_SYMBOL; }
inline void markChildren(JSTracer *trc);
inline void finalize(js::FreeOp *) {}
#ifdef DEBUG
void dump(FILE *fp = stderr);
#endif
};
} /* namespace JS */