Bug 1502280 - Remove the case BinTokenReaderBase.errorReporter_ is null. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Wed, 14 Nov 2018 13:00:34 +0900
changeset 446156 9b456742a2cc22f56aac2a4d26063307b85135a6
parent 446155 a4fb56d2819e636de6c7ae756028e537efae48d0
child 446157 d3f4d556a89d3e5e72749314a0cf81d942fafc13
push id35035
push userccoroiu@mozilla.com
push dateWed, 14 Nov 2018 09:52:26 +0000
treeherdermozilla-central@073045259e75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1502280
milestone65.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 1502280 - Remove the case BinTokenReaderBase.errorReporter_ is null. r=Yoric
js/src/frontend/BinTokenReaderBase.cpp
js/src/frontend/BinTokenReaderBase.h
js/src/jsapi-tests/testBinTokenReaderTester.cpp
--- a/js/src/frontend/BinTokenReaderBase.cpp
+++ b/js/src/frontend/BinTokenReaderBase.cpp
@@ -26,24 +26,17 @@ BinTokenReaderBase::updateLatestKnownGoo
     MOZ_ASSERT(update >= latestKnownGoodPos_);
     latestKnownGoodPos_ = update;
 }
 
 ErrorResult<JS::Error&>
 BinTokenReaderBase::raiseError(const char* description)
 {
     MOZ_ASSERT(!hasRaisedError());
-    if (MOZ_LIKELY(errorReporter_)) {
-        errorReporter_->reportErrorNoOffset(JSMSG_BINAST, description);
-    } else {
-        // Only true in testing code.
-        TokenPos pos = this->pos();
-        JS_ReportErrorASCII(cx_, "BinAST parsing error: %s at offsets %u => %u",
-                            description, pos.begin, pos.end);
-    }
+    errorReporter_->reportErrorNoOffset(JSMSG_BINAST, description);
     return cx_->alreadyReportedError();
 }
 
 ErrorResult<JS::Error&>
 BinTokenReaderBase::raiseOOM()
 {
     ReportOutOfMemory(cx_);
     return cx_->alreadyReportedError();
--- a/js/src/frontend/BinTokenReaderBase.h
+++ b/js/src/frontend/BinTokenReaderBase.h
@@ -80,17 +80,19 @@ class MOZ_STACK_CLASS BinTokenReaderBase
     BinTokenReaderBase(JSContext* cx, ErrorReporter* er, const uint8_t* start, const size_t length)
         : cx_(cx)
         , errorReporter_(er)
         , poisoned_(false)
         , start_(start)
         , current_(start)
         , stop_(start + length)
         , latestKnownGoodPos_(0)
-    { }
+    {
+        MOZ_ASSERT(errorReporter_);
+    }
 
     /**
      * Read a single byte.
      */
     MOZ_MUST_USE JS::Result<uint8_t> readByte();
 
     /**
      * Read several bytes.
--- a/js/src/jsapi-tests/testBinTokenReaderTester.cpp
+++ b/js/src/jsapi-tests/testBinTokenReaderTester.cpp
@@ -13,16 +13,17 @@
 #elif defined(XP_UNIX)
 #include <fcntl.h>
 #include <unistd.h>
 #endif // defined (XP_WIN) || defined (XP_UNIX)
 
 #include "mozilla/Maybe.h"
 
 #include "frontend/BinTokenReaderTester.h"
+#include "frontend/ErrorReporter.h"
 
 #include "js/Vector.h"
 
 #include "jsapi-tests/tests.h"
 
 using mozilla::Maybe;
 
 using Tokenizer = js::frontend::BinTokenReaderTester;
@@ -102,16 +103,71 @@ void exitJsDirectory() {
     if (SetCurrentDirectory(gJsDirectory) == 0) {
         MOZ_CRASH("Could not return to original directory");
     }
     gJsDirectory[0] = 0;
 }
 
 #endif // defined(XP_UNIX) || defined(XP_WIN)
 
+// An dummy error reporter that does nothing, which is requred by
+// BinTokenReaderTester ctor.
+// These testcases don't test error case, so methods that is related to
+// error reporting crashes when called.
+class DummyErrorReporter : public js::frontend::ErrorReporter
+{
+    const JS::CompileOptions options_;
+
+  public:
+    explicit DummyErrorReporter(JSContext* cx)
+      : options_(cx)
+    {}
+
+    virtual const JS::ReadOnlyCompileOptions& options() const override {
+        return options_;
+    }
+
+    virtual void lineAndColumnAt(size_t offset, uint32_t* line, uint32_t* column) const override {
+        *line = 0;
+        *column = 0;
+    }
+    virtual void currentLineAndColumn(uint32_t* line, uint32_t* column) const override {
+        *line = 0;
+        *column = 0;
+    }
+    virtual bool isOnThisLine(size_t offset, uint32_t lineNum, bool *onThisLine) const override {
+        *onThisLine = true;
+        return true;
+    }
+    virtual uint32_t lineAt(size_t offset) const override {
+        return 0;
+    }
+    virtual uint32_t columnAt(size_t offset) const override {
+        return 0;
+    }
+
+    virtual bool hasTokenizationStarted() const override {
+        return true;
+    }
+    virtual void reportErrorNoOffsetVA(unsigned errorNumber, va_list args) override {
+        MOZ_CRASH("shouldn't be used in test");
+    }
+    virtual const char* getFilename() const override {
+        return "dummy filename";
+    }
+
+    virtual void errorAtVA(uint32_t offset, unsigned errorNumber, va_list* args) override {
+        MOZ_CRASH("shouldn't be used in test");
+    }
+    virtual bool reportExtraWarningErrorNumberVA(UniquePtr<JSErrorNotes> notes, uint32_t offset, unsigned errorNumber, va_list* args) override {
+        MOZ_CRASH("shouldn't be used in test");
+        return false;
+    }
+};
+
 void readFull(const char* path, js::Vector<uint8_t>& buf) {
     enterJsDirectory();
     buf.shrinkTo(0);
     FILE* in = fopen(path, "rb");
     if (!in) {
         MOZ_CRASH_UNSAFE_PRINTF("Could not open %s: %s", path, strerror(errno));
     }
 
@@ -135,66 +191,70 @@ void readFull(const char* path, js::Vect
 }
 
 
 // Reading a simple string.
 BEGIN_TEST(testBinTokenReaderTesterSimpleString)
 {
     js::Vector<uint8_t> contents(cx);
     readFull("jsapi-tests/binast/tokenizer/tester/test-simple-string.binjs", contents);
-    Tokenizer tokenizer(cx, nullptr, contents);
+    DummyErrorReporter reporter(cx);
+    Tokenizer tokenizer(cx, &reporter, contents);
 
     Chars found(cx);
     CHECK(tokenizer.readChars(found).isOk());
 
     CHECK(Tokenizer::equals(found, "simple string")); // FIXME: Find a way to make CHECK_EQUAL use `Tokenizer::equals`.
 
     return true;
 }
 END_TEST(testBinTokenReaderTesterSimpleString)
 
 // Reading a string with embedded 0.
 BEGIN_TEST(testBinTokenReaderTesterStringWithEscapes)
 {
     js::Vector<uint8_t> contents(cx);
     readFull("jsapi-tests/binast/tokenizer/tester/test-string-with-escapes.binjs", contents);
-    Tokenizer tokenizer(cx, nullptr, contents);
+    DummyErrorReporter reporter(cx);
+    Tokenizer tokenizer(cx, &reporter, contents);
 
     Chars found(cx);
     CHECK(tokenizer.readChars(found).isOk());
 
     CHECK(Tokenizer::equals(found, "string with escapes \0\1\0")); // FIXME: Find a way to make CHECK_EQUAL use `Tokenizer::equals`.
 
     return true;
 }
 END_TEST(testBinTokenReaderTesterStringWithEscapes)
 
 // Reading an empty untagged tuple
 BEGIN_TEST(testBinTokenReaderTesterEmptyUntaggedTuple)
 {
     js::Vector<uint8_t> contents(cx);
     readFull("jsapi-tests/binast/tokenizer/tester/test-empty-untagged-tuple.binjs", contents);
-    Tokenizer tokenizer(cx, nullptr, contents);
+    DummyErrorReporter reporter(cx);
+    Tokenizer tokenizer(cx, &reporter, contents);
 
     {
         Tokenizer::AutoTuple guard(tokenizer);
         CHECK(tokenizer.enterUntaggedTuple(guard).isOk());
         CHECK(guard.done().isOk());
     }
 
     return true;
 }
 END_TEST(testBinTokenReaderTesterEmptyUntaggedTuple)
 
 // Reading a untagged tuple with two strings
 BEGIN_TEST(testBinTokenReaderTesterTwoStringsInTuple)
 {
     js::Vector<uint8_t> contents(cx);
     readFull("jsapi-tests/binast/tokenizer/tester/test-trivial-untagged-tuple.binjs", contents);
-    Tokenizer tokenizer(cx, nullptr, contents);
+    DummyErrorReporter reporter(cx);
+    Tokenizer tokenizer(cx, &reporter, contents);
 
     {
         Tokenizer::AutoTuple guard(tokenizer);
         CHECK(tokenizer.enterUntaggedTuple(guard).isOk());
 
         Chars found_0(cx);
         CHECK(tokenizer.readChars(found_0).isOk());
         CHECK(Tokenizer::equals(found_0, "foo")); // FIXME: Find a way to make CHECK_EQUAL use `Tokenizer::equals`.
@@ -210,17 +270,18 @@ BEGIN_TEST(testBinTokenReaderTesterTwoSt
 }
 END_TEST(testBinTokenReaderTesterTwoStringsInTuple)
 
 // Reading a tagged tuple `Pattern { id: "foo", value: 3.1415}`
 BEGIN_TEST(testBinTokenReaderTesterSimpleTaggedTuple)
 {
     js::Vector<uint8_t> contents(cx);
     readFull("jsapi-tests/binast/tokenizer/tester/test-simple-tagged-tuple.binjs", contents);
-    Tokenizer tokenizer(cx, nullptr, contents);
+    DummyErrorReporter reporter(cx);
+    Tokenizer tokenizer(cx, &reporter, contents);
 
     {
         js::frontend::BinKind tag;
         Tokenizer::BinFields fields(cx);
         Tokenizer::AutoTaggedTuple guard(tokenizer);
         CHECK(tokenizer.enterTaggedTuple(tag, fields, guard).isOk());
 
         CHECK(tag == js::frontend::BinKind::BindingIdentifier);
@@ -244,17 +305,18 @@ BEGIN_TEST(testBinTokenReaderTesterSimpl
 END_TEST(testBinTokenReaderTesterSimpleTaggedTuple)
 
 
 // Reading an empty list
 BEGIN_TEST(testBinTokenReaderTesterEmptyList)
 {
     js::Vector<uint8_t> contents(cx);
     readFull("jsapi-tests/binast/tokenizer/tester/test-empty-list.binjs", contents);
-    Tokenizer tokenizer(cx, nullptr, contents);
+    DummyErrorReporter reporter(cx);
+    Tokenizer tokenizer(cx, &reporter, contents);
 
     {
         uint32_t length;
         Tokenizer::AutoList guard(tokenizer);
         CHECK(tokenizer.enterList(length, guard).isOk());
 
         CHECK(length == 0);
         CHECK(guard.done().isOk());
@@ -264,17 +326,18 @@ BEGIN_TEST(testBinTokenReaderTesterEmpty
 }
 END_TEST(testBinTokenReaderTesterEmptyList)
 
 // Reading `["foo", "bar"]`
 BEGIN_TEST(testBinTokenReaderTesterSimpleList)
 {
     js::Vector<uint8_t> contents(cx);
     readFull("jsapi-tests/binast/tokenizer/tester/test-trivial-list.binjs", contents);
-    Tokenizer tokenizer(cx, nullptr, contents);
+    DummyErrorReporter reporter(cx);
+    Tokenizer tokenizer(cx, &reporter, contents);
 
     {
         uint32_t length;
         Tokenizer::AutoList guard(tokenizer);
         CHECK(tokenizer.enterList(length, guard).isOk());
 
         CHECK(length == 2);
 
@@ -294,17 +357,18 @@ BEGIN_TEST(testBinTokenReaderTesterSimpl
 END_TEST(testBinTokenReaderTesterSimpleList)
 
 
 // Reading `[["foo", "bar"]]`
 BEGIN_TEST(testBinTokenReaderTesterNestedList)
 {
     js::Vector<uint8_t> contents(cx);
     readFull("jsapi-tests/binast/tokenizer/tester/test-nested-lists.binjs", contents);
-    Tokenizer tokenizer(cx, nullptr, contents);
+    DummyErrorReporter reporter(cx);
+    Tokenizer tokenizer(cx, &reporter, contents);
 
     {
         uint32_t outerLength;
         Tokenizer::AutoList outerGuard(tokenizer);
         CHECK(tokenizer.enterList(outerLength, outerGuard).isOk());
         CHECK_EQUAL(outerLength, (uint32_t)1);
 
         {