Bug 1428863 - Add and use TokenStreamChars::copyTokenbufTo. r=arai
authorJeff Walden <jwalden@mit.edu>
Wed, 27 Dec 2017 10:21:31 -0500
changeset 399892 6349fe7d8cbf246274f39f14456d2b5a70863217
parent 399891 325b6c9e845e8857d5666beb574970253fd8d574
child 399893 515639ccfaf21f80b52a91544d1f2a219bb11e98
push id33279
push useraciure@mozilla.com
push dateThu, 18 Jan 2018 21:53:37 +0000
treeherdermozilla-central@cffb3cd9dbb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1428863
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1428863 - Add and use TokenStreamChars::copyTokenbufTo. r=arai
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -1117,16 +1117,32 @@ TokenStreamSpecific<CharT, AnyCharsAcces
     // line comments containing a source mapping URL inside a multiline
     // comment. To avoid potentially expensive lookahead and backtracking, we
     // only check for this case if we encounter a '#' character.
 
     return getDisplayURL(isMultiline, shouldWarnDeprecated) &&
            getSourceMappingURL(isMultiline, shouldWarnDeprecated);
 }
 
+template<class AnyCharsAccess>
+MOZ_MUST_USE bool
+TokenStreamChars<char16_t, AnyCharsAccess>::copyTokenbufTo(JSContext* cx,
+                                                           UniquePtr<char16_t[], JS::FreePolicy>* destination)
+{
+    size_t length = tokenbuf.length();
+
+    *destination = cx->make_pod_array<char16_t>(length + 1);
+    if (!*destination)
+        return false;
+
+    PodCopy(destination->get(), tokenbuf.begin(), length);
+    (*destination)[length] = '\0';
+    return true;
+}
+
 template<typename CharT, class AnyCharsAccess>
 MOZ_MUST_USE bool
 TokenStreamSpecific<CharT, AnyCharsAccess>::getDirective(bool isMultiline,
                                                          bool shouldWarnDeprecated,
                                                          const char* directive,
                                                          uint8_t directiveLength,
                                                          const char* errorMsgPragma,
                                                          UniquePtr<char16_t[], JS::FreePolicy>* destination)
@@ -1180,26 +1196,17 @@ TokenStreamSpecific<CharT, AnyCharsAcces
     } while (true);
 
     if (tokenbuf.empty()) {
         // The directive's URL was missing, but this is not quite an
         // exception that we should stop and drop everything for.
         return true;
     }
 
-    size_t length = tokenbuf.length();
-
-    *destination = anyCharsAccess().cx->template make_pod_array<char16_t>(length + 1);
-    if (!*destination)
-        return false;
-
-    PodCopy(destination->get(), tokenbuf.begin(), length);
-    (*destination)[length] = '\0';
-
-    return true;
+    return copyTokenbufTo(anyCharsAccess().cx, destination);
 }
 
 template<typename CharT, class AnyCharsAccess>
 bool
 TokenStreamSpecific<CharT, AnyCharsAccess>::getDisplayURL(bool isMultiline,
                                                           bool shouldWarnDeprecated)
 {
     // Match comments of the form "//# sourceURL=<url>" or
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -972,16 +972,19 @@ class TokenStreamChars<char16_t, AnyChar
     TokenStreamAnyChars& anyChars() {
         return AnyCharsAccess::anyChars(this);
     }
 
     const TokenStreamAnyChars& anyChars() const {
         return AnyCharsAccess::anyChars(this);
     }
 
+    MOZ_MUST_USE bool copyTokenbufTo(JSContext* cx,
+                                     UniquePtr<char16_t[], JS::FreePolicy>* destination);
+
     MOZ_ALWAYS_INLINE bool isMultiUnitCodepoint(char16_t c, uint32_t* codepoint) {
         if (MOZ_LIKELY(!unicode::IsLeadSurrogate(c)))
             return false;
 
         return matchTrailForLeadSurrogate(c, codepoint);
     }
 
     static MOZ_ALWAYS_INLINE JSAtom*
@@ -1062,16 +1065,19 @@ class MOZ_STACK_CLASS TokenStreamSpecifi
 
     using CharsSharedBase::appendMultiUnitCodepointToTokenbuf;
 
     using CharsSharedBase::userbuf;
     using CharsSharedBase::tokenbuf;
 
     using typename CharsSharedBase::Position;
 
+  private:
+    using CharsBase::copyTokenbufTo;
+
   public:
     TokenStreamSpecific(JSContext* cx, const ReadOnlyCompileOptions& options,
                         const CharT* base, size_t length);
 
     TokenStreamAnyChars& anyCharsAccess() {
         return CharsBase::anyChars();
     }