Index: compiled/api.cpp |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/compiled/api.cpp |
@@ -0,0 +1,282 @@ |
+#include <exception> |
+ |
+#include <emscripten.h> |
+#include <emscripten/trace.h> |
+ |
+#include "Filter.h" |
+#include "InvalidFilter.h" |
+#include "ActiveFilter.h" |
+#include "RegExpFilter.h" |
+#include "ElemHideBase.h" |
+#include "CSSPropertyFilter.h" |
+#include "String.h" |
+ |
+#define DO_PRAGMA(pragma) _Pragma(#pragma) |
+#define INSERT_MESSAGE(m) DO_PRAGMA(comment(m)) |
+ |
+#define CLASS(name) \ |
+ extern "C"\ |
+ INSERT_MESSAGE(class name) |
+ |
+#define AUGMENTS(name) INSERT_MESSAGE(augments name) |
+#define CLASS_INIT(func) INSERT_MESSAGE(class_init func) |
+ |
+#define METHOD(name, impl) INSERT_MESSAGE(method name impl) |
+#define CLASS_METHOD(name, impl) INSERT_MESSAGE(class_method name impl) |
+#define STRING_ARG(pos) INSERT_MESSAGE(string_arg pos) |
+#define RETURNS_STRING INSERT_MESSAGE(string_result) |
+#define RETURNS_POINTER(cls) INSERT_MESSAGE(pointer_result cls) |
+ |
+#define READONLY_PROPERTY(name, getter) INSERT_MESSAGE(property name getter) |
+#define PROPERTY(name, getter, setter) INSERT_MESSAGE(property name getter setter) |
+#define READONLY_STRING_PROPERTY(name, getter) INSERT_MESSAGE(string_property name getter) |
+#define STRING_PROPERTY(name, getter, setter) INSERT_MESSAGE(string_property name getter setter) |
+#define STATIC_PROPERTY(name, value) INSERT_MESSAGE(static_property name value) |
+ |
+#define DIFFERENTIATOR(cls, func) INSERT_MESSAGE(differentiator cls func) |
+#define ASSOCIATE(value, cls) INSERT_MESSAGE(differentiator_mapping value cls) |
+ |
+#if defined(__EMSCRIPTEN_TRACING__) |
+struct InitTracing |
+{ |
+ InitTracing() |
+ { |
+ emscripten_trace_configure("http://127.0.0.1:5000/", "MyApplication"); |
+ } |
+ |
+ ~InitTracing() |
+ { |
+ emscripten_trace_close(); |
+ } |
+}; |
+ |
+InitTracing foo; |
+#endif |
+ |
+#define EXPOSE_FILTER_PROPERTY(class, type, name, getter, setter) \ |
+ type EMSCRIPTEN_KEEPALIVE class##_##getter(const class* filter)\ |
+ {\ |
+ return filter->getter();\ |
+ }\ |
+ void EMSCRIPTEN_KEEPALIVE class##_##setter(\ |
+ class* filter, type value)\ |
+ {\ |
+ filter->setter(value);\ |
+ }\ |
+ PROPERTY(name, class##_##getter, class##_##setter) |
+ |
+#pragma clang diagnostic push |
+#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" |
+ |
+extern "C" |
+{ |
+ size_t EMSCRIPTEN_KEEPALIVE GetSizeofString() |
+ { |
+ return sizeof(String); |
+ } |
+ |
+ 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 DeletePointer(Filter* ptr) |
+ { |
+ ptr->ReleaseRef(); |
+ } |
+} |
+ |
+DIFFERENTIATOR(Filter, Filter_GetType) |
+ ASSOCIATE(1, InvalidFilter) |
+ ASSOCIATE(2, CommentFilter) |
+ ASSOCIATE(3, RegExpFilter) |
+ ASSOCIATE(4, WhitelistFilter) |
+ ASSOCIATE(5, ElemHideFilter) |
+ ASSOCIATE(6, ElemHideException) |
+ ASSOCIATE(7, CSSPropertyFilter) |
+ |
+CLASS(Filter) |
+{ |
+ String EMSCRIPTEN_KEEPALIVE Filter_GetText(const Filter* filter) |
+ { |
+ return filter->GetText(); |
+ } |
+ READONLY_STRING_PROPERTY(text, Filter_GetText) |
+ |
+ Filter::Type EMSCRIPTEN_KEEPALIVE Filter_GetType(const Filter* filter) |
+ { |
+ return filter->GetType(); |
+ } |
+ |
+ String EMSCRIPTEN_KEEPALIVE Filter_Serialize(const Filter* filter) |
+ { |
+ return filter->Serialize(); |
+ } |
+ METHOD(serialize, Filter_Serialize) RETURNS_STRING |
+ |
+ Filter* EMSCRIPTEN_KEEPALIVE Filter_FromText(String& text) |
+ { |
+ Filter* filter = Filter::FromText(text); |
+ filter->AddRef(); |
+ return filter; |
+ } |
+ CLASS_METHOD(fromText, Filter_FromText) STRING_ARG(0) RETURNS_POINTER(Filter) |
+ |
+ String EMSCRIPTEN_KEEPALIVE Filter_Normalize(String& text) |
+ { |
+ return Filter::Normalize(text); |
+ } |
+ CLASS_METHOD(normalize, Filter_Normalize) STRING_ARG(0) RETURNS_STRING |
+} |
+ |
+CLASS(InvalidFilter) |
+{ |
+ AUGMENTS(Filter) |
+ STATIC_PROPERTY(type, "invalid") |
+ |
+ String EMSCRIPTEN_KEEPALIVE InvalidFilter_GetReason(const InvalidFilter* filter) |
+ { |
+ return filter->GetReason(); |
+ } |
+ READONLY_STRING_PROPERTY(reason, InvalidFilter_GetReason) |
+} |
+ |
+CLASS(CommentFilter) |
+{ |
+ AUGMENTS(Filter) |
+ STATIC_PROPERTY(type, "comment") |
+} |
+ |
+CLASS(ActiveFilter) |
+{ |
+ AUGMENTS(Filter) |
+ |
+ EXPOSE_FILTER_PROPERTY(ActiveFilter, bool, disabled, GetDisabled, SetDisabled); |
+ EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, hitCount, GetHitCount, SetHitCount); |
+ EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, lastHit, GetLastHit, SetLastHit); |
+ |
+ bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnDomain( |
+ const ActiveFilter* filter, String& domain, String& sitekey) |
+ { |
+ return filter->IsActiveOnDomain(domain, sitekey); |
+ } |
+ METHOD(isActiveOnDomain, ActiveFilter_IsActiveOnDomain) STRING_ARG(0) STRING_ARG(1) |
+ |
+ bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnlyOnDomain( |
+ const ActiveFilter* filter, String& domain) |
+ { |
+ return filter->IsActiveOnlyOnDomain(domain); |
+ } |
+ METHOD(isActiveOnlyOnDomain, ActiveFilter_IsActiveOnlyOnDomain) STRING_ARG(0) |
+ |
+ bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsGeneric(const ActiveFilter* filter) |
+ { |
+ return filter->IsGeneric(); |
+ } |
+ METHOD(isGeneric, ActiveFilter_IsGeneric) |
+} |
+ |
+CLASS(RegExpFilter) |
+{ |
+ AUGMENTS(ActiveFilter) |
+ STATIC_PROPERTY(type, "blocking") |
+ |
+ bool EMSCRIPTEN_KEEPALIVE RegExpFilter_Matches(const RegExpFilter* filter, |
+ String& location, int typeMask, String& docDomain, bool thirdParty, |
+ String& sitekey) |
+ { |
+ return filter->Matches(location, typeMask, docDomain, thirdParty, sitekey); |
+ } |
+ METHOD(matches, RegExpFilter_Matches) STRING_ARG(0) STRING_ARG(2) STRING_ARG(4) |
+ |
+ void EMSCRIPTEN_KEEPALIVE RegExpFilter_InitJSTypes() |
+ { |
+ RegExpFilter::InitJSTypes(); |
+ } |
+ CLASS_INIT(RegExpFilter_InitJSTypes) |
+} |
+ |
+CLASS(WhitelistFilter) |
+{ |
+ AUGMENTS(RegExpFilter) |
+ STATIC_PROPERTY(type, "whitelist") |
+} |
+ |
+CLASS(ElemHideBase) |
+{ |
+ AUGMENTS(ActiveFilter) |
+ |
+ String EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelector( |
+ const ElemHideBase* filter) |
+ { |
+ return filter->GetSelector(); |
+ } |
+ READONLY_STRING_PROPERTY(selector, ElemHideBase_GetSelector) |
+ |
+ String EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelectorDomain( |
+ const ElemHideBase* filter) |
+ { |
+ return filter->GetSelectorDomain(); |
+ } |
+ READONLY_STRING_PROPERTY(selectorDomain, ElemHideBase_GetSelectorDomain) |
+} |
+ |
+CLASS(ElemHideFilter) |
+{ |
+ AUGMENTS(ElemHideBase) |
+ STATIC_PROPERTY(type, "elemhide") |
+} |
+ |
+CLASS(ElemHideException) |
+{ |
+ AUGMENTS(ElemHideBase) |
+ STATIC_PROPERTY(type, "elemhideexception") |
+} |
+ |
+CLASS(CSSPropertyFilter) |
+{ |
+ AUGMENTS(ElemHideBase) |
+ STATIC_PROPERTY(type, "cssproperty") |
+ |
+ String EMSCRIPTEN_KEEPALIVE CSSPropertyFilter_GetRegExpString( |
+ const CSSPropertyFilter* filter) |
+ { |
+ return filter->GetRegExpString(); |
+ } |
+ READONLY_STRING_PROPERTY(regexpString, CSSPropertyFilter_GetRegExpString) |
+ |
+ String EMSCRIPTEN_KEEPALIVE CSSPropertyFilter_GetSelectorPrefix( |
+ const CSSPropertyFilter* filter) |
+ { |
+ return filter->GetSelectorPrefix(); |
+ } |
+ READONLY_STRING_PROPERTY(selectorPrefix, CSSPropertyFilter_GetSelectorPrefix) |
+ |
+ String EMSCRIPTEN_KEEPALIVE CSSPropertyFilter_GetSelectorSuffix( |
+ const CSSPropertyFilter* filter) |
+ { |
+ return filter->GetSelectorSuffix(); |
+ } |
+ READONLY_STRING_PROPERTY(selectorSuffix, CSSPropertyFilter_GetSelectorSuffix) |
+} |
+ |
+#pragma clang diagnostic pop |