-
Notifications
You must be signed in to change notification settings - Fork 303
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
[WIP]: refactor: redesign bridge code base #1063
base: main
Are you sure you want to change the base?
Conversation
aebe7b6
to
3449e36
Compare
0ca4d99
to
d80b528
Compare
a337c2e
to
16bdee7
Compare
94d4bfe
to
5c1dd1b
Compare
68777ae
to
ace4002
Compare
206f48e
to
d55a199
Compare
065ee27
to
2570240
Compare
…aken into refactor/remove_host_class
…aken into refactor/remove_host_class
50fb8fb
to
63f27a7
Compare
22ff003
to
46dccea
Compare
feat: remove init window and init document dart methods.
659212a
to
c0bca99
Compare
1090b29
to
65d6f89
Compare
027b27f
to
6a145bd
Compare
acfa8b7
to
0652de3
Compare
2c8c0a1
to
05e59b9
Compare
这个pr还有问题吗?看起来做了很不错的修改,改动较大,原始团队评估能合入了么 |
原始团队很难找到人 review 了,估计要组建新团队之后重新 review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ 53%] Building CXX object CMakeFiles/kraken.dir/core/dom/node_traversal.cc.o
[ 53%] Building CXX object CMakeFiles/kraken.dir/core/dom/character_data.cc.o
/Users/vivo/AndroidStudioProjects/kraken/bridge/core/dom/events/event.cc:13:64: error: cannot initialize a parameter of type 'kraken::NativeString ' with an lvalue of type
'int64_t' (aka 'long long')
AtomicString event_type = AtomicString::From(context->ctx(), native_event->type);
^~~~~~~~~~~~~~~~~~
/Users/vivo/AndroidStudioProjects/kraken/bridge/bindings/qjs/atomic_string.h:34:58: note: passing argument to parameter 'native_string' here
static AtomicString From(JSContext ctx, NativeString* native_string);
^
/Users/vivo/AndroidStudioProjects/kraken/bridge/core/dom/events/event.cc:19:20: error: cannot cast from type 'int64_t' (aka 'long long') to pointer type
'kraken::EventTarget '
event->SetTarget(static_cast<EventTarget>(native_event->target));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/vivo/AndroidStudioProjects/kraken/bridge/core/dom/events/event.cc:20:27: error: cannot cast from type 'int64_t' (aka 'long long') to pointer type
'kraken::EventTarget '
event->SetCurrentTarget(static_cast<EventTarget>(native_event->currentTarget));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 55%] Building CXX object CMakeFiles/kraken.dir/core/dom/comment.cc.o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外:package.json 需要添加json5的依赖
c56d52e
to
84068e4
Compare
对 bridge 的实现进行重新设计,用更好的方案解决一些固有的顽疾,并有效提升 bridge 的运行性能。
Bridge 目前存在的顽疾:
基于以上问题,采用一些新的设计思路方案:
Design Notes:
实现层与接口之间的分离
TS 类型与 C++ 类型之间的转换
依据 TS 类型的信息,生成对应调用
Converter
的代码。Converter
是一个 C++ Type Trains 类,负责将各种类型 JS 值转换为 C++ 值。基本的类型映射关系:
TSOptional<TSDouble>
TSNullable<TSDouble>
TSSequence<TSDouble>
生成器实现范例
JS API 的装载过程
生成器生成的 API 代码需要通过装载才可以被注入到 JS 的全局环境中,供 JS 访问。
装载会在 Bridge 初始化到时候进行调用。
JS 环境中类构造函数
JS 环境大部分的 API 都是通过构造函数来创建,比如 EventTarget,Element,Node 这些都可以直接全部访问的变量。通过构造函数所创建的对象的原型都指向构造函数。
构造函数都是全局性的,即同一种类型的构造函数,在一个 JSContext 中只会存在一个。同时这些值都将存储在
ExecutionContextData
这样一个全局的对象中。读取一个方法的过程
JS 采用原型链的方式实现继承,所以访问属性和方法会按照原型链来进行定位。
GC 回收的过程
在 bindings 目录有一个叫做
GarbageCollected
的类,所有继承它的类的内存管理均交给 JS 引擎的 GC 来承担,所以在 C++ 环境中不需要额外对这些类做内存回收操作。GC 的回收分为两个阶段,
EventTarget