Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize create element and create text node. #952

Merged
merged 26 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
168841f
feat: optimize create element and create textnode.
andycall Dec 8, 2021
98224cf
feat: optimize all nodes.
andycall Dec 8, 2021
ad56a79
Committing clang-format changes
Dec 8, 2021
ee9388c
feat: create setter to standalone function.
andycall Dec 8, 2021
0d8300c
feat: generate setter by needs.
andycall Dec 8, 2021
e3f1ec8
feat: use JSPropertyDescriptor instead of magic
andycall Dec 8, 2021
15f9517
Merge branch 'feat/optimize-create-element' of github.com:openkraken/…
andycall Dec 8, 2021
6d26cae
Committing clang-format changes
Dec 8, 2021
e2aa09d
fix: fix customEvent.detail and Event.cancelBubble.
andycall Dec 9, 2021
d4caa50
Merge branch 'feat/optimize-create-element' of github.com:openkraken/…
andycall Dec 9, 2021
65c323f
chore: rename macros.
andycall Dec 9, 2021
6fa8be7
refactor: refactor TemplateElement.
andycall Dec 9, 2021
af2389e
chore: remove test code.
andycall Dec 9, 2021
22dd3e9
Committing clang-format changes
Dec 9, 2021
17ef126
Merge remote-tracking branch 'origin/main' into feat/optimize-create-…
andycall Dec 9, 2021
34df7da
refactor: rename PROP_GETTER and PROP_SETTER
andycall Dec 9, 2021
93fb600
Merge branch 'feat/optimize-create-element' of github.com:openkraken/…
andycall Dec 9, 2021
fb92107
fix: fix text node
andycall Dec 9, 2021
0da17b4
fix: rename prop macro and fix instance prototype.
andycall Dec 9, 2021
8d27fe8
fix: fix prop getter no ENUMERABLE.
andycall Dec 9, 2021
51a47e7
refactor: refactor macros.
andycall Dec 9, 2021
6b43f30
fix: fix code linter
andycall Dec 9, 2021
da84c1b
refactor: refactor ObjectFunction to macro.
andycall Dec 10, 2021
71b5549
fix: fix performance
andycall Dec 10, 2021
67088ec
fix: fix style methods.
andycall Dec 10, 2021
519c7d4
refactor: rename prop getter and setter.
andycall Dec 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions bridge/bindings/qjs/bom/blob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,15 @@ JSValue Blob::instanceConstructor(QjsContext* ctx, JSValue func_obj, JSValue thi
return blob->instanceObject;
}

PROP_GETTER(BlobInstance, type)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_GETTER(Blob, type)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* blobInstance = static_cast<BlobInstance*>(JS_GetOpaque(this_val, Blob::kBlobClassID));
return JS_NewString(blobInstance->m_ctx, blobInstance->mimeType.empty() ? "" : blobInstance->mimeType.c_str());
}
PROP_SETTER(BlobInstance, type)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(BlobInstance, size)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_GETTER(Blob, size)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* blobInstance = static_cast<BlobInstance*>(JS_GetOpaque(this_val, Blob::kBlobClassID));
return JS_NewFloat64(blobInstance->m_ctx, blobInstance->_size);
}
PROP_SETTER(BlobInstance, size)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

JSValue Blob::arrayBuffer(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
JSValue resolving_funcs[2];
Expand Down
2 changes: 1 addition & 1 deletion bridge/bindings/qjs/bom/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Blob : public HostClass {

private:
friend BlobInstance;
DEFINE_HOST_CLASS_PROTOTYPE_GETTER_PROPERTY(2, type, size);

ObjectFunction m_arrayBuffer{m_context, m_prototypeObject, "arrayBuffer", arrayBuffer, 0};
ObjectFunction m_slice{m_context, m_prototypeObject, "slice", slice, 3};
Expand All @@ -51,7 +52,6 @@ class BlobInstance : public Instance {
int32_t size();

private:
DEFINE_HOST_CLASS_PROPERTY(2, type, size);
size_t _size;
std::string mimeType{""};
std::vector<uint8_t> _data;
Expand Down
31 changes: 4 additions & 27 deletions bridge/bindings/qjs/bom/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ PROP_GETTER(Window, devicePixelRatio)(QjsContext* ctx, JSValue this_val, int arg
double devicePixelRatio = getDartMethod()->devicePixelRatio(context->getContextId());
return JS_NewFloat64(ctx, devicePixelRatio);
}
PROP_SETTER(Window, devicePixelRatio)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}


PROP_GETTER(Window, colorScheme)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
if (getDartMethod()->platformBrightness == nullptr) {
Expand All @@ -92,56 +90,38 @@ PROP_GETTER(Window, colorScheme)(QjsContext* ctx, JSValue this_val, int argc, JS
const NativeString* code = getDartMethod()->platformBrightness(context->getContextId());
return JS_NewUnicodeString(context->runtime(), ctx, code->string, code->length);
}
PROP_SETTER(Window, colorScheme)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}


PROP_GETTER(Window, __location__)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* window = static_cast<WindowInstance*>(JS_GetOpaque(this_val, 1));
if (window == nullptr)
return JS_UNDEFINED;
return JS_DupValue(ctx, window->m_location.value());
}
PROP_SETTER(Window, __location__)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}


PROP_GETTER(Window, location)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* window = static_cast<WindowInstance*>(JS_GetOpaque(this_val, 1));
return JS_GetPropertyStr(ctx, window->m_context->global(), "location");
}
PROP_SETTER(Window, location)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(Window, window)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_GetGlobalObject(ctx);
}
PROP_SETTER(Window, window)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(Window, parent)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_GetGlobalObject(ctx);
}
PROP_SETTER(Window, parent)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(Window, scrollX)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* window = static_cast<WindowInstance*>(JS_GetOpaque(this_val, 1));
return window->callNativeMethods("scrollX", 0, nullptr);
}
PROP_SETTER(Window, scrollX)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(Window, scrollY)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* window = static_cast<WindowInstance*>(JS_GetOpaque(this_val, 1));
return window->callNativeMethods("scrollY", 0, nullptr);
}
PROP_SETTER(Window, scrollY)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(Window, onerror)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* window = static_cast<WindowInstance*>(JS_GetOpaque(this_val, 1));
Expand All @@ -162,9 +142,6 @@ PROP_SETTER(Window, onerror)(QjsContext* ctx, JSValue this_val, int argc, JSValu
return JS_NULL;
}

PROP_SETTER(Window, self)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}
PROP_GETTER(Window, self)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_GetGlobalObject(ctx);
}
Expand Down
3 changes: 2 additions & 1 deletion bridge/bindings/qjs/bom/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class Window : public EventTarget {
ObjectFunction m_scrollBy{m_context, m_prototypeObject, "scrollBy", scrollBy, 2};
ObjectFunction m_postMessage{m_context, m_prototypeObject, "postMessage", postMessage, 3};

DEFINE_HOST_CLASS_PROTOTYPE_PROPERTY(10, devicePixelRatio, colorScheme, __location__, location, window, parent, scrollX, scrollY, onerror, self);
DEFINE_HOST_CLASS_PROTOTYPE_GETTER_PROPERTY(9, devicePixelRatio, colorScheme, __location__, location, window, parent, scrollX, scrollY, self)
DEFINE_HOST_CLASS_PROTOTYPE_PROPERTY(1, onerror);
friend WindowInstance;
};

Expand Down
15 changes: 3 additions & 12 deletions bridge/bindings/qjs/dom/comment_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,17 @@ JSValue Comment::instanceConstructor(QjsContext* ctx, JSValue func_obj, JSValue
return (new CommentInstance(this))->instanceObject;
}

PROP_GETTER(CommentInstance, data)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_GETTER(Comment, data)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NewString(ctx, "");
}
PROP_SETTER(CommentInstance, data)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(CommentInstance, nodeName)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_GETTER(Comment, nodeName)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NewString(ctx, "#comment");
}
PROP_SETTER(CommentInstance, nodeName)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(CommentInstance, length)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_GETTER(Comment, length)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NewUint32(ctx, 0);
}
PROP_SETTER(CommentInstance, length)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

CommentInstance::CommentInstance(Comment* comment) : NodeInstance(comment, NodeType::COMMENT_NODE, DocumentInstance::instance(Document::instance(comment->m_context)), Comment::classId(), "Comment") {
::foundation::UICommandBuffer::instance(m_context->getContextId())->addCommand(m_eventTargetId, UICommand::createComment, nativeEventTarget);
Expand Down
3 changes: 1 addition & 2 deletions bridge/bindings/qjs/dom/comment_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Comment : public Node {
JSValue instanceConstructor(QjsContext* ctx, JSValue func_obj, JSValue this_val, int argc, JSValue* argv) override;

private:
DEFINE_HOST_CLASS_PROTOTYPE_GETTER_PROPERTY(3, data, nodeName, length)
friend CommentInstance;
};

Expand All @@ -35,8 +36,6 @@ class CommentInstance : public NodeInstance {
explicit CommentInstance(Comment* comment);

private:
DEFINE_HOST_CLASS_PROPERTY(3, data, nodeName, length)

friend Comment;
};

Expand Down
9 changes: 1 addition & 8 deletions bridge/bindings/qjs/dom/custom_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,10 @@ JSValue CustomEvent::instanceConstructor(QjsContext* ctx, JSValue func_obj, JSVa
return customEvent->instanceObject;
}

PROP_GETTER(CustomEventInstance, detail)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_GETTER(CustomEvent, detail)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* customEventInstance = static_cast<CustomEventInstance*>(JS_GetOpaque(this_val, Event::kEventClassID));
return customEventInstance->m_detail.value();
}
PROP_SETTER(CustomEventInstance, detail)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
if (argc == 0)
return JS_NULL;
auto* customEventInstance = static_cast<CustomEventInstance*>(JS_GetOpaque(this_val, Event::kEventClassID));
customEventInstance->m_detail.value(argv[0]);
return JS_NULL;
}

CustomEventInstance::CustomEventInstance(CustomEvent* jsCustomEvent, JSAtom customEventType, JSValue eventInit) : EventInstance(jsCustomEvent, customEventType, eventInit) {
if (!JS_IsNull(eventInit)) {
Expand Down
3 changes: 1 addition & 2 deletions bridge/bindings/qjs/dom/custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CustomEvent : public Event {
OBJECT_INSTANCE(CustomEvent);

private:
DEFINE_HOST_CLASS_PROTOTYPE_GETTER_PROPERTY(1, detail);
andycall marked this conversation as resolved.
Show resolved Hide resolved
ObjectFunction m_initCustomEvent{m_context, m_prototypeObject, "initCustomEvent", initCustomEvent, 4};
friend CustomEventInstance;
};
Expand All @@ -39,8 +40,6 @@ class CustomEventInstance : public EventInstance {
explicit CustomEventInstance(CustomEvent* jsCustomEvent, NativeCustomEvent* nativeCustomEvent);

private:
DEFINE_HOST_CLASS_PROPERTY(1, detail);

JSValueHolder m_detail{m_ctx, JS_NULL};
NativeCustomEvent* nativeCustomEvent{nullptr};
friend CustomEvent;
Expand Down
14 changes: 4 additions & 10 deletions bridge/bindings/qjs/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,11 @@ bool Document::isCustomElement(const std::string& tagName) {
return elementConstructorMap.count(tagName) > 0;
}

PROP_GETTER(DocumentInstance, nodeName)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_GETTER(Document, nodeName)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NewString(ctx, "#document");
}
PROP_SETTER(DocumentInstance, nodeName)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(DocumentInstance, all)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_GETTER(Document, all)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* document = static_cast<DocumentInstance*>(JS_GetOpaque(this_val, Document::classId()));
auto all = new AllCollection(document->m_context);

Expand All @@ -318,16 +315,13 @@ PROP_GETTER(DocumentInstance, all)(QjsContext* ctx, JSValue this_val, int argc,

return all->jsObject;
}
PROP_SETTER(DocumentInstance, all)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
return JS_NULL;
}

PROP_GETTER(DocumentInstance, cookie)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_GETTER(Document, cookie)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* document = static_cast<DocumentInstance*>(JS_GetOpaque(this_val, Document::classId()));
std::string cookie = document->m_cookie->getCookie();
return JS_NewString(ctx, cookie.c_str());
}
PROP_SETTER(DocumentInstance, cookie)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
PROP_SETTER(Document, cookie)(QjsContext* ctx, JSValue this_val, int argc, JSValue* argv) {
auto* document = static_cast<DocumentInstance*>(JS_GetOpaque(this_val, Document::classId()));
std::string value = jsValueToStdString(ctx, argv[0]);
document->m_cookie->setCookie(value);
Expand Down
5 changes: 3 additions & 2 deletions bridge/bindings/qjs/dom/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class Document : public Node {
bool isCustomElement(const std::string& tagName);

private:
DEFINE_HOST_CLASS_PROTOTYPE_GETTER_PROPERTY(2, nodeName, all)
DEFINE_HOST_CLASS_PROTOTYPE_PROPERTY(1, cookie);

void defineElement(const std::string& tagName, Element* constructor);

ObjectFunction m_createEvent{m_context, m_prototypeObject, "createEvent", createEvent, 1};
Expand Down Expand Up @@ -86,8 +89,6 @@ class DocumentInstance : public NodeInstance {
}

private:
DEFINE_HOST_CLASS_PROPERTY(3, nodeName, all, cookie);

void removeElementById(JSAtom id, ElementInstance* element);
void addElementById(JSAtom id, ElementInstance* element);
std::unordered_map<JSAtom, std::vector<ElementInstance*>> m_elementMapById;
Expand Down
Loading