Bug 1619177 - Remove extra warnings from the frontend. r=arai

We eliminate a bunch of extra warnings that seem vaguely useful.
However with us rewriting the parser anyway, we will just keep that
in mind for later.

Differential Revision: https://phabricator.services.mozilla.com/D65712
This commit is contained in:
Tom Schuster committed 2020-03-10 22:53:12 +00:00
1 parent 228063b355
commit 14134274f1
24 files changed
+58 -492

No files matched your search

+2 -4
View File
@@ -334,8 +334,7 @@ static bool EvalKernel(JSContext* cx, HandleValue v, EvalType evalType,
}
frontend::EvalSharedContext evalsc(cx, env, compilationInfo, enclosing,
compilationInfo.directives,
options.extraWarningsOption);
compilationInfo.directives);
RootedScript compiled(
cx, frontend::CompileEvalScript(compilationInfo, evalsc, env, srcBuf));
if (!compiled) {
@@ -434,8 +433,7 @@ bool js::DirectEvalStringFromIon(JSContext* cx, HandleObject env,
}
frontend::EvalSharedContext evalsc(cx, env, compilationInfo, enclosing,
compilationInfo.directives,
options.extraWarningsOption);
compilationInfo.directives);
JSScript* compiled =
frontend::CompileEvalScript(compilationInfo, evalsc, env, srcBuf);
if (!compiled) {
+3 -5
View File
@@ -1002,8 +1002,7 @@ static bool EvaluateInEnv(JSContext* cx, Handle<Env*> env,
}
frontend::EvalSharedContext evalsc(cx, env, compilationInfo, scope,
compilationInfo.directives,
options.extraWarningsOption);
compilationInfo.directives);
script = frontend::CompileEvalScript(compilationInfo, evalsc, env, srcBuf);
if (!script) {
return false;
@@ -1023,9 +1022,8 @@ static bool EvaluateInEnv(JSContext* cx, Handle<Env*> env,
MOZ_ASSERT(scopeKind == ScopeKind::Global ||
scopeKind == ScopeKind::NonSyntactic);
frontend::GlobalSharedContext globalsc(
cx, scopeKind, compilationInfo, compilationInfo.directives,
compilationInfo.options.extraWarningsOption);
frontend::GlobalSharedContext globalsc(cx, scopeKind, compilationInfo,
compilationInfo.directives);
script = frontend::CompileGlobalScript(compilationInfo, globalsc, srcBuf);
if (!script) {
return false;
+1 -2
View File
@@ -280,8 +280,7 @@ JS::Result<FunctionBox*> BinASTParserPerTokenizer<Tok>::buildFunctionBox(
auto* funbox = alloc_.new_<FunctionBox>(
cx_, traceListHead_, fun, /* toStringStart = */ 0, getCompilationInfo(),
*directives,
/* extraWarning = */ false, generatorKind, functionAsyncKind);
*directives, generatorKind, functionAsyncKind);
if (MOZ_UNLIKELY(!funbox)) {
return raiseOOM();
}
+1 -2
View File
@@ -752,8 +752,7 @@ static JSScript* CompileGlobalBinASTScriptImpl(
}
GlobalSharedContext globalsc(cx, ScopeKind::Global, compilationInfo,
compilationInfo.directives,
compilationInfo.options.extraWarningsOption);
compilationInfo.directives);
frontend::BinASTParser<ParserT> parser(cx, compilationInfo, options,
compilationInfo.sourceObject);
-61
View File
@@ -1612,34 +1612,6 @@ void BytecodeEmitter::reportError(const Maybe<uint32_t>& maybeOffset,
va_end(args);
}
bool BytecodeEmitter::reportExtraWarning(ParseNode* pn, unsigned errorNumber,
...) {
uint32_t offset = pn ? pn->pn_pos.begin : *scriptStartOffset;
va_list args;
va_start(args, errorNumber);
bool result = parser->errorReporter().extraWarningWithNotesAtVA(
nullptr, AsVariant(offset), errorNumber, &args);
va_end(args);
return result;
}
bool BytecodeEmitter::reportExtraWarning(const Maybe<uint32_t>& maybeOffset,
unsigned errorNumber, ...) {
uint32_t offset = maybeOffset ? *maybeOffset : *scriptStartOffset;
va_list args;
va_start(args, errorNumber);
bool result = parser->errorReporter().extraWarningWithNotesAtVA(
nullptr, AsVariant(offset), errorNumber, &args);
va_end(args);
return result;
}
bool BytecodeEmitter::iteratorResultShape(uint32_t* shape) {
// Use |NoValues| to keep the flags consistent with their usage for normal
// object literal creation, where |NoValues| is always used in conjunction
@@ -6584,39 +6556,6 @@ bool BytecodeEmitter::emitExpressionStatement(UnaryNode* exprStmt) {
if (!ese.emitEnd()) {
return false;
}
} else if (exprStmt->isDirectivePrologueMember()) {
// Don't complain about directive prologue members; just don't emit
// their code.
} else {
if (JSAtom* atom = exprStmt->isStringExprStatement()) {
// Warn if encountering a non-directive prologue member string
// expression statement, that is inconsistent with the current
// directive prologue. That is, a script *not* starting with
// "use strict" should warn for any "use strict" statements seen
// later in the script, because such statements are misleading.
const char* directive = nullptr;
if (atom == cx->names().useStrict) {
if (!sc->strictScript) {
directive = js_useStrict_str;
}
} else if (atom == cx->names().useAsm) {
if (sc->isFunctionBox()) {
if (IsAsmJSModule(sc->asFunctionBox()->function())) {
directive = js_useAsm_str;
}
}
}
if (directive) {
if (!reportExtraWarning(expr, JSMSG_CONTRARY_NONDIRECTIVE, directive)) {
return false;
}
}
} else {
if (!reportExtraWarning(expr, JSMSG_USELESS_EXPR)) {
return false;
}
}
}
return true;
-3
View File
@@ -326,9 +326,6 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
void reportError(ParseNode* pn, unsigned errorNumber, ...);
void reportError(const mozilla::Maybe<uint32_t>& maybeOffset,
unsigned errorNumber, ...);
bool reportExtraWarning(ParseNode* pn, unsigned errorNumber, ...);
bool reportExtraWarning(const mozilla::Maybe<uint32_t>& maybeOffset,
unsigned errorNumber, ...);
// If pn contains a useful expression, return true with *answer set to true.
// If pn contains a useless expression, return true with *answer set to
+5 -111
View File
@@ -242,105 +242,6 @@ class ErrorReportMixin : public StrictModeGetter {
JSREPORT_WARNING, errorNumber, args);
}
// ==== extraWarning ====
//
// Reports a warning if extra warnings are enabled.
//
// Returns true if the warning is reported.
// Returns false if the warning is treated as an error, or an error occurs
// while reporting.
//
// See the comment on the error section for details on what the arguments
// and function names indicate for all these functions.
MOZ_MUST_USE bool extraWarning(unsigned errorNumber, ...) {
va_list args;
va_start(args, errorNumber);
bool result = extraWarningWithNotesAtVA(
nullptr, mozilla::AsVariant(Current()), errorNumber, &args);
va_end(args);
return result;
}
MOZ_MUST_USE bool extraWarningWithNotes(UniquePtr<JSErrorNotes> notes,
unsigned errorNumber, ...) {
va_list args;
va_start(args, errorNumber);
bool result = extraWarningWithNotesAtVA(
std::move(notes), mozilla::AsVariant(Current()), errorNumber, &args);
va_end(args);
return result;
}
MOZ_MUST_USE bool extraWarningAt(uint32_t offset, unsigned errorNumber, ...) {
va_list args;
va_start(args, errorNumber);
bool result = extraWarningWithNotesAtVA(nullptr, mozilla::AsVariant(offset),
errorNumber, &args);
va_end(args);
return result;
}
MOZ_MUST_USE bool extraWarningWithNotesAt(UniquePtr<JSErrorNotes> notes,
uint32_t offset,
unsigned errorNumber, ...) {
va_list args;
va_start(args, errorNumber);
bool result = extraWarningWithNotesAtVA(
std::move(notes), mozilla::AsVariant(offset), errorNumber, &args);
va_end(args);
return result;
}
MOZ_MUST_USE bool extraWarningNoOffset(unsigned errorNumber, ...) {
va_list args;
va_start(args, errorNumber);
bool result = extraWarningWithNotesAtVA(
nullptr, mozilla::AsVariant(NoOffset()), errorNumber, &args);
va_end(args);
return result;
}
MOZ_MUST_USE bool extraWarningWithNotesNoOffset(UniquePtr<JSErrorNotes> notes,
unsigned errorNumber, ...) {
va_list args;
va_start(args, errorNumber);
bool result = extraWarningWithNotesAtVA(
std::move(notes), mozilla::AsVariant(NoOffset()), errorNumber, &args);
va_end(args);
return result;
}
MOZ_MUST_USE bool extraWarningWithNotesAtVA(UniquePtr<JSErrorNotes> notes,
const ErrorOffset& offset,
unsigned errorNumber,
va_list* args) {
if (!options().extraWarningsOption) {
return true;
}
ErrorMetadata metadata;
if (!computeErrorMetadata(&metadata, offset)) {
return false;
}
return compileWarning(std::move(metadata), std::move(notes),
JSREPORT_STRICT | JSREPORT_WARNING, errorNumber,
args);
}
// ==== strictModeError ====
//
// Reports an error if in strict mode code, or warn if not.
@@ -426,8 +327,7 @@ class ErrorReportMixin : public StrictModeGetter {
const ErrorOffset& offset,
unsigned errorNumber,
va_list* args) {
bool strict = strictMode();
if (!strict && !options().extraWarningsOption) {
if (!strictMode()) {
return true;
}
@@ -436,16 +336,10 @@ class ErrorReportMixin : public StrictModeGetter {
return false;
}
if (strict) {
ReportCompileErrorLatin1(getContext(), std::move(metadata),
std::move(notes), JSREPORT_ERROR, errorNumber,
args);
return false;
}
return compileWarning(std::move(metadata), std::move(notes),
JSREPORT_WARNING | JSREPORT_STRICT, errorNumber,
args);
ReportCompileErrorLatin1(getContext(), std::move(metadata),
std::move(notes), JSREPORT_ERROR, errorNumber,
args);
return false;
}
// Reports a warning, or an error if the warning is treated as an error.
-3
View File
@@ -1007,9 +1007,6 @@ class FullParseHandler {
MOZ_MUST_USE NodeType setLikelyIIFE(NodeType node) {
return parenthesize(node);
}
void setInDirectivePrologue(UnaryNodeType exprStmt) {
exprStmt->setIsDirectivePrologueMember();
}
bool isName(Node node) { return node->isKind(ParseNodeKind::Name); }
+1 -10
View File
@@ -377,8 +377,6 @@ inline bool IsTypeofKind(ParseNodeKind kind) {
* kid: returned expression, or null if none
* ExpressionStmt (UnaryNode)
* kid: expr
* prologue: true if Directive Prologue member in original source, not
* introduced via constant folding or other tree rewriting
* EmptyStmt (NullaryNode)
* (no fields)
* LabelStmt (LabeledStatement)
@@ -884,11 +882,10 @@ inline bool ParseNode::isName(PropertyName* name) const {
class UnaryNode : public ParseNode {
ParseNode* kid_;
bool prologue; /* directive prologue member */
public:
UnaryNode(ParseNodeKind kind, const TokenPos& pos, ParseNode* kid)
: ParseNode(kind, pos), kid_(kid), prologue(false) {
: ParseNode(kind, pos), kid_(kid) {
MOZ_ASSERT(is<UnaryNode>());
}
@@ -914,11 +911,6 @@ class UnaryNode : public ParseNode {
ParseNode* kid() const { return kid_; }
/* Return true if this node appears in a Directive Prologue. */
bool isDirectivePrologueMember() const { return prologue; }
void setIsDirectivePrologueMember() { prologue = true; }
/*
* Non-null if this is a statement node which could be a member of a
* Directive Prologue: an expression statement consisting of a single
@@ -2292,7 +2284,6 @@ inline bool ParseNode::isConstant() {
enum ParseReportKind {
ParseError,
ParseWarning,
ParseExtraWarning,
ParseStrictError
};
+7 -50
View File
@@ -273,8 +273,7 @@ FunctionBox* PerHandlerParser<ParseHandler>::newFunctionBox(
*/
FunctionBox* funbox = alloc_.new_<FunctionBox>(
cx_, traceListHead_, fun, toStringStart, this->getCompilationInfo(),
inheritedDirectives, options().extraWarningsOption, generatorKind,
asyncKind);
inheritedDirectives, generatorKind, asyncKind);
if (!funbox) {
ReportOutOfMemory(cx_);
return nullptr;
@@ -307,8 +306,7 @@ FunctionBox* PerHandlerParser<ParseHandler>::newFunctionBox(
*/
FunctionBox* funbox = alloc_.new_<FunctionBox>(
cx_, traceListHead_, toStringStart, this->getCompilationInfo(),
inheritedDirectives, options().extraWarningsOption, generatorKind,
asyncKind, index);
inheritedDirectives, generatorKind, asyncKind, index);
if (!funbox) {
ReportOutOfMemory(cx_);
@@ -381,8 +379,7 @@ typename ParseHandler::ListNodeType GeneralParser<ParseHandler, Unit>::parse() {
Directives directives(options().forceStrictMode());
GlobalSharedContext globalsc(cx_, ScopeKind::Global,
this->getCompilationInfo(), directives,
options().extraWarningsOption);
this->getCompilationInfo(), directives);
SourceParseContext globalpc(this, &globalsc, /* newDirectives = */ nullptr);
if (!globalpc.init()) {
return null();
@@ -3529,18 +3526,6 @@ bool GeneralParser<ParseHandler, Unit>::maybeParseDirective(
}
if (IsEscapeFreeStringLiteral(directivePos, directive)) {
// Mark this statement as being a possibly legitimate part of a
// directive prologue, so the bytecode emitter won't warn about it being
// useless code. (We mustn't just omit the statement entirely yet, as it
// could be producing the value of an eval or JSScript execution.)
//
// Note that even if the string isn't one we recognize as a directive,
// the emitter still shouldn't flag it as useless, as it could become a
// directive in the future. We don't want to interfere with people
// taking advantage of directive-prologue-enabled features that appear
// in other browsers first.
handler_.setInDirectivePrologue(handler_.asUnary(possibleDirective));
if (directive == cx_->names().useStrict) {
// Functions with non-simple parameter lists (destructuring,
// default or rest parameters) must not contain a "use strict"
@@ -3677,12 +3662,6 @@ typename ParseHandler::Node GeneralParser<ParseHandler, Unit>::condition(
return null();
}
/* Check for (a = b) and warn about possible (a == b) mistype. */
if (handler_.isUnparenthesizedAssignment(pn)) {
if (!extraWarning(JSMSG_EQUAL_AS_ASSIGN)) {
return null();
}
}
return pn;
}
@@ -3790,17 +3769,6 @@ bool GeneralParser<ParseHandler, Unit>::PossibleError::checkForError(
return false;
}
template <class ParseHandler, typename Unit>
bool GeneralParser<ParseHandler, Unit>::PossibleError::checkForWarning(
ErrorKind kind) {
if (!hasError(kind)) {
return true;
}
Error& err = error(kind);
return parser_.extraWarningAt(err.offset_, err.errorNumber_);
}
template <class ParseHandler, typename Unit>
bool GeneralParser<ParseHandler,
Unit>::PossibleError::checkForDestructuringErrorOrWarning() {
@@ -3808,16 +3776,15 @@ bool GeneralParser<ParseHandler,
// expression context.
setResolved(ErrorKind::Expression);
// Report any pending destructuring error or warning.
return checkForError(ErrorKind::Destructuring) &&
checkForWarning(ErrorKind::DestructuringWarning);
// Report any pending destructuring error.
return checkForError(ErrorKind::Destructuring);
}
template <class ParseHandler, typename Unit>
bool GeneralParser<ParseHandler,
Unit>::PossibleError::checkForExpressionError() {
// Clear pending destructuring error or warning, because we're definitely
// not in a destructuring context.
// Clear pending destructuring error, because we're definitely not
// in a destructuring context.
setResolved(ErrorKind::Destructuring);
setResolved(ErrorKind::DestructuringWarning);
@@ -5754,11 +5721,6 @@ GeneralParser<ParseHandler, Unit>::ifStatement(YieldHandling yieldHandling) {
if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
return null();
}
if (tt == TokenKind::Semi) {
if (!extraWarning(JSMSG_EMPTY_CONSEQUENT)) {
return null();
}
}
Node thenBranch = consequentOrAlternative(yieldHandling);
if (!thenBranch) {
@@ -6511,11 +6473,6 @@ GeneralParser<ParseHandler, Unit>::withStatement(YieldHandling yieldHandling) {
MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::With));
uint32_t begin = pos().begin;
// Usually we want the constructs forbidden in strict mode code to be a
// subset of those that ContextOptions::extraWarnings() warns about, and we
// use strictModeError directly. But while 'with' is forbidden in strict
// mode code, it doesn't even merit a warning in non-strict code. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=514576#c1.
if (pc_->sc()->strict()) {
if (!strictModeError(JSMSG_STRICT_CODE_WITH)) {
return null();
+3 -42
View File
@@ -369,12 +369,6 @@ class MOZ_STACK_CLASS ParserBase : public ParserSharedBase,
using Base::errorWithNotes;
using Base::errorWithNotesAt;
using Base::errorWithNotesNoOffset;
using Base::extraWarning;
using Base::extraWarningAt;
using Base::extraWarningNoOffset;
using Base::extraWarningWithNotes;
using Base::extraWarningWithNotesAt;
using Base::extraWarningWithNotesNoOffset;
using Base::strictModeError;
using Base::strictModeErrorAt;
using Base::strictModeErrorNoOffset;
@@ -512,14 +506,9 @@ class MOZ_STACK_CLASS PerHandlerParser : public ParserBase {
GeneralParser<SyntaxParseHandler, Unit>* syntaxParser,
BaseScript* lazyOuterFunction,
ScriptSourceObject* sourceObject)
: PerHandlerParser(
cx, options, foldConstants, compilationInfo, lazyOuterFunction,
sourceObject,
// JSOPTION_EXTRA_WARNINGS adds extra warnings not
// generated when functions are parsed lazily.
// ("use strict" doesn't inhibit lazy parsing.)
static_cast<void*>(options.extraWarningsOption ? nullptr
: syntaxParser)) {}
: PerHandlerParser(cx, options, foldConstants, compilationInfo,
lazyOuterFunction, sourceObject,
static_cast<void*>(syntaxParser)) {}
static typename ParseHandler::NullNode null() { return ParseHandler::null(); }
@@ -626,12 +615,6 @@ class MOZ_STACK_CLASS PerHandlerParser : public ParserBase {
using Base::errorWithNotes;
using Base::errorWithNotesAt;
using Base::errorWithNotesNoOffset;
using Base::extraWarning;
using Base::extraWarningAt;
using Base::extraWarningNoOffset;
using Base::extraWarningWithNotes;
using Base::extraWarningWithNotesAt;
using Base::extraWarningWithNotesNoOffset;
using Base::strictModeError;
using Base::strictModeErrorAt;
using Base::strictModeErrorNoOffset;
@@ -783,12 +766,6 @@ class MOZ_STACK_CLASS GeneralParser : public PerHandlerParser<ParseHandler> {
using Base::errorWithNotes;
using Base::errorWithNotesAt;
using Base::errorWithNotesNoOffset;
using Base::extraWarning;
using Base::extraWarningAt;
using Base::extraWarningNoOffset;
using Base::extraWarningWithNotes;
using Base::extraWarningWithNotesAt;
using Base::extraWarningWithNotesNoOffset;
using Base::strictModeError;
using Base::strictModeErrorAt;
using Base::strictModeErrorNoOffset;
@@ -915,10 +892,6 @@ class MOZ_STACK_CLASS GeneralParser : public PerHandlerParser<ParseHandler> {
// return true.
MOZ_MUST_USE bool checkForError(ErrorKind kind);
// If there is a pending warning, report it and return either false or
// true depending on the werror option, otherwise return true.
MOZ_MUST_USE bool checkForWarning(ErrorKind kind);
// Transfer an existing error to another instance.
void transferErrorTo(ErrorKind kind, PossibleError* other);
@@ -1528,12 +1501,6 @@ class MOZ_STACK_CLASS Parser<SyntaxParseHandler, Unit> final
using Base::errorWithNotes;
using Base::errorWithNotesAt;
using Base::errorWithNotesNoOffset;
using Base::extraWarning;
using Base::extraWarningAt;
using Base::extraWarningNoOffset;
using Base::extraWarningWithNotes;
using Base::extraWarningWithNotesAt;
using Base::extraWarningWithNotesNoOffset;
using Base::strictModeError;
using Base::strictModeErrorAt;
using Base::strictModeErrorNoOffset;
@@ -1676,12 +1643,6 @@ class MOZ_STACK_CLASS Parser<FullParseHandler, Unit> final
using Base::errorWithNotes;
using Base::errorWithNotesAt;
using Base::errorWithNotesNoOffset;
using Base::extraWarning;
using Base::extraWarningAt;
using Base::extraWarningNoOffset;
using Base::extraWarningWithNotes;
using Base::extraWarningWithNotesAt;
using Base::extraWarningWithNotesNoOffset;
using Base::strictModeError;
using Base::strictModeErrorAt;
using Base::strictModeErrorNoOffset;
+9 -10
View File
@@ -76,8 +76,8 @@ void SharedContext::computeInWith(Scope* scope) {
EvalSharedContext::EvalSharedContext(JSContext* cx, JSObject* enclosingEnv,
CompilationInfo& compilationInfo,
Scope* enclosingScope,
Directives directives, bool extraWarnings)
: SharedContext(cx, Kind::Eval, compilationInfo, directives, extraWarnings),
Directives directives)
: SharedContext(cx, Kind::Eval, compilationInfo, directives),
enclosingScope_(cx, enclosingScope),
bindings(cx) {
computeAllowSyntax(enclosingScope);
@@ -119,12 +119,11 @@ bool FunctionBox::atomsAreKept() { return cx_->zone()->hasKeptAtoms(); }
FunctionBox::FunctionBox(JSContext* cx, FunctionBox* traceListHead,
uint32_t toStringStart,
CompilationInfo& compilationInfo,
Directives directives, bool extraWarnings,
Directives directives,
GeneratorKind generatorKind,
FunctionAsyncKind asyncKind, JSAtom* explicitName,
FunctionFlags flags)
: SharedContext(cx, Kind::FunctionBox, compilationInfo, directives,
extraWarnings),
: SharedContext(cx, Kind::FunctionBox, compilationInfo, directives),
object_(nullptr),
traceLink_(traceListHead),
emitLink_(nullptr),
@@ -164,11 +163,11 @@ FunctionBox::FunctionBox(JSContext* cx, FunctionBox* traceListHead,
FunctionBox::FunctionBox(JSContext* cx, FunctionBox* traceListHead,
JSFunction* fun, uint32_t toStringStart,
CompilationInfo& compilationInfo,
Directives directives, bool extraWarnings,
Directives directives,
GeneratorKind generatorKind,
FunctionAsyncKind asyncKind)
: FunctionBox(cx, traceListHead, toStringStart, compilationInfo, directives,
extraWarnings, generatorKind, asyncKind, fun->explicitName(),
generatorKind, asyncKind, fun->explicitName(),
fun->flags()) {
object_ = fun;
// Functions created at parse time may be set singleton after parsing and
@@ -180,11 +179,11 @@ FunctionBox::FunctionBox(JSContext* cx, FunctionBox* traceListHead,
FunctionBox::FunctionBox(JSContext* cx, FunctionBox* traceListHead,
uint32_t toStringStart,
CompilationInfo& compilationInfo,
Directives directives, bool extraWarnings,
Directives directives,
GeneratorKind generatorKind,
FunctionAsyncKind asyncKind, size_t index)
: FunctionBox(cx, traceListHead, toStringStart, compilationInfo, directives,
extraWarnings, generatorKind, asyncKind,
generatorKind, asyncKind,
compilationInfo.funcData[index].get().atom,
compilationInfo.funcData[index].get().flags) {
funcDataIndex_.emplace(index);
@@ -345,7 +344,7 @@ ModuleSharedContext::ModuleSharedContext(JSContext* cx, ModuleObject* module,
CompilationInfo& compilationInfo,
Scope* enclosingScope,
ModuleBuilder& builder)
: SharedContext(cx, Kind::Module, compilationInfo, Directives(true), false),
: SharedContext(cx, Kind::Module, compilationInfo, Directives(true)),
module_(cx, module),
enclosingScope_(cx, enclosingScope),
bindings(cx),
+8 -12
View File
@@ -115,7 +115,6 @@ class SharedContext {
public:
bool strictScript : 1;
bool localStrict : 1;
bool extraWarnings : 1;
protected:
bool allowNewTarget_ : 1;
@@ -165,14 +164,13 @@ class SharedContext {
public:
SharedContext(JSContext* cx, Kind kind, CompilationInfo& compilationInfo,
Directives directives, bool extraWarnings)
Directives directives)
: cx_(cx),
kind_(kind),
compilationInfo_(compilationInfo),
thisBinding_(ThisBinding::Global),
strictScript(directives.strict()),
localStrict(false),
extraWarnings(extraWarnings),
allowNewTarget_(false),
allowSuperProperty_(false),
allowSuperCall_(false),
@@ -249,7 +247,7 @@ class SharedContext {
}
// JSOPTION_EXTRA_WARNINGS warnings or strict mode errors.
bool needStrictChecks() const { return strict() || extraWarnings; }
bool needStrictChecks() const { return strict(); }
};
class MOZ_STACK_CLASS GlobalSharedContext : public SharedContext {
@@ -259,10 +257,8 @@ class MOZ_STACK_CLASS GlobalSharedContext : public SharedContext {
Rooted<GlobalScope::Data*> bindings;
GlobalSharedContext(JSContext* cx, ScopeKind scopeKind,
CompilationInfo& compilationInfo, Directives directives,
bool extraWarnings)
: SharedContext(cx, Kind::Global, compilationInfo, directives,
extraWarnings),
CompilationInfo& compilationInfo, Directives directives)
: SharedContext(cx, Kind::Global, compilationInfo, directives),
scopeKind_(scopeKind),
bindings(cx) {
MOZ_ASSERT(scopeKind == ScopeKind::Global ||
@@ -288,7 +284,7 @@ class MOZ_STACK_CLASS EvalSharedContext : public SharedContext {
EvalSharedContext(JSContext* cx, JSObject* enclosingEnv,
CompilationInfo& compilationInfo, Scope* enclosingScope,
Directives directives, bool extraWarnings);
Directives directives);
Scope* compilationEnclosingScope() const override { return enclosingScope_; }
};
@@ -341,7 +337,7 @@ class FunctionBox : public SharedContext {
FunctionBox(JSContext* cx, FunctionBox* traceListHead, uint32_t toStringStart,
CompilationInfo& compilationInfo, Directives directives,
bool extraWarnings, GeneratorKind generatorKind,
GeneratorKind generatorKind,
FunctionAsyncKind asyncKind, JSAtom* explicitName,
FunctionFlags flags);
@@ -445,12 +441,12 @@ class FunctionBox : public SharedContext {
FunctionBox(JSContext* cx, FunctionBox* traceListHead, JSFunction* fun,
uint32_t toStringStart, CompilationInfo& compilationInfo,
Directives directives, bool extraWarnings,
Directives directives,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind);
FunctionBox(JSContext* cx, FunctionBox* traceListHead, uint32_t toStringStart,
CompilationInfo& compilationInfo, Directives directives,
bool extraWarnings, GeneratorKind generatorKind,
GeneratorKind generatorKind,
FunctionAsyncKind asyncKind, size_t functionIndex);
#ifdef DEBUG
+3 -10
View File
@@ -118,15 +118,9 @@ class SyntaxParseHandler {
// |("use strict");| as a useless statement.
NodeUnparenthesizedString,
// Assignment expressions in condition contexts could be typos for
// equality checks. (Think |if (x = y)| versus |if (x == y)|.) Thus
// we need this to treat |if (x = y)| as a possible typo and
// |if ((x = y))| as a deliberate assignment within a condition.
//
// (Technically this isn't needed, as these are *only* extraWarnings
// warnings, and parsing with that option disables syntax parsing. But
// it seems best to be consistent, and perhaps the syntax parser will
// eventually enforce extraWarnings and will require this then.)
// For destructuring patterns an assignment element with
// an initializer expression is not allowed be parenthesized.
// i.e. |{x = 1} = obj|
NodeUnparenthesizedAssignment,
// This node is necessary to determine if the base operand in an
@@ -669,7 +663,6 @@ class SyntaxParseHandler {
MOZ_MUST_USE NodeType setLikelyIIFE(NodeType node) {
return node; // Remain in syntax-parse mode.
}
void setInDirectivePrologue(UnaryNodeType exprStmt) {}
bool isName(Node node) {
return node == NodeName || node == NodeArgumentsName ||
+1 -1
View File
@@ -57,7 +57,7 @@ static int testBinASTReaderFuzz(const uint8_t* buf, size_t size) {
Directives directives(false);
GlobalSharedContext globalsc(gCx, ScopeKind::Global, binCompilationInfo,
directives, false);
directives);
BinASTParser<js::frontend::BinASTTokenReaderMultipart> reader(
gCx, binCompilationInfo, options, binCompilationInfo.sourceObject);
-2
View File
@@ -235,7 +235,6 @@ MSG_DEF(JSMSG_COLON_AFTER_CASE, 0, JSEXN_SYNTAXERR, "missing : after case
MSG_DEF(JSMSG_COLON_AFTER_ID, 0, JSEXN_SYNTAXERR, "missing : after property id")
MSG_DEF(JSMSG_COLON_IN_COND, 0, JSEXN_SYNTAXERR, "missing : in conditional expression")
MSG_DEF(JSMSG_COMP_PROP_UNTERM_EXPR, 0, JSEXN_SYNTAXERR, "missing ] in computed property name")
MSG_DEF(JSMSG_CONTRARY_NONDIRECTIVE, 1, JSEXN_SYNTAXERR, "'{0}' statement won't be enforced as a directive because it isn't in directive prologue position")
MSG_DEF(JSMSG_CURLY_AFTER_BODY, 0, JSEXN_SYNTAXERR, "missing } after function body")
MSG_DEF(JSMSG_CURLY_OPENED, 2, JSEXN_NOTE, "{ opened at line {0}, column {1}")
MSG_DEF(JSMSG_CURLY_AFTER_CATCH, 0, JSEXN_SYNTAXERR, "missing } after catch block")
@@ -353,7 +352,6 @@ MSG_DEF(JSMSG_UNTERMINATED_REGEXP, 0, JSEXN_SYNTAXERR, "unterminated regular
MSG_DEF(JSMSG_EOF_BEFORE_END_OF_LITERAL,1,JSEXN_SYNTAXERR, "{0} literal not terminated before end of script")
MSG_DEF(JSMSG_EOL_BEFORE_END_OF_STRING,1, JSEXN_SYNTAXERR, "{0} string literal contains an unescaped line break")
MSG_DEF(JSMSG_EOF_IN_ESCAPE_IN_LITERAL,1, JSEXN_SYNTAXERR, "reached end of script in the middle of an escape sequence in a {0} literal")
MSG_DEF(JSMSG_USELESS_EXPR, 0, JSEXN_TYPEERR, "useless expression")
MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL, 0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body")
MSG_DEF(JSMSG_VAR_HIDES_ARG, 1, JSEXN_TYPEERR, "variable {0} redeclares argument")
MSG_DEF(JSMSG_WHILE_AFTER_DO, 0, JSEXN_SYNTAXERR, "missing while after do-loop body")
+2 -2
View File
@@ -330,8 +330,8 @@ void runTestFromPath(JSContext* cx, const char* path) {
}
frontend::Directives directives(false);
frontend::GlobalSharedContext globalsc(
cx, ScopeKind::Global, binCompilationInfo, directives, false);
frontend::GlobalSharedContext globalsc(cx, ScopeKind::Global,
binCompilationInfo, directives);
frontend::BinASTParser<Tok> binParser(cx, binCompilationInfo, binOptions,
binCompilationInfo.sourceObject);
+2 -2
View File
@@ -5430,8 +5430,8 @@ static bool BinParse(JSContext* cx, unsigned argc, Value* vp) {
}
js::frontend::Directives directives(false);
js::frontend::GlobalSharedContext globalsc(
cx, ScopeKind::Global, compilationInfo, directives, false);
js::frontend::GlobalSharedContext globalsc(cx, ScopeKind::Global,
compilationInfo, directives);
auto parseFunc = mode == Multipart
? ParseBinASTData<frontend::BinASTTokenReaderMultipart>
@@ -1,74 +0,0 @@
// |reftest| skip-if(!xulRuntime.shell) -- needs evaluate()
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
* Contributor:
* Jeff Walden <[email protected]>
*/
//-----------------------------------------------------------------------------
var BUGNUMBER = 1046964;
var summary =
"Misplaced directives (e.g. 'use strict') should trigger warnings if they " +
"contradict the actually-used semantics";
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
options("strict");
options("werror");
function evaluateNoRval(code)
{
evaluate(code, { isRunOnce: true, noScriptRval: true });
}
function expectSyntaxError(code)
{
try
{
evaluateNoRval(code);
throw new Error("didn't throw");
}
catch (e)
{
assertEq(e instanceof SyntaxError, true,
"should have thrown a SyntaxError, instead got:\n" +
" " + e + "\n" +
"when evaluating:\n" +
" " + code);
}
}
expectSyntaxError("function f1() {} 'use strict'; function f2() {}");
expectSyntaxError("function f3() { var x; 'use strict'; }");
if (isAsmJSCompilationAvailable())
expectSyntaxError("function f4() {} 'use asm'; function f5() {}");
expectSyntaxError("function f6() { var x; 'use strict'; }");
if (isAsmJSCompilationAvailable())
expectSyntaxError("'use asm'; function f7() {}");
// No errors expected -- useless non-directives, but not contrary to used
// semantics.
evaluateNoRval("'use strict'; function f8() {} 'use strict'; function f9() {}");
evaluateNoRval("'use strict'; function f10() { var z; 'use strict' }");
if (isAsmJSCompilationAvailable()) {
try {
evaluateNoRval("function f11() { 'use asm'; return {}; }");
} catch(e) {
if (!e.toString().includes("Successfully compiled asm.js code"))
throw e;
}
}
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");
@@ -1,32 +0,0 @@
// Turn on strict mode and warnings-as-errors mode.
if (options().split().indexOf('strict') == -1)
options('strict');
if (options().split().indexOf('werror') == -1)
options('werror');
function expectSyntaxError(stmt) {
print(stmt);
var result = 'no error';
try {
Function(stmt);
} catch (exc) {
result = exc.constructor.name;
}
assertEq(result, 'SyntaxError');
}
function test(expr) {
// Without extra parentheses, expect an error.
expectSyntaxError('if (' + expr + ') {};');
// Extra parentheses silence the warning/error.
Function('if ((' + expr + ')) {};');
}
// Overparenthesized assignment in a condition should not be a strict error.
test('a = 0');
test('a = (f(), g)');
test('a = b || c > d');
expectSyntaxError('if (a == 0);');
reportCompare('passed', 'passed', 'Overparenthesized assignment in a condition should not be a strict error.');
@@ -1,40 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 323314;
var summary = 'JSMSG_EQUAL_AS_ASSIGN in js.msg should be JSEXN_SYNTAXERR';
var actual = '';
var expect = '';
printBugNumber(BUGNUMBER);
printStatus (summary);
if (!options().match(/strict/))
{
options('strict');
}
if (!options().match(/werror/))
{
options('werror');
}
var xyzzy;
expect = 'SyntaxError';
try
{
eval('if (xyzzy=1) printStatus(xyzzy);');
actual = 'No Warning';
}
catch(ex)
{
actual = ex.name;
printStatus(ex + '');
}
reportCompare(expect, actual, summary);
+4 -5
View File
@@ -8,21 +8,20 @@ print(BUGNUMBER + ": " + summary);
// Warning with JSEXN_SYNTAXERR.
enableLastWarning();
options("strict");
eval(`var a; if (a=0) {}`);
eval(`function f() { if (false) { "use asm"; } }`);
warning = getLastWarning();
assertEq(warning !== null, true);
assertEq(warning.name, "SyntaxError");
assertEq(warning.message.includes("equality"), true);
assertEq(warning.message.includes("Directive Prologue"), true);
assertEq(warning.lineNumber, 1);
assertEq(warning.columnNumber, 14);
assertEq(warning.columnNumber, 28);
// Disabled.
disableLastWarning();
eval(`var a; if (a=0) {}`);
eval(`function f() { if (false) { "use asm"; } }`);
enableLastWarning();
warning = getLastWarning();
+4 -6
View File
@@ -72,9 +72,8 @@ static JSScript* CompileSourceBuffer(JSContext* cx,
return nullptr;
}
frontend::GlobalSharedContext globalsc(
cx, scopeKind, compilationInfo, compilationInfo.directives,
compilationInfo.options.extraWarningsOption);
frontend::GlobalSharedContext globalsc(cx, scopeKind, compilationInfo,
compilationInfo.directives);
return frontend::CompileGlobalScript(compilationInfo, globalsc, srcBuf);
}
@@ -556,9 +555,8 @@ static bool EvaluateSourceBuffer(JSContext* cx, ScopeKind scopeKind,
return false;
}
frontend::GlobalSharedContext globalsc(
cx, scopeKind, compilationInfo, compilationInfo.directives,
compilationInfo.options.extraWarningsOption);
frontend::GlobalSharedContext globalsc(cx, scopeKind, compilationInfo,
compilationInfo.directives);
script = frontend::CompileGlobalScript(compilationInfo, globalsc, srcBuf);
if (!script) {
return false;
+2 -3
View File
@@ -594,9 +594,8 @@ void ScriptParseTask<Unit>::parse(JSContext* cx) {
// initialized SSO.
sourceObjects.infallibleAppend(compilationInfo.sourceObject);
frontend::GlobalSharedContext globalsc(
cx, scopeKind, compilationInfo, compilationInfo.directives,
compilationInfo.options.extraWarningsOption);
frontend::GlobalSharedContext globalsc(cx, scopeKind, compilationInfo,
compilationInfo.directives);
JSScript* script =
frontend::CompileGlobalScript(compilationInfo, globalsc, data);