Skip to content

Conversation

andycall
Copy link
Member

@andycall andycall commented Aug 9, 2022

Complete re-design the code base of bridge, fix hard-core problems and improve the performance.

Note: this PR removed 95% of original bridge's code.

The hard-core problems in bridge:

  1. All implements are mixed with QuickJS API, memory management are messed, no one knows how many retaining bugs in there.
  2. Al the binding glue code are written by hand, it wasted too much time.
  3. The DOM tree are implemented by QuickJS data structures, it's not efficient.

Performance improvement

  1. 2x faster on Node.appendChild API
  2. 5x faster on Node.insertBefore API

image

The new design:

  1. Split out the code base to core and bindings directory. core aims to DOM and Web API, bindings aims to all interactions to QuickJS API.
  2. Manage QuickJS JSValue reference count with stack.
  3. Use code generator to generate all API glue code.
  4. Make all initialize data to static and read-only.
  5. re-design DOM API
    1. EventTarget
    2. Node
    3. ContainerNode
    4. Element
    5. Document
    6. Attr
    7. CharacterData
    8. DocumentFragment
    9. Text
    10. NodeList
    11. CSSStyleDeclaration
    12. CustomElement
    13. CustomEvent
    14. DOM Selector
  6. Make more useful string statically and pre-allocated at build stage.

Design Notes:

Split out core and interface

Type kind conversion with TypeScript and C++.

Based on the type define in TypeScript typings and generated the corresponding C++ call code. The call code are formed by C++ Converter class, responsible to easy convert any JS kind to C++ kind.

JS C++
double TSDouble
int64 TSInt64
boolean TSBool
double? TSOptional<TSDouble>
double | null TSNullable<TSDouble>
double[] TSSequence<TSDouble>
type BlobPart = { name: string, value: double} TSBlobPart // 自定义类型需要独立实现转换器
any TSAny

Example:

template <>
struct Converter<TSDouble> : public ConverterBase<TSDouble> {
  static ImplType FromValue(JSContext* ctx, JSValue value) {
    assert(!JS_IsException(value));
    double v;
    JS_ToFloat64(ctx, &v, value);
    return v;
  }

  static JSValue ToValue(JSContext* ctx, double v) { return JS_NewFloat64(ctx, v); }
};

image

How properties and methods defined

JS code use prototype to access native defined properties and methods.

@andycall andycall force-pushed the refactor/remove_host_class branch from c55a19f to c0e64e6 Compare August 9, 2022 09:31
@andycall andycall force-pushed the refactor/remove_host_class branch from c0e64e6 to 03a87cc Compare August 9, 2022 10:33
@andycall andycall force-pushed the refactor/remove_host_class branch from 8a5e4d5 to 0b35f50 Compare August 9, 2022 13:47
@andycall andycall force-pushed the refactor/remove_host_class branch from 23c1b81 to d8a5f14 Compare August 14, 2022 15:15
@andycall andycall force-pushed the refactor/remove_host_class branch from d774707 to 5c9554c Compare August 15, 2022 15:49
@andycall andycall force-pushed the refactor/remove_host_class branch from 21dd6ee to 8cf26ff Compare August 17, 2022 09:27
Copy link
Contributor

@XGHeaven XGHeaven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • bridge/third_party/quickjs/quickjs.c file is empty, remove it.
  • The integration snapshot files about hsl/hsla should not be added. Maybe rebase the main branch and rerun to fix it.

(PS: 实在是看不懂,只能 re 出一些无关紧要的东西了)

@andycall andycall force-pushed the refactor/remove_host_class branch from 0b036d3 to b88c8b5 Compare October 13, 2022 10:53
@andycall andycall merged commit f89f731 into feat/css_selector Oct 21, 2022
@liuzitong123a liuzitong123a mentioned this pull request Oct 21, 2022
1 task
looseyi pushed a commit that referenced this pull request May 29, 2024
[0.14.2][Android] [fix]: fix double click issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants