From 45cf5b11341a5b14c28fe373bfb5bf10e952e6b9 Mon Sep 17 00:00:00 2001 From: Matthew Gaudet <mgaudet@mozilla.com> Date: Fri, 20 Dec 2019 16:25:16 +0000 Subject: [PATCH] Bug 1604952 - Move RegExpCreationData to Stencil.h r=tcampbell As a side effect of removing a now-cylic-dependency, this rehomes FunctionSytaxKind. Differential Revision: https://phabricator.services.mozilla.com/D57903 --HG-- extra : moz-landing-system : lando --- js/src/frontend/ParseNode.h | 27 ++------------------------- js/src/frontend/Stencil.h | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/js/src/frontend/ParseNode.h b/js/src/frontend/ParseNode.h index cb494997dc8ae..a1239f36e68f0 100644 --- a/js/src/frontend/ParseNode.h +++ b/js/src/frontend/ParseNode.h @@ -10,6 +10,7 @@ #include "mozilla/Attributes.h" #include "mozilla/Variant.h" +#include "frontend/Stencil.h" #include "frontend/Token.h" #include "util/Text.h" #include "vm/BigIntType.h" @@ -586,7 +587,7 @@ inline bool IsTypeofKind(ParseNodeKind kind) { FOR_EACH_PARSENODE_SUBCLASS(DECLARE_CLASS) #undef DECLARE_CLASS -enum class FunctionSyntaxKind { +enum class FunctionSyntaxKind : uint8_t { // A non-arrow function expression. Expression, @@ -1892,30 +1893,6 @@ class BooleanLiteral : public NullaryNode { } }; -// This owns a set of characters, previously syntax checked as a RegExp. Used -// to avoid allocating the RegExp on the GC heap during parsing. -class RegExpCreationData { - UniquePtr<char16_t[], JS::FreePolicy> buf_; - size_t length_ = 0; - JS::RegExpFlags flags_; - - public: - RegExpCreationData() = default; - - MOZ_MUST_USE bool init(JSContext* cx, mozilla::Range<const char16_t> range, - JS::RegExpFlags flags) { - length_ = range.length(); - buf_ = js::DuplicateString(cx, range.begin().get(), range.length()); - if (!buf_) { - return false; - } - flags_ = flags; - return true; - } - - RegExpObject* createRegExp(JSContext* cx) const; -}; - class RegExpLiteral : public ParseNode { mozilla::Variant<mozilla::Nothing, ObjectBox*, RegExpCreationData> data_; diff --git a/js/src/frontend/Stencil.h b/js/src/frontend/Stencil.h index 28b64e2c9d2d6..4a16b05927f60 100644 --- a/js/src/frontend/Stencil.h +++ b/js/src/frontend/Stencil.h @@ -7,9 +7,9 @@ #ifndef frontend_Stencil_h #define frontend_Stencil_h -#include "frontend/ParseNode.h" #include "gc/AllocKind.h" #include "gc/Rooting.h" +#include "js/RegExpFlags.h" #include "vm/JSFunction.h" #include "vm/JSScript.h" @@ -25,6 +25,8 @@ namespace frontend { // // Renaming to use the term stencil more broadly is still in progress. +enum class FunctionSyntaxKind : uint8_t; + // Data used to instantiate the lazy script before script emission. struct LazyScriptCreationData { frontend::AtomVector closedOverBindings; @@ -93,7 +95,7 @@ struct FunctionCreationData { // The Parser uses KeepAtoms to prevent GC from collecting atoms JSAtom* atom = nullptr; - FunctionSyntaxKind kind = FunctionSyntaxKind::Expression; + FunctionSyntaxKind kind; // can't field-initialize and forward declare GeneratorKind generatorKind = GeneratorKind::NotGenerator; FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction; @@ -111,6 +113,30 @@ struct FunctionCreationData { } }; +// This owns a set of characters, previously syntax checked as a RegExp. Used +// to avoid allocating the RegExp on the GC heap during parsing. +class RegExpCreationData { + UniquePtr<char16_t[], JS::FreePolicy> buf_; + size_t length_ = 0; + JS::RegExpFlags flags_; + + public: + RegExpCreationData() = default; + + MOZ_MUST_USE bool init(JSContext* cx, mozilla::Range<const char16_t> range, + JS::RegExpFlags flags) { + length_ = range.length(); + buf_ = js::DuplicateString(cx, range.begin().get(), range.length()); + if (!buf_) { + return false; + } + flags_ = flags; + return true; + } + + RegExpObject* createRegExp(JSContext* cx) const; +}; + } /* namespace frontend */ } /* namespace js */ -- GitLab