Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/filter/RegExpFilter.cpp

Issue 29398655: Issue 5062 - [emscripten] Allow generation of custom bindings code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Made the code slightly safer Created April 4, 2017, 2:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <cctype>
18 #include <climits> 19 #include <climits>
20 #include <cstdio>
21 #include <stdexcept>
22 #include <iterator>
19 23
20 #include <emscripten.h> 24 #include <emscripten.h>
21 25
22 #include "RegExpFilter.h" 26 #include "RegExpFilter.h"
23 #include "../StringScanner.h" 27 #include "../StringScanner.h"
24 #include "../StringMap.h" 28 #include "../StringMap.h"
25 29
26 namespace 30 namespace
27 { 31 {
28 enum 32 enum
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 done = scanner.done(); 343 done = scanner.done();
340 if (scanner.next() == u'|') 344 if (scanner.next() == u'|')
341 { 345 {
342 if (scanner.position() > start) 346 if (scanner.position() > start)
343 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ; 347 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ;
344 start = scanner.position() + 1; 348 start = scanner.position() + 1;
345 } 349 }
346 } 350 }
347 } 351 }
348 352
349 void RegExpFilter::InitJSTypes() 353 void RegExpFilter::GenerateCustomBindings()
350 { 354 {
351 EM_ASM(exports.RegExpFilter.typeMap = {};); 355 printf("exports.RegExpFilter.typeMap = {\n");
352 for (auto it = typeMap.begin(); it != typeMap.end(); ++it) 356
353 EM_ASM_ARGS(exports.RegExpFilter.typeMap[readString($0).replace("-", "_").to UpperCase()] = $1, &(it->first), it->second); 357 OwnedString type;
358 char type_cstr[256];
359 for (const auto& it : typeMap)
360 {
361 type = it.first;
362 auto len = type.length();
363 if (len >= std::end(type_cstr) - std::begin(type_cstr))
364 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.
365 for (int i = 0; i < len; i++)
366 {
367 if (type[i] == '-')
368 type_cstr[i] = '_';
369 else
370 type_cstr[i] = toupper(type[i]);
371 }
372 type_cstr[len] = 0;
373 printf(" %s: %i,\n", type_cstr, it.second);
374 }
375 printf("};\n");
354 } 376 }
355 377
356 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const 378 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const
357 { 379 {
358 if (!mData.DomainsParsingDone()) 380 if (!mData.DomainsParsingDone())
359 { 381 {
360 ParseDomains(mData.GetDomainsSource(mText), u'|'); 382 ParseDomains(mData.GetDomainsSource(mText), u'|');
361 mData.SetDomainsParsingDone(); 383 mData.SetDomainsParsingDone();
362 } 384 }
363 return ActiveFilter::GetDomains(); 385 return ActiveFilter::GetDomains();
(...skipping 20 matching lines...) Expand all
384 return false; 406 return false;
385 } 407 }
386 408
387 if (!mData.RegExpParsingDone()) 409 if (!mData.RegExpParsingDone())
388 { 410 {
389 const OwnedString pattern(mData.GetRegExpSource(mText)); 411 const OwnedString pattern(mData.GetRegExpSource(mText));
390 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ; 412 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ;
391 } 413 }
392 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location); 414 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location);
393 } 415 }
OLDNEW
« no previous file with comments | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld