fix: eval (#3877)
This commit is contained in:
1 parent
a1107de0c0
commit
9ffa42392f
10 files changed
+31
-6
No files matched your search
@@ -1 +1 @@
|
|||||||
[14101548031762241351]
|
[16018260687765471498]
|
||||||
@@ -1 +1 @@
|
|||||||
class Channel{pending;waiting;constructor(){this.pending=[],this.waiting=[]}send(data){if(this.waiting.length>0){this.waiting.shift()(data);return}this.pending.push(data)}async recv(){return new Promise((resolve,_reject)=>{if(this.pending.length>0){resolve(this.pending.shift());return}this.waiting.push(resolve)})}}class WeakDioxusChannel{inner;constructor(channel){this.inner=new WeakRef(channel)}rustSend(data){let channel=this.inner.deref();if(channel)channel.rustSend(data)}async rustRecv(){let channel=this.inner.deref();if(channel)return await channel.rustRecv()}}class DioxusChannel{weak(){return new WeakDioxusChannel(this)}}class QueryParams{id;data;constructor(id,method,data){this.id=id,this.data={method,data}}}window.__msg_queues=window.__msg_queues||[];window.finalizationRegistry=window.finalizationRegistry||new FinalizationRegistry(({id})=>{window.ipc.postMessage(JSON.stringify({method:"query",params:new QueryParams(id,"drop")}))});window.getQuery=function(request_id){return window.__msg_queues[request_id]};window.createQuery=function(request_id){return new NativeDioxusChannel(request_id)};class NativeDioxusChannel extends DioxusChannel{rust_to_js;request_id;constructor(request_id){super();this.rust_to_js=new Channel,this.request_id=request_id,window.__msg_queues[request_id]=this.weak(),window.finalizationRegistry.register(this,{id:request_id})}async recv(){return await this.rust_to_js.recv()}send(data){window.ipc.postMessage(JSON.stringify({method:"query",params:new QueryParams(this.request_id,"send",data)}))}rustSend(data){this.rust_to_js.send(data)}async rustRecv(){}}export{NativeDioxusChannel};
|
class Channel{pending;waiting;constructor(){this.pending=[],this.waiting=[]}send(data){if(this.waiting.length>0){this.waiting.shift()(data);return}this.pending.push(data)}async recv(){return new Promise((resolve,_reject)=>{if(this.pending.length>0){resolve(this.pending.shift());return}this.waiting.push(resolve)})}}class WeakDioxusChannel{inner;constructor(channel){this.inner=new WeakRef(channel)}rustSend(data){let channel=this.inner.deref();if(channel)channel.rustSend(data)}async rustRecv(){let channel=this.inner.deref();if(channel)return await channel.rustRecv()}}class DioxusChannel{weak(){return new WeakDioxusChannel(this)}}class QueryParams{id;data;constructor(id,method,data){this.id=id,this.data={method,data}}}window.__msg_queues=window.__msg_queues||[];window.finalizationRegistry=window.finalizationRegistry||new FinalizationRegistry(({id})=>{window.ipc.postMessage(JSON.stringify({method:"query",params:new QueryParams(id,"drop")}))});window.getQuery=function(request_id){return window.__msg_queues[request_id]};window.createQuery=function(request_id){return new NativeDioxusChannel(request_id)};class NativeDioxusChannel extends DioxusChannel{rust_to_js;request_id;constructor(request_id){super();this.rust_to_js=new Channel,this.request_id=request_id,window.__msg_queues[request_id]=this,window.finalizationRegistry.register(this,{id:request_id})}async recv(){return await this.rust_to_js.recv()}send(data){window.ipc.postMessage(JSON.stringify({method:"query",params:new QueryParams(this.request_id,"send",data)}))}rustSend(data){this.rust_to_js.send(data)}async rustRecv(){}close(){window.__msg_queues[this.request_id]=null}}export{NativeDioxusChannel};
|
||||||
@@ -80,6 +80,7 @@ impl QueryEngine {
|
|||||||
let promise = (new AsyncFunction("dioxus", {script:?}))(dioxus);
|
let promise = (new AsyncFunction("dioxus", {script:?}))(dioxus);
|
||||||
promise
|
promise
|
||||||
.then((result)=>{{
|
.then((result)=>{{
|
||||||
|
dioxus.close();
|
||||||
let returned_value = {{
|
let returned_value = {{
|
||||||
"method": "query",
|
"method": "query",
|
||||||
"params": {{
|
"params": {{
|
||||||
@@ -96,6 +97,7 @@ impl QueryEngine {
|
|||||||
}})
|
}})
|
||||||
.catch(err => post_error(`Error running JS: ${{err}}`));
|
.catch(err => post_error(`Error running JS: ${{err}}`));
|
||||||
}} catch (error) {{
|
}} catch (error) {{
|
||||||
|
dioxus.close();
|
||||||
post_error(`Invalid JS: ${{error}}`);
|
post_error(`Invalid JS: ${{error}}`);
|
||||||
}}
|
}}
|
||||||
}})();"#
|
}})();"#
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export class NativeDioxusChannel extends DioxusChannel {
|
|||||||
this.rust_to_js = new Channel();
|
this.rust_to_js = new Channel();
|
||||||
this.request_id = request_id;
|
this.request_id = request_id;
|
||||||
|
|
||||||
window.__msg_queues[request_id] = this.weak();
|
window.__msg_queues[request_id] = this;
|
||||||
window.finalizationRegistry.register(this, { id: request_id });
|
window.finalizationRegistry.register(this, { id: request_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,4 +87,9 @@ export class NativeDioxusChannel extends DioxusChannel {
|
|||||||
|
|
||||||
// Receive data sent from javascript in rust. This is a no-op in the native interpreter because the rust code runs remotely
|
// Receive data sent from javascript in rust. This is a no-op in the native interpreter because the rust code runs remotely
|
||||||
async rustRecv(): Promise<any> { }
|
async rustRecv(): Promise<any> { }
|
||||||
|
|
||||||
|
// Close the channel, dropping it.
|
||||||
|
close(): void {
|
||||||
|
window.__msg_queues[this.request_id] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
[206827801705263822, 8375185156499858125]
|
[5568016277461366671, 8375185156499858125]
|
||||||
@@ -67,4 +67,7 @@ export abstract class DioxusChannel {
|
|||||||
|
|
||||||
// Receive data sent from javascript in rust
|
// Receive data sent from javascript in rust
|
||||||
abstract rustRecv(): Promise<any>;
|
abstract rustRecv(): Promise<any>;
|
||||||
|
|
||||||
|
// Close the channel, dropping it.
|
||||||
|
abstract close(): void;
|
||||||
}
|
}
|
||||||
@@ -136,6 +136,8 @@ impl Document for WebDocument {
|
|||||||
const PROMISE_WRAPPER: &str = r#"
|
const PROMISE_WRAPPER: &str = r#"
|
||||||
return (async function(){
|
return (async function(){
|
||||||
{JS_CODE}
|
{JS_CODE}
|
||||||
|
|
||||||
|
dioxus.close();
|
||||||
})();
|
})();
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
class Channel{pending;waiting;constructor(){this.pending=[],this.waiting=[]}send(data){if(this.waiting.length>0){this.waiting.shift()(data);return}this.pending.push(data)}async recv(){return new Promise((resolve,_reject)=>{if(this.pending.length>0){resolve(this.pending.shift());return}this.waiting.push(resolve)})}}class WeakDioxusChannel{inner;constructor(channel){this.inner=new WeakRef(channel)}rustSend(data){let channel=this.inner.deref();if(channel)channel.rustSend(data)}async rustRecv(){let channel=this.inner.deref();if(channel)return await channel.rustRecv()}}class DioxusChannel{weak(){return new WeakDioxusChannel(this)}}class WebDioxusChannel extends DioxusChannel{js_to_rust;rust_to_js;owner;constructor(owner){super();this.owner=owner,this.js_to_rust=new Channel,this.rust_to_js=new Channel}weak(){return new WeakDioxusChannel(this)}async recv(){return await this.rust_to_js.recv()}send(data){this.js_to_rust.send(data)}rustSend(data){this.rust_to_js.send(data)}async rustRecv(){return await this.js_to_rust.recv()}}export{WebDioxusChannel};
|
class Channel{pending;waiting;constructor(){this.pending=[],this.waiting=[]}send(data){if(this.waiting.length>0){this.waiting.shift()(data);return}this.pending.push(data)}async recv(){return new Promise((resolve,_reject)=>{if(this.pending.length>0){resolve(this.pending.shift());return}this.waiting.push(resolve)})}}class WeakDioxusChannel{inner;constructor(channel){this.inner=new WeakRef(channel)}rustSend(data){let channel=this.inner.deref();if(channel)channel.rustSend(data)}async rustRecv(){let channel=this.inner.deref();if(channel)return await channel.rustRecv()}}class DioxusChannel{weak(){return new WeakDioxusChannel(this)}}window.__nextChannelId=0;window.__channels=[];class WebDioxusChannel extends DioxusChannel{js_to_rust;rust_to_js;owner;id;constructor(owner){super();this.owner=owner,this.js_to_rust=new Channel,this.rust_to_js=new Channel,this.id=window.__nextChannelId,window.__channels[this.id]=this,window.__nextChannelId+=1}weak(){return new WeakDioxusChannel(this)}async recv(){return await this.rust_to_js.recv()}send(data){this.js_to_rust.send(data)}rustSend(data){this.rust_to_js.send(data)}async rustRecv(){return await this.js_to_rust.recv()}close(){window.__channels[this.id]=null}}export{WebDioxusChannel};
|
||||||
@@ -1 +1 @@
|
|||||||
[1614426347475783279]
|
[857504888396904142]
|
||||||
@@ -4,16 +4,24 @@ import {
|
|||||||
WeakDioxusChannel,
|
WeakDioxusChannel,
|
||||||
} from "../../../document/src/ts/eval";
|
} from "../../../document/src/ts/eval";
|
||||||
|
|
||||||
|
window.__nextChannelId = 0;
|
||||||
|
window.__channels = [];
|
||||||
|
|
||||||
export class WebDioxusChannel extends DioxusChannel {
|
export class WebDioxusChannel extends DioxusChannel {
|
||||||
js_to_rust: Channel;
|
js_to_rust: Channel;
|
||||||
rust_to_js: Channel;
|
rust_to_js: Channel;
|
||||||
owner: any;
|
owner: any;
|
||||||
|
id: number;
|
||||||
|
|
||||||
constructor(owner: any) {
|
constructor(owner: any) {
|
||||||
super();
|
super();
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.js_to_rust = new Channel();
|
this.js_to_rust = new Channel();
|
||||||
this.rust_to_js = new Channel();
|
this.rust_to_js = new Channel();
|
||||||
|
|
||||||
|
this.id = window.__nextChannelId;
|
||||||
|
window.__channels[this.id] = this;
|
||||||
|
window.__nextChannelId += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a weak reference to this channel
|
// Return a weak reference to this channel
|
||||||
@@ -40,4 +48,9 @@ export class WebDioxusChannel extends DioxusChannel {
|
|||||||
async rustRecv(): Promise<any> {
|
async rustRecv(): Promise<any> {
|
||||||
return await this.js_to_rust.recv();
|
return await this.js_to_rust.recv();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close the channel, dropping it.
|
||||||
|
close(): void {
|
||||||
|
window.__channels[this.id] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user