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

refactor: redesign bridge code base #18

Merged
merged 401 commits into from
Oct 21, 2022

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.

Copy link
Member

@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 出一些无关紧要的东西了)

bridge/CMakeLists.txt Outdated Show resolved Hide resolved
bridge/polyfill/src/index.ts Outdated Show resolved Hide resolved
bridge/polyfill/src/location.ts Outdated Show resolved Hide resolved
bridge/polyfill/src/location.ts Outdated Show resolved Hide resolved
integration_tests/scripts/core_integration_starter.js Outdated Show resolved Hide resolved
@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.

None yet

5 participants