From 3e916d11bcbfb7c208c295bcd92a1730157a8564 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Tue, 31 Jan 2012 15:48:27 -0800 Subject: [PATCH] Add dump() to JSString, JSAtom, and JSObject as an easier-to-type alias to js_Dump*. Also add equals(const char*) methods to JSAtom and JSString. These methods are all to be used *only* while debugging. No bug, rs=luke over IRC --- js/src/jsobj.cpp | 6 ++++++ js/src/jsobj.h | 3 +++ js/src/vm/String.cpp | 29 +++++++++++++++++++++++++++++ js/src/vm/String.h | 7 +++++++ 4 files changed, 45 insertions(+) diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 3a36ef4af611..5cbc7a49a380 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -6709,6 +6709,12 @@ DumpProperty(JSObject *obj, const Shape &shape) fprintf(stderr, "\n"); } +void +JSObject::dump() +{ + js_DumpObject(this); +} + JS_FRIEND_API(void) js_DumpObject(JSObject *obj) { diff --git a/js/src/jsobj.h b/js/src/jsobj.h index 92e148de4f45..ae37f5909a76 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -1474,6 +1474,9 @@ struct JSObject : js::gc::Cell JS_STATIC_ASSERT(offsetof(JSObject, type_) == offsetof(js::shadow::Object, type)); JS_STATIC_ASSERT(sizeof(JSObject) == sizeof(js::shadow::Object)); } + + /* For debugging purposes only! */ + void dump(); }; /* diff --git a/js/src/vm/String.cpp b/js/src/vm/String.cpp index 362fd0c28322..346c8b15957e 100644 --- a/js/src/vm/String.cpp +++ b/js/src/vm/String.cpp @@ -114,6 +114,29 @@ JSString::sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf) return mallocSizeOf(fixed.chars()); } +void +JSString::dump() +{ + js_DumpString(this); +} + +bool +JSString::equals(const char *s) +{ + const jschar *c = getChars(NULL); + if (!c) { + fprintf(stderr, "OOM in JSString::equals!\n"); + return false; + } + while (*c && *s) { + if (*c != *s) + return false; + c++; + s++; + } + return *c == *s; +} + static JS_ALWAYS_INLINE bool AllocChars(JSContext *maybecx, size_t length, jschar **chars, size_t *capacity) { @@ -390,6 +413,12 @@ JSFlatString::isIndex(uint32_t *indexp) const return false; } +void +JSAtom::dump() +{ + js_DumpAtom(this); +} + /* * Set up some tools to make it easier to generate large tables. After constant * folding, for each n, Rn(0) is the comma-separated list R(0), R(1), ..., R(2^n-1). diff --git a/js/src/vm/String.h b/js/src/vm/String.h index 73d3c5c8693b..b52d60e41f17 100644 --- a/js/src/vm/String.h +++ b/js/src/vm/String.h @@ -198,6 +198,10 @@ class JSString : public js::gc::Cell }; } d; + /* These are for debugging purposes only! */ + void dump(); + bool equals(const char *s); + public: /* Flags exposed only for jits */ @@ -693,6 +697,9 @@ class JSAtom : public JSFixedString bool isAtom() const MOZ_DELETE; JSAtom &asAtom() const MOZ_DELETE; + /* This is for debugging purposes only! */ + void dump(); + public: /* Returns the PropertyName for this. isIndex() must be false. */ inline js::PropertyName *asPropertyName();