Index: compiled/filter/RegExpFilter.cpp |
=================================================================== |
--- a/compiled/filter/RegExpFilter.cpp |
+++ b/compiled/filter/RegExpFilter.cpp |
@@ -10,17 +10,21 @@ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
+#include <cctype> |
#include <climits> |
+#include <cstdio> |
+#include <stdexcept> |
+#include <iterator> |
#include <emscripten.h> |
#include "RegExpFilter.h" |
#include "../StringScanner.h" |
#include "../StringMap.h" |
namespace |
@@ -341,21 +345,39 @@ void RegExpFilter::ParseSitekeys(const S |
{ |
if (scanner.position() > start) |
AddSitekey(DependentString(sitekeys, start, scanner.position() - start)); |
start = scanner.position() + 1; |
} |
} |
} |
-void RegExpFilter::InitJSTypes() |
+void RegExpFilter::GenerateCustomBindings() |
{ |
- EM_ASM(exports.RegExpFilter.typeMap = {};); |
- for (auto it = typeMap.begin(); it != typeMap.end(); ++it) |
- EM_ASM_ARGS(exports.RegExpFilter.typeMap[readString($0).replace("-", "_").toUpperCase()] = $1, &(it->first), it->second); |
+ printf("exports.RegExpFilter.typeMap = {\n"); |
+ |
+ OwnedString type; |
+ char type_cstr[256]; |
+ for (const auto& it : typeMap) |
+ { |
+ type = it.first; |
+ auto len = type.length(); |
+ if (len >= std::end(type_cstr) - std::begin(type_cstr)) |
+ throw std::runtime_error("Value size too large for the buffer"); |
sergei
2017/04/04 14:49:31
Well, if you touch this code then I would recommen
Wladimir Palant
2017/04/04 15:41:48
Done.
|
+ for (int i = 0; i < len; i++) |
+ { |
+ if (type[i] == '-') |
+ type_cstr[i] = '_'; |
+ else |
+ type_cstr[i] = toupper(type[i]); |
+ } |
+ type_cstr[len] = 0; |
+ printf(" %s: %i,\n", type_cstr, it.second); |
+ } |
+ printf("};\n"); |
} |
RegExpFilter::DomainMap* RegExpFilter::GetDomains() const |
{ |
if (!mData.DomainsParsingDone()) |
{ |
ParseDomains(mData.GetDomainsSource(mText), u'|'); |
mData.SetDomainsParsingDone(); |