You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by wentao shi <to...@gmail.com> on 2017/11/29 13:50:37 UTC

Use multi context for Weex page

As we know, Weex is using custom js engine (JavascriptCore) on Android as
same as IOS. When Weex startup will inject a long js script that we call it
jsf to JSC. This action could generate many global object which share on
diff page.
if one page change that global object, will impact all page. For example,
we could use this script
http://dotwe.org/vue/522f075bbeed1479486c067781c41adc  to change global
object, if other page use "setTimeout" may throw js exception. So we want
use multi context for Weex page, that one page cannot  impact other pages.


As the picture shows, create globla class on Global Context and transform
limited & controllable class to Instance Context which each Weex page has
one.

What do you think fellows?

Best regards, Toretto

Re: Use multi context for Weex page

Posted by Hanks Zhang <zh...@gmail.com>.
The implementation in js framework is finished, and I sent a PR [1] to
merge it into the master branch.

The Vue.js framework and native render engines have already achieved it and
all unit tests are passed (poison: [2] validator: [3]). I think it's time
to test it in some real cases, such as the TaoBao app.

[1] https://github.com/apache/incubator-weex/pull/960
[2] http://dotwe.org/vue/665a40b9ccc937025fceda627937f659
[3] http://dotwe.org/vue/5a182754bf404b314d70a4ced455c3e8

2017-12-19 16:47 GMT+08:00 Hanks Zhang <zh...@gmail.com>:

> For the Vue.js framework, I sent a PR [1] to achieve it. I think Rax
> should do the same thing.
>
> In the PR, I removed legacy framework APIs and use "createInstanceContext"
> instead of "createInstance" to create the Vue module instance for each page.
>
> Native render engines should also call "createInstanceContext" instead of
> "createInstance", and the source code is no longer needed. Another change
> is, the bundle type of the code (Vue or Rax) should be parsed in native and
> send it to js framework.
>
> [1] https://github.com/vuejs/vue/pull/7272
>
> 2017-12-04 16:22 GMT+08:00 Hanks Zhang <zh...@gmail.com>:
>
>> +1. Currently, multiple js bundles are executed in the same js context,
>> and the isolation is implemented by js, which is not robust.
>>
>> In my opinion, the most reasonable solution is to distinguish the "Global
>> Context" and the "Instance Context", move the logic of instance management
>> and code execution from js to native.
>>
>> On this basis, I think there are some sub-problems that need to be solved:
>>
>> (1). How to expose APIs from Global Context to Instance Context?
>> (2). How to isolate those exposed APIs?
>> (3). Adjustments of Vue and Rax.
>> (4). Impact on performance.
>> (5). What about the platform APIs and the polyfills? Such as console,
>> Object.assign, and timer.
>> (6). Redesign the js service.
>>
>> Feel free to discuss any of these topics, or add one.
>>
>> Best regards, Hanks
>>
>
>

Re: Use multi context for Weex page

Posted by Hanks Zhang <zh...@gmail.com>.
For the Vue.js framework, I sent a PR [1] to achieve it. I think Rax should
do the same thing.

In the PR, I removed legacy framework APIs and use "createInstanceContext"
instead of "createInstance" to create the Vue module instance for each page.

Native render engines should also call "createInstanceContext" instead of
"createInstance", and the source code is no longer needed. Another change
is, the bundle type of the code (Vue or Rax) should be parsed in native and
send it to js framework.

[1] https://github.com/vuejs/vue/pull/7272

2017-12-04 16:22 GMT+08:00 Hanks Zhang <zh...@gmail.com>:

> +1. Currently, multiple js bundles are executed in the same js context,
> and the isolation is implemented by js, which is not robust.
>
> In my opinion, the most reasonable solution is to distinguish the "Global
> Context" and the "Instance Context", move the logic of instance management
> and code execution from js to native.
>
> On this basis, I think there are some sub-problems that need to be solved:
>
> (1). How to expose APIs from Global Context to Instance Context?
> (2). How to isolate those exposed APIs?
> (3). Adjustments of Vue and Rax.
> (4). Impact on performance.
> (5). What about the platform APIs and the polyfills? Such as console,
> Object.assign, and timer.
> (6). Redesign the js service.
>
> Feel free to discuss any of these topics, or add one.
>
> Best regards, Hanks
>

Re: Use multi context for Weex page

Posted by Hanks Zhang <zh...@gmail.com>.
+1. Currently, multiple js bundles are executed in the same js context, and
the isolation is implemented by js, which is not robust.

In my opinion, the most reasonable solution is to distinguish the "Global
Context" and the "Instance Context", move the logic of instance management
and code execution from js to native.

On this basis, I think there are some sub-problems that need to be solved:

(1). How to expose APIs from Global Context to Instance Context?
(2). How to isolate those exposed APIs?
(3). Adjustments of Vue and Rax.
(4). Impact on performance.
(5). What about the platform APIs and the polyfills? Such as console,
Object.assign, and timer.
(6). Redesign the js service.

Feel free to discuss any of these topics, or add one.

Best regards, Hanks

Re: Use multi context for Weex page

Posted by xing zhang <zh...@gmail.com>.
I think that this action should be done as soon as possible,  there are so
much problem such as memory issue and context `pollution` for the shared
context.

2017-11-29 21:50 GMT+08:00 wentao shi <to...@gmail.com>:

> As we know, Weex is using custom js engine (JavascriptCore) on Android as
> same as IOS. When Weex startup will inject a long js script that we call it
> jsf to JSC. This action could generate many global object which share on
> diff page.
> if one page change that global object, will impact all page. For example,
> we could use this script http://dotwe.org/vue/
> 522f075bbeed1479486c067781c41adc  to change global object, if other page
> use "setTimeout" may throw js exception. So we want use multi context for
> Weex page, that one page cannot  impact other pages.
>
>
> As the picture shows, create globla class on Global Context and transform
> limited & controllable class to Instance Context which each Weex page has
> one.
>
> What do you think fellows?
>
> Best regards, Toretto
>