Bug 1342483 - Add JSScript::needsBodyEnvironment
MozReview-Commit-ID: ETGQtw2sIGJ
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -300,27 +300,16 @@ class TryFinallyControl : public Bytecod
emittingSubroutine_ = true;
}
bool emittingSubroutine() const {
return emittingSubroutine_;
}
};
-static bool
-ScopeKindIsInBody(ScopeKind kind)
-{
- return kind == ScopeKind::Lexical ||
- kind == ScopeKind::SimpleCatch ||
- kind == ScopeKind::Catch ||
- kind == ScopeKind::With ||
- kind == ScopeKind::FunctionBodyVar ||
- kind == ScopeKind::ParameterExpressionVar;
-}
-
static inline void
MarkAllBindingsClosedOver(LexicalScope::Data& data)
{
BindingName* names = data.names;
for (uint32_t i = 0; i < data.length; i++)
names[i] = BindingName(names[i].name(), true);
}
--- a/js/src/jsscript.h
+++ b/js/src/jsscript.h
@@ -1629,16 +1629,25 @@ class JSScript : public js::gc::TenuredC
for (uint32_t i = 0; i < scopes()->length; i++) {
js::Scope* scope = getScope(i);
if (scope->kind() == js::ScopeKind::FunctionBodyVar)
return &scope->as<js::VarScope>();
}
MOZ_CRASH("Function extra body var scope not found");
}
+ bool needsBodyEnvironment() const {
+ for (uint32_t i = 0; i < scopes()->length; i++) {
+ js::Scope* scope = getScope(i);
+ if (ScopeKindIsInBody(scope->kind()) && scope->hasEnvironment())
+ return true;
+ }
+ return false;
+ }
+
inline js::LexicalScope* maybeNamedLambdaScope() const;
js::Scope* enclosingScope() const {
return outermostScope()->enclosing();
}
private:
bool makeTypes(JSContext* cx);
--- a/js/src/vm/Scope.h
+++ b/js/src/vm/Scope.h
@@ -78,16 +78,27 @@ enum class ScopeKind : uint8_t
};
static inline bool
ScopeKindIsCatch(ScopeKind kind)
{
return kind == ScopeKind::SimpleCatch || kind == ScopeKind::Catch;
}
+static inline bool
+ScopeKindIsInBody(ScopeKind kind)
+{
+ return kind == ScopeKind::Lexical ||
+ kind == ScopeKind::SimpleCatch ||
+ kind == ScopeKind::Catch ||
+ kind == ScopeKind::With ||
+ kind == ScopeKind::FunctionBodyVar ||
+ kind == ScopeKind::ParameterExpressionVar;
+}
+
const char* BindingKindString(BindingKind kind);
const char* ScopeKindString(ScopeKind kind);
class BindingName
{
// A JSAtom* with its low bit used as a tag for whether it is closed over
// (i.e., exists in the environment shape).
uintptr_t bits_;