From 0ce08b418d84a57bae22a0aa395fecb7412ed931 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 4 Sep 2019 15:27:40 +0200 Subject: Fix an issue with the html5 tokenizer and tree builder. --- parser/html/jArray.h | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'parser/html/jArray.h') 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 { -- cgit v1.2.3