From d0751bba57bf107a2f29583bc5d35cf94d84b82f Mon Sep 17 00:00:00 2001 From: Matthew Gaudet Date: Mon, 2 Dec 2019 20:26:39 +0000 Subject: [PATCH] Bug 1588158 - Add FunctionFlags member to FunctionBox, and delegate relevant queries to it r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D55315 --HG-- extra : moz-landing-system : lando --- js/src/frontend/SharedContext.cpp | 30 +++++---------------- js/src/frontend/SharedContext.h | 43 ++++++++++++------------------- js/src/vm/JSFunction.h | 7 +++++ 3 files changed, 29 insertions(+), 51 deletions(-) diff --git a/js/src/frontend/SharedContext.cpp b/js/src/frontend/SharedContext.cpp index 9248bee82cd0..1776988b00c5 100644 --- a/js/src/frontend/SharedContext.cpp +++ b/js/src/frontend/SharedContext.cpp @@ -117,11 +117,8 @@ bool FunctionBox::atomsAreKept() { return cx_->zone()->hasKeptAtoms(); } FunctionBox::FunctionBox(JSContext* cx, TraceListNode* traceListHead, uint32_t toStringStart, Directives directives, bool extraWarnings, GeneratorKind generatorKind, - FunctionAsyncKind asyncKind, bool isArrow, - bool isNamedLambda, bool isGetter, bool isSetter, - bool isMethod, bool isInterpreted, - bool isInterpretedLazy, - FunctionFlags::FunctionKind kind, JSAtom* explicitName) + FunctionAsyncKind asyncKind, JSAtom* explicitName, + FunctionFlags flags) : ObjectBox(nullptr, traceListHead, TraceListNode::NodeType::Function), SharedContext(cx, Kind::FunctionBox, directives, extraWarnings), enclosingScope_(nullptr), @@ -159,16 +156,9 @@ FunctionBox::FunctionBox(JSContext* cx, TraceListNode* traceListHead, isDerivedClassConstructor_(false), hasThisBinding_(false), hasInnerFunctions_(false), - isArrow_(isArrow), - isNamedLambda_(isNamedLambda), - isGetter_(isGetter), - isSetter_(isSetter), - isMethod_(isMethod), - isInterpreted_(isInterpreted), - isInterpretedLazy_(isInterpretedLazy), - kind_(kind), + nargs_(0), explicitName_(explicitName), - nargs_(0) {} + flags_(flags) {} FunctionBox::FunctionBox(JSContext* cx, TraceListNode* traceListHead, JSFunction* fun, uint32_t toStringStart, @@ -176,10 +166,7 @@ FunctionBox::FunctionBox(JSContext* cx, TraceListNode* traceListHead, GeneratorKind generatorKind, FunctionAsyncKind asyncKind) : FunctionBox(cx, traceListHead, toStringStart, directives, extraWarnings, - generatorKind, asyncKind, fun->isArrow(), - fun->isNamedLambda(), fun->isGetter(), fun->isSetter(), - fun->isMethod(), fun->isInterpreted(), - fun->isInterpretedLazy(), fun->kind(), fun->explicitName()) { + generatorKind, asyncKind, fun->explicitName(), fun->flags()) { gcThing = fun; // Functions created at parse time may be set singleton after parsing and // baked into JIT code, so they must be allocated tenured. They are held by @@ -193,12 +180,7 @@ FunctionBox::FunctionBox(JSContext* cx, TraceListNode* traceListHead, bool extraWarnings, GeneratorKind generatorKind, FunctionAsyncKind asyncKind) : FunctionBox(cx, traceListHead, toStringStart, directives, extraWarnings, - generatorKind, asyncKind, data.get().flags.isArrow(), - data.get().flags.isNamedLambda(data.get().atom), - data.get().flags.isGetter(), data.get().flags.isSetter(), - data.get().flags.isMethod(), data.get().flags.isInterpreted(), - data.get().flags.isInterpretedLazy(), data.get().flags.kind(), - data.get().atom) { + generatorKind, asyncKind, data.get().atom, data.get().flags) { functionCreationData_.emplace(data); } diff --git a/js/src/frontend/SharedContext.h b/js/src/frontend/SharedContext.h index 9e0bc2db6393..c56415b274bd 100644 --- a/js/src/frontend/SharedContext.h +++ b/js/src/frontend/SharedContext.h @@ -328,9 +328,7 @@ class FunctionBox : public ObjectBox, public SharedContext { FunctionBox(JSContext* cx, TraceListNode* traceListHead, uint32_t toStringStart, Directives directives, bool extraWarnings, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, - bool isArrow, bool isNamedLambda, bool isGetter, bool isSetter, - bool isMethod, bool isInterpreted, bool isInterpretedLazy, - FunctionFlags::FunctionKind kind, JSAtom* explicitName); + JSAtom* explicitName, FunctionFlags flags); void initWithEnclosingScope(Scope* enclosingScope, JSFunction* fun); @@ -426,22 +424,11 @@ class FunctionBox : public ObjectBox, public SharedContext { // Whether this function has nested functions. bool hasInnerFunctions_ : 1; - // Whether this function is an arrow function - bool isArrow_ : 1; - - bool isNamedLambda_ : 1; - bool isGetter_ : 1; - bool isSetter_ : 1; - bool isMethod_ : 1; - - bool isInterpreted_ : 1; - bool isInterpretedLazy_ : 1; - - FunctionFlags::FunctionKind kind_; - JSAtom* explicitName_; - uint16_t nargs_; + JSAtom* explicitName_; + FunctionFlags flags_; + mozilla::Maybe lazyScriptData_; mozilla::Maybe& lazyScriptData() { @@ -609,7 +596,7 @@ class FunctionBox : public ObjectBox, public SharedContext { bool needsIteratorResult() const { return isGenerator() && !isAsync(); } bool needsPromiseResult() const { return isAsync() && !isGenerator(); } - bool isArrow() const { return isArrow_; } + bool isArrow() const { return flags_.isArrow(); } bool isLambda() const { if (hasObject()) { return function()->isLambda(); @@ -633,16 +620,18 @@ class FunctionBox : public ObjectBox, public SharedContext { bool needsHomeObject() const { return needsHomeObject_; } bool isDerivedClassConstructor() const { return isDerivedClassConstructor_; } bool hasInnerFunctions() const { return hasInnerFunctions_; } - bool isNamedLambda() const { return isNamedLambda_; } - bool isGetter() const { return isGetter_; } - bool isSetter() const { return isSetter_; } - bool isMethod() const { return isMethod_; } + bool isNamedLambda() const { return flags_.isNamedLambda(explicitName()); } + bool isGetter() const { return flags_.isGetter(); } + bool isSetter() const { return flags_.isSetter(); } + bool isMethod() const { return flags_.isMethod(); } - bool isInterpreted() const { return isInterpreted_; } - void setIsInterpreted(bool interpreted) { isInterpreted_ = interpreted; } - bool isInterpretedLazy() const { return isInterpretedLazy_; } + bool isInterpreted() const { return flags_.isInterpreted(); } + void setIsInterpreted(bool interpreted) { + flags_.setFlags(FunctionFlags::INTERPRETED, interpreted); + } + bool isInterpretedLazy() const { return flags_.isInterpretedLazy(); } void setIsInterpretedLazy(bool interpretedLazy) { - isInterpretedLazy_ = interpretedLazy; + flags_.setFlags(FunctionFlags::INTERPRETED_LAZY, interpretedLazy); } void initLazyScript(LazyScript* script) { @@ -650,7 +639,7 @@ class FunctionBox : public ObjectBox, public SharedContext { setIsInterpretedLazy(function()->isInterpretedLazy()); } - FunctionFlags::FunctionKind kind() { return kind_; } + FunctionFlags::FunctionKind kind() { return flags_.kind(); } JSAtom* explicitName() const { return explicitName_; } diff --git a/js/src/vm/JSFunction.h b/js/src/vm/JSFunction.h index 2919da5c6a91..6bf1d7d49afd 100644 --- a/js/src/vm/JSFunction.h +++ b/js/src/vm/JSFunction.h @@ -147,6 +147,13 @@ class FunctionFlags { bool hasFlags(uint16_t flags) const { return flags_ & flags; } void setFlags(uint16_t flags) { flags_ |= flags; } void clearFlags(uint16_t flags) { flags_ &= ~flags; } + void setFlags(uint16_t flags, bool set) { + if (set) { + setFlags(flags); + } else { + clearFlags(flags); + } + } FunctionKind kind() const { return static_cast((flags_ & FUNCTION_KIND_MASK) >>