code_editor/Cargo.toml | 1 - code_editor/src/lib.rs | 3 - draw/src/cx_2d.rs | 83 + draw/src/cx_draw.rs | 43 + draw/src/draw_list_2d.rs | 22 + draw/src/geometry/geometry_gen.rs | 7 +- draw/src/image_cache.rs | 51 +- draw/src/lib.rs | 1 - draw/src/shader/draw_text.rs | 40 +- draw/src/shader/mod.rs | 1 - draw/src/text/fonts.rs | 2 +- draw/src/text/mod.rs | 1 - draw/src/text/slug_atlas.rs | 2 +- draw/src/turtle.rs | 3469 ++++- draw/src/vector/triangulate.rs | 378 +- libs/error_log/src/lib.rs | 17 +- platform/network/src/backend.rs | 6 + platform/network/src/backend/apple/http.rs | 2 +- platform/network/src/http_server.rs | 15 +- platform/script/derive/src/derive_scriptable.rs | 19 +- platform/script/src/lib.rs | 4 + platform/script/src/shader_calls.rs | 92 +- platform/script/src/shader_hlsl.rs | 9 +- platform/script/src/shader_metal.rs | 18 +- platform/script/src/shader_wgsl.rs | 12 +- platform/script/tests/hook_scope.rs | 8 +- platform/src/action.rs | 12 +- platform/src/app_main.rs | 110 +- platform/src/cx.rs | 466 +- platform/src/cx_api.rs | 368 +- platform/src/draw_list.rs | 2598 +++- platform/src/draw_pass.rs | 35 +- platform/src/draw_vars.rs | 103 +- platform/src/geometry.rs | 588 +- platform/src/gpu_texture.rs | 2 +- platform/src/id_pool.rs | 71 +- platform/src/lib.rs | 26 +- platform/src/log.rs | 111 +- platform/src/os/apple/apple_game_input.rs | 6 + platform/src/os/apple/apple_sys.rs | 1 + platform/src/os/apple/macos/macos_app.rs | 384 +- platform/src/os/apple/metal.rs | 3347 +++- platform/src/os/cx_native.rs | 5 +- platform/src/os/cx_shared.rs | 202 +- platform/src/os/gpusim/event_loop.rs | 24 +- platform/src/os/gpusim/mod.rs | 8 + platform/src/os/gpusim/raster.rs | 11 + platform/src/os/linux/opengl.rs | 856 +- platform/src/os/linux/vulkan.rs | 752 +- platform/src/os/linux/vulkan_linux.rs | 4 - platform/src/os/linux/wayland/linux_wayland.rs | 15 +- platform/src/os/linux/wayland/opengl_wayland.rs | 67 +- platform/src/os/linux/wayland/wayland_state.rs | 37 +- platform/src/os/web/web.js | 1409 +- platform/src/os/web/web.rs | 212 +- platform/src/os/web/web_gl.rs | 284 +- platform/src/os/web/web_worker.js | 76 +- platform/src/os/windows/d3d11.rs | 1323 +- platform/src/remote.rs | 1297 +- platform/src/retained_instances.rs | 3 - platform/src/script/res.rs | 245 +- platform/src/sploded.rs | 59 +- platform/src/texture.rs | 416 +- platform/src/thread.rs | 2816 +++- platform/src/thread/ui_hang/linux.rs | 2 +- platform/src/thread/ui_hang/macos.rs | 22 +- platform/src/thread/ui_hang/native.rs | 3 + platform/src/thread/ui_hang/windows.rs | 2 +- platform/src/web_socket.rs | 45 +- platform/src/window.rs | 129 +- platform/tests/texture_lifetime.rs | 143 +- platform/video/src/stream_debug.rs | 2 +- platform/video/tests/stream_codec.rs | 85 +- widgets/derive_widget/src/derive_widget.rs | 4 +- widgets/src/animator.rs | 138 +- widgets/src/combo_box.rs | 10 + widgets/src/desktop_style.rs | 4 +- widgets/src/drop_down.rs | 96 + widgets/src/font_policy.rs | 25 + widgets/src/grid.rs | 1 + widgets/src/image.rs | 3 + widgets/src/lib.rs | 18 +- widgets/src/map/archive.rs | 544 +- widgets/src/map/geometry.rs | 34 +- widgets/src/map/label.rs | 48 +- widgets/src/map/tile.rs | 6890 ++++++--- widgets/src/map/tile_draw.rs | 2 - widgets/src/map/view.rs | 17896 ++++++++++++++-------- widgets/src/menu_bar.rs | 18 +- widgets/src/screen_cap.rs | 513 +- widgets/src/slider.rs | 6 + widgets/src/splash.rs | 280 +- widgets/src/tweaker.rs | 221 +- widgets/src/view.rs | 105 +- widgets/src/widget.rs | 5 +- widgets/src/widget_async.rs | 269 +- widgets/src/window.rs | 601 +- widgets/src/window_voice_input.rs | 17 +- 98 files changed, 38159 insertions(+), 12677 deletions(-) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
55 lines
2.3 KiB
Rust
55 lines
2.3 KiB
Rust
//! Host->script hook lookups against a Splash-shaped body: the script is
|
|
//! wrapped in an auto-closed object literal, and a `let`/`fn` that shadows
|
|
//! an existing name opens a child scope the module scope cannot see into.
|
|
//! The body remembers the scope it ended in for exactly that.
|
|
|
|
use makepad_script::*;
|
|
|
|
fn test_vm() -> ScriptVm<'static> {
|
|
let host = Box::leak(Box::new(ScriptVmHost::new(0i32, ())));
|
|
ScriptVm {
|
|
host,
|
|
bx: Box::new(ScriptVmBase::new()),
|
|
}
|
|
}
|
|
|
|
fn scopes(vm: &mut ScriptVm, file: &str) -> (ScriptObject, Option<ScriptObject>) {
|
|
let bodies = vm.bx.code.bodies.borrow();
|
|
bodies.iter().find_map(|body| match &body.source {
|
|
ScriptSource::Mod(m) if m.file == file => {
|
|
Some((body.scope.as_object(), body.end_scope.as_ref().map(|s| s.as_object())))
|
|
}
|
|
_ => None,
|
|
}).expect("body")
|
|
}
|
|
|
|
#[test]
|
|
fn hooks_resolve_in_the_scope_the_body_ended_in() {
|
|
let mut vm = test_vm();
|
|
vm.bx.captured_errors = Some(Vec::new());
|
|
// `fs` is defined twice: the second `let` shadows and opens a child scope.
|
|
let code = "let fs = 1\n{height: 1, let fs = 2\nfn before(){ 7 }\nfn on_x(){ 42 }\n{}\n";
|
|
vm.with_instruction_limit(500_000, |vm| {
|
|
vm.eval(ScriptMod {
|
|
cargo_manifest_path: String::new(),
|
|
module_path: String::new(),
|
|
file: "hook_scope".to_string(),
|
|
line: 0, column: 0,
|
|
code: code.to_string(),
|
|
values: vec![],
|
|
})
|
|
});
|
|
let errors = vm.take_errors();
|
|
assert!(errors.is_empty(), "eval errored: {errors:?}");
|
|
|
|
let (module, end) = scopes(&mut vm, "hook_scope");
|
|
let end = end.expect("the body recorded the scope it ended in");
|
|
let from_module = vm.bx.heap.scope_value(module, id!(on_x), NoTrap);
|
|
assert!(from_module.is_nil() || from_module.is_err(), "the module scope should not see past the shadowing let");
|
|
let on_x = vm.bx.heap.scope_value(end, id!(on_x), NoTrap);
|
|
assert!(!on_x.is_nil() && !on_x.is_err(), "on_x not found in the end scope");
|
|
let result = vm.with_instruction_limit(500_000, |vm| vm.call(on_x, &[]));
|
|
assert_eq!(format!("{result:?}"), "42", "on_x returned {result:?}");
|
|
let before = vm.bx.heap.scope_value(end, id!(before), NoTrap);
|
|
assert!(!before.is_nil() && !before.is_err(), "before not found in the end scope");
|
|
}
|