diff --git a/parser/html/jArray.h b/parser/html/jArray.h
index 45548a077..98889059c 100644
--- a/parser/html/jArray.h
+++ b/parser/html/jArray.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008-2015 Mozilla Foundation
+ * Copyright (c) 2019 Moonchild Productions
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -44,32 +45,66 @@ struct staticJArray {
}
};
-template
-struct jArray {
+template
+class autoJArray;
+
+template
+class jArray {
+ friend class autoJArray;
+
+private:
T* arr;
+
+public:
L length;
+
static jArray newJArray(L const len) {
MOZ_ASSERT(len >= 0, "Negative length.");
jArray newArray = { new T[size_t(len)], len };
return newArray;
}
+
static jArray newFallibleJArray(L const len) {
MOZ_ASSERT(len >= 0, "Negative length.");
T* a = new (mozilla::fallible) T[size_t(len)];
jArray newArray = { a, a ? len : 0 };
return newArray;
}
- operator T*() { return arr; }
+
+ operator T*() {
+ return arr;
+ }
+
T& operator[] (L const index) {
MOZ_ASSERT(index >= 0, "Array access with negative index.");
MOZ_ASSERT(index < length, "Array index out of bounds.");
return arr[index];
}
+
void operator=(staticJArray& other) {
arr = (T*)other.arr;
length = other.length;
}
-};
+
+ MOZ_IMPLICIT jArray(decltype(nullptr))
+ : arr(nullptr)
+ , length(0)
+ {
+ }
+
+ jArray()
+ : arr(nullptr)
+ , length(0)
+ {
+ }
+
+private:
+ jArray(T* aArr, L aLength)
+ : arr(aArr)
+ , length(aLength)
+ {
+ }
+}; // class jArray
template
class autoJArray {
diff --git a/parser/html/javasrc/Tokenizer.java b/parser/html/javasrc/Tokenizer.java
index 70e1df75c..f141d94d7 100644
--- a/parser/html/javasrc/Tokenizer.java
+++ b/parser/html/javasrc/Tokenizer.java
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2005-2007 Henri Sivonen
* Copyright (c) 2007-2015 Mozilla Foundation
+ * Copyright (c) 2019 Moonchild Productions
* Portions of comments Copyright 2004-2010 Apple Computer, Inc., Mozilla
* Foundation, and Opera Software ASA.
*
@@ -680,6 +681,22 @@ public class Tokenizer implements Locator {
*
* @param specialTokenizerState
* the tokenizer state to set
+ */
+ public void setState(int specialTokenizerState) {
+ this.stateSave = specialTokenizerState;
+ this.endTagExpectation = null;
+ this.endTagExpectationAsArray = null;
+ }
+
+ // [NOCPP[
+
+ /**
+ * Sets the tokenizer state and the associated element name. This should
+ * only ever used to put the tokenizer into one of the states that have
+ * a special end tag expectation. For use from the tokenizer test harness.
+ *
+ * @param specialTokenizerState
+ * the tokenizer state to set
* @param endTagExpectation
* the expected end tag for transitioning back to normal
*/
@@ -695,6 +712,8 @@ public class Tokenizer implements Locator {
endTagExpectationToArray();
}
+ // ]NOCPP]
+
/**
* Sets the tokenizer state and the associated element name. This should
* only ever used to put the tokenizer into one of the states that have
@@ -3759,11 +3778,17 @@ public class Tokenizer implements Locator {
c = checkChar(buf, pos);
/*
* ASSERT! when entering this state, set index to 0 and
- * call clearStrBufBeforeUse() assert (contentModelElement !=
- * null); Let's implement the above without lookahead.
- * strBuf is the 'temporary buffer'.
+ * call clearStrBufBeforeUse(); Let's implement the above
+ * without lookahead. strBuf is the 'temporary buffer'.
*/
- if (index < endTagExpectationAsArray.length) {
+ if (endTagExpectationAsArray == null) {
+ tokenHandler.characters(Tokenizer.LT_SOLIDUS,
+ 0, 2);
+ cstart = pos;
+ reconsume = true;
+ state = transition(state, returnState, reconsume, pos);
+ continue stateloop;
+ } else if (index < endTagExpectationAsArray.length) {
char e = endTagExpectationAsArray[index];
char folded = c;
if (c >= 'A' && c <= 'Z') {
diff --git a/parser/html/javasrc/TreeBuilder.java b/parser/html/javasrc/TreeBuilder.java
index 5e83d1847..58074086d 100644
--- a/parser/html/javasrc/TreeBuilder.java
+++ b/parser/html/javasrc/TreeBuilder.java
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2007 Henri Sivonen
* Copyright (c) 2007-2015 Mozilla Foundation
+ * Copyright (c) 2018-2019 Moonchild Productions
* Portions of comments Copyright 2004-2008 Apple Computer, Inc., Mozilla
* Foundation, and Opera Software ASA.
*
@@ -640,8 +641,7 @@ public abstract class TreeBuilder implements TokenHandler,
);
currentPtr++;
stack[currentPtr] = node;
- tokenizer.setStateAndEndTagExpectation(Tokenizer.DATA,
- contextName);
+ tokenizer.setState(Tokenizer.DATA);
// The frameset-ok flag is set even though