Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcca19cf

Browse files
Merge pull request#569 from coolreader18/wasm-alert
Add alert, confirm, and prompt to the browser module
2 parents6c8584c +ea93fb8 commitcca19cf

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

‎wasm/lib/src/browser_module.rs‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,61 @@ fn browser_cancel_animation_frame(vm: &mut VirtualMachine, args: PyFuncArgs) ->
182182
Ok(vm.get_none())
183183
}
184184

185+
fnbrowser_alert(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
186+
arg_check!(vm, args, required =[(message,Some(vm.ctx.str_type()))]);
187+
188+
window()
189+
.alert_with_message(&objstr::get_value(message))
190+
.expect("alert() not to fail");
191+
192+
Ok(vm.get_none())
193+
}
194+
195+
fnbrowser_confirm(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
196+
arg_check!(vm, args, required =[(message,Some(vm.ctx.str_type()))]);
197+
198+
let result =window()
199+
.confirm_with_message(&objstr::get_value(message))
200+
.expect("confirm() not to fail");
201+
202+
Ok(vm.new_bool(result))
203+
}
204+
205+
fnbrowser_prompt(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
206+
arg_check!(
207+
vm,
208+
args,
209+
required =[(message,Some(vm.ctx.str_type()))],
210+
optional =[(default,Some(vm.ctx.str_type()))]
211+
);
212+
213+
let result =ifletSome(default) = default{
214+
window().prompt_with_message_and_default(
215+
&objstr::get_value(message),
216+
&objstr::get_value(default),
217+
)
218+
}else{
219+
window().prompt_with_message(&objstr::get_value(message))
220+
};
221+
222+
let result =match result.expect("prompt() not to fail"){
223+
Some(result) => vm.new_str(result),
224+
None => vm.get_none(),
225+
};
226+
227+
Ok(result)
228+
}
229+
185230
constBROWSER_NAME:&str ="browser";
186231

187232
pubfnmk_module(ctx:&PyContext) ->PyObjectRef{
188233
py_module!(ctx,BROWSER_NAME,{
189234
"fetch" => ctx.new_rustfunc(browser_fetch),
190235
"request_animation_frame" => ctx.new_rustfunc(browser_request_animation_frame),
191236
"cancel_animation_frame" => ctx.new_rustfunc(browser_cancel_animation_frame),
237+
"alert" => ctx.new_rustfunc(browser_alert),
238+
"confirm" => ctx.new_rustfunc(browser_confirm),
239+
"prompt" => ctx.new_rustfunc(browser_prompt),
192240
})
193241
}
194242

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp