Bug 1071646 - Light refactoring of lexical binding helpers in Parser. (r=jorendorff)

This commit is contained in:
Shu-yu Guo 2015-12-09 07:52:58 -08:00
Родитель c72b0e3879
Коммит 53c0e2cad8
2 изменённых файлов: 40 добавлений и 14 удалений

Просмотреть файл

@ -3827,23 +3827,27 @@ Parser<ParseHandler>::noteNameUse(HandlePropertyName name, Node pn)
template <>
bool
Parser<FullParseHandler>::bindUninitialized(BindData<FullParseHandler>* data, ParseNode* pn)
Parser<FullParseHandler>::bindUninitialized(BindData<FullParseHandler>* data, HandlePropertyName name,
ParseNode* pn)
{
MOZ_ASSERT(pn->isKind(PNK_NAME));
RootedPropertyName name(context, pn->pn_atom->asPropertyName());
data->setNameNode(pn);
if (!data->bind(name, this))
return false;
return true;
return data->bind(name, this);
}
template <>
bool
Parser<FullParseHandler>::bindInitialized(BindData<FullParseHandler>* data, ParseNode* pn)
Parser<FullParseHandler>::bindUninitialized(BindData<FullParseHandler>* data, ParseNode* pn)
{
if (!bindUninitialized(data, pn))
RootedPropertyName name(context, pn->name());
return bindUninitialized(data, name, pn);
}
template <>
bool
Parser<FullParseHandler>::bindInitialized(BindData<FullParseHandler>* data, HandlePropertyName name,
ParseNode* pn)
{
if (!bindUninitialized(data, name, pn))
return false;
/*
@ -3864,6 +3868,14 @@ Parser<FullParseHandler>::bindInitialized(BindData<FullParseHandler>* data, Pars
return true;
}
template <>
bool
Parser<FullParseHandler>::bindInitialized(BindData<FullParseHandler>* data, ParseNode* pn)
{
RootedPropertyName name(context, pn->name());
return bindInitialized(data, name, pn);
}
template <>
bool
Parser<FullParseHandler>::checkDestructuringName(BindData<FullParseHandler>* data, ParseNode* expr)
@ -4522,21 +4534,31 @@ CurrentLexicalStaticBlock(ParseContext<FullParseHandler>* pc)
}
template <>
ParseNode*
Parser<FullParseHandler>::makeInitializedLexicalBinding(HandlePropertyName name, bool isConst,
const TokenPos& pos)
bool
Parser<FullParseHandler>::prepareAndBindInitializedLexicalWithNode(HandlePropertyName name,
bool isConst,
ParseNode* pn,
const TokenPos& pos)
{
BindData<FullParseHandler> data(context);
if (!checkAndPrepareLexical(isConst, pos))
return null();
data.initLexical(HoistVars, isConst ? JSOP_DEFCONST : JSOP_DEFLET,
CurrentLexicalStaticBlock(pc), JSMSG_TOO_MANY_LOCALS);
return bindInitialized(&data, name, pn);
}
template <>
ParseNode*
Parser<FullParseHandler>::makeInitializedLexicalBinding(HandlePropertyName name, bool isConst,
const TokenPos& pos)
{
ParseNode* dn = newBindingNode(name, false);
if (!dn)
return null();
handler.setPosition(dn, pos);
if (!bindInitialized(&data, dn))
if (!prepareAndBindInitializedLexicalWithNode(name, isConst, dn, pos))
return null();
return dn;

Просмотреть файл

@ -845,6 +845,8 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter
Node objectLiteral(YieldHandling yieldHandling);
bool checkAndPrepareLexical(bool isConst, const TokenPos& errorPos);
bool prepareAndBindInitializedLexicalWithNode(HandlePropertyName name, bool isConst,
ParseNode* pn, const TokenPos& pos);
Node makeInitializedLexicalBinding(HandlePropertyName name, bool isConst, const TokenPos& pos);
Node newBindingNode(PropertyName* name, bool functionScope, VarContext varContext = HoistVars);
@ -860,7 +862,9 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter
bool checkDestructuringObject(BindData<ParseHandler>* data, Node objectPattern);
bool checkDestructuringName(BindData<ParseHandler>* data, Node expr);
bool bindInitialized(BindData<ParseHandler>* data, HandlePropertyName name, Node pn);
bool bindInitialized(BindData<ParseHandler>* data, Node pn);
bool bindUninitialized(BindData<ParseHandler>* data, HandlePropertyName name, Node pn);
bool bindUninitialized(BindData<ParseHandler>* data, Node pn);
bool makeSetCall(Node node, unsigned errnum);
Node cloneDestructuringDefault(Node opn);