WIP: Ported BinSource to enum class taggedTuple
MozReview-Commit-ID: 8ytXdCKuCAU
--- a/js/src/frontend/BinTokenReader.cpp
+++ b/js/src/frontend/BinTokenReader.cpp
@@ -215,69 +215,16 @@ SimpleTokenReader::readString(std::strin
// - "<head>"
// - non-null string `name` (see `readString()`);
// - uint32_t number of fields;
// - array of `number of fields` non-null strings (see `readString()`);
// - "</head>"
// - content (specified by the higher-level grammar);
// - "</tuple>"
bool
-SimpleTokenReader::taggedTuple(std::string* name, SimpleTokenReader::Fields *fields, SimpleTokenReader* subReader)
-{
- if (!this->readConst("<tuple>")) {
- return false;
- }
-
- if (!this->readConst("<head>")) {
- return false;
- }
-
- // Caution: we do not validate the string.
- Maybe<std::string> maybeName;
- if (!this->readMaybeString(&maybeName)) {
- return false;
- }
-
- if (!maybeName) {
- return false;
- }
- name->swap(*maybeName);
-
- uint32_t fieldNum;
- if (!this->readInternalUint32(&fieldNum)) {
- return false;
- }
-
- fields->clear();
- if (!fields->reserve(fieldNum)) {
- return false;
- }
- for (uint32_t i = 0; i < fieldNum; ++i) {
- std::string fieldName;
- Maybe<std::string> maybeString;
- if (!this->readMaybeString(&maybeString)) {
- return false;
- }
- if (maybeString.isNothing()) {
- return false;
- }
- fieldName.swap(*maybeString);
- if (!fields->append(Move(fieldName))) {
- return false;
- }
- }
-
- if (!this->readConst("</head>")) {
- return false;
- }
-
- subReader->init(this->current, this->stop, nullptr, "</tuple>", this);
- return true;
-}
-bool
SimpleTokenReader::taggedTuple(BinKind& tag, SimpleTokenReader::BinFields& fields, SimpleTokenReader* subReader)
{
// Header
if (!this->readConst("<tuple>")) {
return false;
}
if (!this->readConst("<head>")) {
--- a/js/src/frontend/BinTokenReader.h
+++ b/js/src/frontend/BinTokenReader.h
@@ -126,17 +126,16 @@ enum class BinField {
/**
* A simple, extremely sub-optimal TokenReader, used as scaffolding for testing
* the implementation of binary parsing.
*/
class SimpleTokenReader MOZ_STACK_CLASS
{
public:
- using Fields = Vector<std::string, 8>;
using BinFields = Vector<BinField, 8>;
public:
SimpleTokenReader(JSContext* cx_)
: cx(cx_)
, initialized(false)
, parent(nullptr)
, errored(false)
, current(nullptr)
@@ -292,17 +291,16 @@ public:
* support `skip()`.
*
* Before destructing `subReader`, callers MUST reach the end of the
* tagged tuple. Failure to do so may either raise an error or cause
* an inconsistent sequence of tokens in the parent.
*
* @return out If the header of the tuple is invalid.
*/
- bool taggedTuple(std::string* tag, SimpleTokenReader::Fields *fields, SimpleTokenReader *subReader);
bool taggedTuple(BinKind& tag, SimpleTokenReader::BinFields& fields, SimpleTokenReader *subReader);
/**
* Start reading an untagged tuple.
* @param subReader (OUT) A token reader for the list. It does NOT
* support `skip()`.
*
* Before destructing `subReader`, callers MUST reach the end of the