Bug 821103 - Don't spit out strict warnings on non-strict code. r=njn
authorBenjamin Peterson <benjamin@python.org>
Mon, 17 Dec 2012 19:11:44 -0500
changeset 125455 eb8734ce0dc2a98ba885bfd5fed9dc5f8177b683
parent 125454 0bec05537ea564b878f548fd540222fd878fea3d
child 125456 7f5c8262d399a057507b6f632536cc8ade4c53e8
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs821103
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 821103 - Don't spit out strict warnings on non-strict code. r=njn
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/Parser.h
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
js/src/jit-test/tests/basic/bug821103.js
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -1713,18 +1713,17 @@ BytecodeEmitter::reportError(ParseNode *
     return result;
 }
 
 bool
 BytecodeEmitter::reportStrictWarning(ParseNode *pn, unsigned errorNumber, ...)
 {
     va_list args;
     va_start(args, errorNumber);
-    bool result = tokenStream()->reportCompileErrorNumberVA(pn, JSREPORT_STRICT | JSREPORT_WARNING,
-                                                            errorNumber, args);
+    bool result = tokenStream()->reportStrictWarningErrorNumberVA(pn, sc->strict, errorNumber, args);
     va_end(args);
     return result;
 }
 
 bool
 BytecodeEmitter::reportStrictModeError(ParseNode *pn, unsigned errorNumber, ...)
 {
     va_list args;
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -503,18 +503,18 @@ Parser::reportWarning(ParseNode *pn, uns
     return result;
 }
 
 inline bool
 Parser::reportStrictWarning(ParseNode *pn, unsigned errorNumber, ...)
 {
     va_list args;
     va_start(args, errorNumber);
-    bool result = tokenStream.reportCompileErrorNumberVA(pn, JSREPORT_STRICT | JSREPORT_WARNING,
-                                                         errorNumber, args);
+    bool result = tokenStream.reportStrictWarningErrorNumberVA(pn, pc->sc->strict,
+                                                               errorNumber, args);
     va_end(args);
     return result;
 }
 
 inline bool
 Parser::reportStrictModeError(ParseNode *pn, unsigned errorNumber, ...)
 {
     va_list args;
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -611,22 +611,31 @@ TokenStream::reportWarning(unsigned erro
     return result;
 }
 
 bool
 TokenStream::reportStrictWarning(unsigned errorNumber, ...)
 {
     va_list args;
     va_start(args, errorNumber);
-    bool result = reportCompileErrorNumberVA(NULL, JSREPORT_STRICT | JSREPORT_WARNING,
-                                             errorNumber, args);
+    bool result = reportStrictWarningErrorNumberVA(NULL, strictMode(), errorNumber, args);
     va_end(args);
     return result;
 }
 
+bool
+TokenStream::reportStrictWarningErrorNumberVA(ParseNode *pn, bool strictMode, unsigned errorNumber,
+                                              va_list args)
+{
+    if (!strictMode && !cx->hasStrictOption())
+        return true;
+
+    return reportCompileErrorNumberVA(NULL, JSREPORT_STRICT | JSREPORT_WARNING, errorNumber, args);
+}
+
 #if JS_HAS_XML_SUPPORT
 
 bool
 TokenStream::getXMLEntity()
 {
     ptrdiff_t offset, length, i;
     int c, d;
     bool ispair;
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -539,16 +539,18 @@ class TokenStream
 
     // General-purpose error reporters.  You should avoid calling these
     // directly, and instead use the more succinct alternatives (e.g.
     // reportError()) in TokenStream, Parser, and BytecodeEmitter.
     bool reportCompileErrorNumberVA(ParseNode *pn, unsigned flags, unsigned errorNumber,
                                     va_list args);
     bool reportStrictModeErrorNumberVA(ParseNode *pn, bool strictMode, unsigned errorNumber,
                                        va_list args);
+    bool reportStrictWarningErrorNumberVA(ParseNode *pn, bool strictMode, unsigned errorNumber,
+                                          va_list args);
 
   private:
     void onError();
     static JSAtom *atomize(JSContext *cx, CharBuffer &cb);
     bool putIdentInTokenbuf(const jschar *identStart);
 
     /*
      * Enables flags in the associated tokenstream for the object lifetime.
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug821103.js
@@ -0,0 +1,4 @@
+options("werror");
+load(libdir + "asserts.js");
+
+eval("function x() { var x= 4; 'hi'; }");