Bug 1662559 - Part 1: Rename NameLocation::fromBinding() -> BindingIter::nameLocation(). r=arai

Differential Revision: https://phabricator.services.mozilla.com/D108283
This commit is contained in:
Jason Orendorff 2021-04-19 19:28:03 +00:00
parent e2c0bc7534
commit 6bf2f324b8
3 changed files with 30 additions and 27 deletions

View File

@ -344,7 +344,7 @@ bool EmitterScope::enterLexical(BytecodeEmitter* bce, ScopeKind kind,
return false;
}
NameLocation loc = NameLocation::fromBinding(bi.kind(), bi.location());
NameLocation loc = bi.nameLocation();
if (!putNameInCache(bce, bi.name(), loc)) {
return false;
}
@ -404,7 +404,7 @@ bool EmitterScope::enterNamedLambda(BytecodeEmitter* bce, FunctionBox* funbox) {
// The lambda name, if not closed over, is accessed via JSOp::Callee and
// not a frame slot. Do not update frame slot information.
NameLocation loc = NameLocation::fromBinding(bi.kind(), bi.location());
NameLocation loc = bi.nameLocation();
if (!putNameInCache(bce, bi.name(), loc)) {
return false;
}
@ -452,7 +452,7 @@ bool EmitterScope::enterFunction(BytecodeEmitter* bce, FunctionBox* funbox) {
return false;
}
NameLocation loc = NameLocation::fromBinding(bi.kind(), bi.location());
NameLocation loc = bi.nameLocation();
NameLocationMap::AddPtr p = cache.lookupForAdd(bi.name());
// The only duplicate bindings that occur are simple formal
@ -503,7 +503,7 @@ bool EmitterScope::enterFunction(BytecodeEmitter* bce, FunctionBox* funbox) {
break;
}
NameLocation loc = NameLocation::fromBinding(bi.kind(), bi.location());
NameLocation loc = bi.nameLocation();
if (loc.kind() == NameLocation::Kind::FrameSlot) {
MOZ_ASSERT(paramFrameSlotEnd <= loc.frameSlot());
paramFrameSlotEnd = loc.frameSlot() + 1;
@ -554,7 +554,7 @@ bool EmitterScope::enterFunctionExtraBodyVar(BytecodeEmitter* bce,
return false;
}
NameLocation loc = NameLocation::fromBinding(bi.kind(), bi.location());
NameLocation loc = bi.nameLocation();
MOZ_ASSERT(bi.kind() == BindingKind::Var);
if (!putNameInCache(bce, bi.name(), loc)) {
return false;
@ -660,7 +660,7 @@ bool EmitterScope::enterGlobal(BytecodeEmitter* bce,
// redeclaration check and initialize these bindings.
if (globalsc->bindings) {
for (ParserBindingIter bi(*globalsc->bindings); bi; bi++) {
NameLocation loc = NameLocation::fromBinding(bi.kind(), bi.location());
NameLocation loc = bi.nameLocation();
if (!putNameInCache(bce, bi.name(), loc)) {
return false;
}
@ -711,7 +711,7 @@ bool EmitterScope::enterEval(BytecodeEmitter* bce, EvalSharedContext* evalsc) {
return false;
}
NameLocation loc = NameLocation::fromBinding(bi.kind(), bi.location());
NameLocation loc = bi.nameLocation();
if (!putNameInCache(bce, bi.name(), loc)) {
return false;
}
@ -765,7 +765,7 @@ bool EmitterScope::enterModule(BytecodeEmitter* bce,
return false;
}
NameLocation loc = NameLocation::fromBinding(bi.kind(), bi.location());
NameLocation loc = bi.nameLocation();
if (!putNameInCache(bce, bi.name(), loc)) {
return false;
}

View File

@ -296,25 +296,6 @@ class NameLocation {
return NameLocation(Kind::DynamicAnnexBVar, BindingKind::Var);
}
static NameLocation fromBinding(BindingKind bindKind,
const BindingLocation& bl) {
switch (bl.kind()) {
case BindingLocation::Kind::Global:
return Global(bindKind);
case BindingLocation::Kind::Argument:
return ArgumentSlot(bl.argumentSlot());
case BindingLocation::Kind::Frame:
return FrameSlot(bindKind, bl.slot());
case BindingLocation::Kind::Environment:
return EnvironmentCoordinate(bindKind, 0, bl.slot());
case BindingLocation::Kind::Import:
return Import();
case BindingLocation::Kind::NamedLambdaCallee:
return NamedLambdaCallee();
}
MOZ_CRASH("Bad BindingKind");
}
bool operator==(const NameLocation& other) const {
return kind_ == other.kind_ && bindingKind_ == other.bindingKind_ &&
hops_ == other.hops_ && slot_ == other.slot_;

View File

@ -1486,6 +1486,28 @@ class BaseAbstractBindingIter {
return BindingKind::Const;
}
js::frontend::NameLocation nameLocation() const {
using js::frontend::NameLocation;
BindingKind bindKind = kind();
BindingLocation bl = location();
switch (bl.kind()) {
case BindingLocation::Kind::Global:
return NameLocation::Global(bindKind);
case BindingLocation::Kind::Argument:
return NameLocation::ArgumentSlot(bl.argumentSlot());
case BindingLocation::Kind::Frame:
return NameLocation::FrameSlot(bindKind, bl.slot());
case BindingLocation::Kind::Environment:
return NameLocation::EnvironmentCoordinate(bindKind, 0, bl.slot());
case BindingLocation::Kind::Import:
return NameLocation::Import();
case BindingLocation::Kind::NamedLambdaCallee:
return NameLocation::NamedLambdaCallee();
}
MOZ_CRASH("Bad BindingKind");
}
bool isTopLevelFunction() const {
MOZ_ASSERT(!done());
bool result = names_[index_].isTopLevelFunction();