From e1c1277c384c309c2db1055e57c05acb752ffabe Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 13 Aug 2015 13:17:00 -0400 Subject: [PATCH] Bug 1194426 - Add sourceLength and functionDisplayNameLength to JS::ubi::StackFrame. r=sfink --- js/public/UbiNode.h | 4 ++++ js/src/vm/UbiNode.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/js/public/UbiNode.h b/js/public/UbiNode.h index 905fef5389f..32908dfbcb9 100644 --- a/js/public/UbiNode.h +++ b/js/public/UbiNode.h @@ -363,6 +363,10 @@ class StackFrame : public JS::Traceable { // terminated. Returns how many characters were written into the buffer. size_t functionDisplayName(RangedPtr 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) diff --git a/js/src/vm/UbiNode.cpp b/js/src/vm/UbiNode.cpp index d252d612b69..f44ebac6ded 100644 --- a/js/src/vm/UbiNode.cpp +++ b/js/src/vm/UbiNode.cpp @@ -112,6 +112,37 @@ StackFrame::functionDisplayName(RangedPtr 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::typeName() const { MOZ_CRASH("null ubi::Node"); } JS::Zone* Concrete::zone() const { MOZ_CRASH("null ubi::Node"); }