summaryrefslogtreecommitdiffstats
path: root/parser/html/jArray.h
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-09-04 15:27:40 +0200
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-09-04 15:27:40 +0200
commit0ce08b418d84a57bae22a0aa395fecb7412ed931 (patch)
tree7d46a9b019e57aee76879290695ce2173a8891af /parser/html/jArray.h
parentcc60a093cb65745602dc1f5eab9f5e328ddaad15 (diff)
downloadUXP-0ce08b418d84a57bae22a0aa395fecb7412ed931.tar
UXP-0ce08b418d84a57bae22a0aa395fecb7412ed931.tar.gz
UXP-0ce08b418d84a57bae22a0aa395fecb7412ed931.tar.lz
UXP-0ce08b418d84a57bae22a0aa395fecb7412ed931.tar.xz
UXP-0ce08b418d84a57bae22a0aa395fecb7412ed931.zip
Fix an issue with the html5 tokenizer and tree builder.
Diffstat (limited to 'parser/html/jArray.h')
-rw-r--r--parser/html/jArray.h43
1 files changed, 39 insertions, 4 deletions
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<class T, class L>
-struct jArray {
+template <class T, class L>
+class autoJArray;
+
+template <class T, class L>
+class jArray {
+ friend class autoJArray<T, L>;
+
+private:
T* arr;
+
+public:
L length;
+
static jArray<T,L> newJArray(L const len) {
MOZ_ASSERT(len >= 0, "Negative length.");
jArray<T,L> newArray = { new T[size_t(len)], len };
return newArray;
}
+
static jArray<T,L> newFallibleJArray(L const len) {
MOZ_ASSERT(len >= 0, "Negative length.");
T* a = new (mozilla::fallible) T[size_t(len)];
jArray<T,L> 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<T,L>& 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 T, class L>
class autoJArray {