Bug 1194426 - Add sourceLength and functionDisplayNameLength to JS::ubi::StackFrame. r=sfink

This commit is contained in:
Nick Fitzgerald 2015-08-13 13:17:00 -04:00
parent 9b02ae2e52
commit e1c1277c38
2 changed files with 35 additions and 0 deletions

View File

@ -363,6 +363,10 @@ class StackFrame : public JS::Traceable {
// terminated. Returns how many characters were written into the buffer.
size_t functionDisplayName(RangedPtr<char16_t> destination, size_t length) const;
// Get the size of the respective strings. 0 is returned for null strings.
size_t sourceLength();
size_t functionDisplayNameLength();
// JS::Traceable implementation just forwards to our virtual trace method.
static void trace(StackFrame* frame, JSTracer* trc) {
if (frame)

View File

@ -112,6 +112,37 @@ StackFrame::functionDisplayName(RangedPtr<char16_t> destination, size_t length)
return functionDisplayName().match(m);
}
struct LengthMatcher
{
using ReturnType = size_t;
size_t
match(JSAtom* atom)
{
return atom ? atom->length() : 0;
}
size_t
match(const char16_t* chars)
{
return chars ? js_strlen(chars) : 0;
}
};
size_t
StackFrame::sourceLength()
{
LengthMatcher m;
return source().match(m);
}
size_t
StackFrame::functionDisplayNameLength()
{
LengthMatcher m;
return functionDisplayName().match(m);
}
// All operations on null ubi::Nodes crash.
const char16_t* Concrete<void>::typeName() const { MOZ_CRASH("null ubi::Node"); }
JS::Zone* Concrete<void>::zone() const { MOZ_CRASH("null ubi::Node"); }