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

Unified Diff: compiled/bindings.cpp

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Reworked JS binding generation Created Feb. 1, 2016, 9:14 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: compiled/bindings.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/bindings.cpp
@@ -0,0 +1,112 @@
+#include <emscripten.h>
+
+#include "bindings.h"
+#include "String.h"
+#include "intrusive_ptr.h"
+#include "Filter.h"
+#include "InvalidFilter.h"
+#include "CommentFilter.h"
+#include "ActiveFilter.h"
+#include "RegExpFilter.h"
+#include "WhitelistFilter.h"
+#include "ElemHideBase.h"
+#include "ElemHideFilter.h"
+#include "ElemHideException.h"
+#include "CSSPropertyFilter.h"
+
+extern "C"
+{
+ void EMSCRIPTEN_KEEPALIVE InitString(String* str, String::value_type* data,
+ String::size_type len)
+ {
+ // String is already allocated on stack, we merely need to call constructor.
+ new (str) String(data, len);
+ }
+
+ void EMSCRIPTEN_KEEPALIVE DestroyString(String* str)
+ {
+ // Stack memory will be freed automatically, we need to call destructor
+ // explicitly however.
+ str->~String();
+ }
+
+ String::size_type EMSCRIPTEN_KEEPALIVE GetStringLength(const String& str)
+ {
+ return str.length();
+ }
+
+ const String::value_type* EMSCRIPTEN_KEEPALIVE GetStringData(const String& str)
+ {
+ return str.data();
+ }
+
+ void EMSCRIPTEN_KEEPALIVE AddRef(ref_counted* ptr)
+ {
+ ptr->AddRef();
+ }
+
+ void EMSCRIPTEN_KEEPALIVE ReleaseRef(ref_counted* ptr)
+ {
+ ptr->ReleaseRef();
+ }
+}
+
+#if defined(PRINT_BINDINGS)
+EMSCRIPTEN_BINDINGS(api)
+{
+ class_<Filter>("Filter")
+ .property("text", &Filter::GetText)
+ .function("serialize", &Filter::Serialize)
+ .class_function("fromText", &Filter::FromText)
+ .class_function("normalize", &Filter::Normalize)
+ .subclass_differentiator(&Filter::GetType, {
+ {Filter::Type::INVALID, "InvalidFilter"},
+ {Filter::Type::COMMENT, "CommentFilter"},
+ {Filter::Type::BLOCKING, "RegExpFilter"},
+ {Filter::Type::WHITELIST, "WhitelistFilter"},
+ {Filter::Type::ELEMHIDE, "ElemHideFilter"},
+ {Filter::Type::ELEMHIDEEXCEPTION, "ElemHideException"},
+ {Filter::Type::CSSPROPERTY, "CSSPropertyFilter"},
+ });
+
+ class_<InvalidFilter,Filter>("InvalidFilter")
+ .class_property("type", "'invalid'")
+ .property("reason", &InvalidFilter::GetReason);
+
+ class_<CommentFilter,Filter>("CommentFilter")
+ .class_property("type", "'comment'");
+
+ class_<ActiveFilter,Filter>("ActiveFilter")
+ .property("disabled", &ActiveFilter::GetDisabled, &ActiveFilter::SetDisabled)
+ .property("hitCount", &ActiveFilter::GetHitCount, &ActiveFilter::SetHitCount)
+ .property("lastHit", &ActiveFilter::GetLastHit, &ActiveFilter::SetLastHit)
+ .function("isActiveOnDomain", &ActiveFilter::IsActiveOnDomain)
+ .function("isActiveOnlyOnDomain", &ActiveFilter::IsActiveOnlyOnDomain)
+ .function("isGeneric", &ActiveFilter::IsGeneric)
+ .function("serialize", &ActiveFilter::Serialize);
+
+ class_<RegExpFilter,ActiveFilter>("RegExpFilter")
+ .class_property("type", "'blocking'")
+ .function("matches", &RegExpFilter::Matches)
+ .class_initializer(&RegExpFilter::InitJSTypes);
+
+ class_<WhitelistFilter,RegExpFilter>("WhitelistFilter")
+ .class_property("type", "'whitelist'");
+
+ class_<ElemHideBase,ActiveFilter>("ElemHideBase")
+ .property("selector", &ElemHideBase::GetSelector)
+ .property("selectorDomain", &ElemHideBase::GetSelectorDomain);
+
+ class_<ElemHideFilter,ElemHideBase>("ElemHideFilter")
+ .class_property("type", "'elemhide'");
+
+ class_<ElemHideException,ElemHideBase>("ElemHideException")
+ .class_property("type", "'elemhideexception'");
+
+ class_<CSSPropertyFilter,ElemHideBase>("CSSPropertyFilter")
+ .class_property("type", "'cssproperty'")
+ .property("regexpString", &CSSPropertyFilter::GetRegExpString)
+ .property("selectorPrefix", &CSSPropertyFilter::GetSelectorPrefix)
+ .property("selectorSuffix", &CSSPropertyFilter::GetSelectorSuffix);
+}
+#endif

Powered by Google App Engine
This is Rietveld