Skip to content

Commit 3f36fcb

Browse files
author
hhaensel
committed
always clone js response per default, control via kwarg clone_result
1 parent 1acde45 commit 3f36fcb

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/GenieTest.jl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ function unproxy(msg::String)
2424
"(x => (window.Vue) && Vue.isProxy(x) ? JSON.parse(JSON.stringify(x)) : x)($msg)"
2525
end
2626

27+
"""
28+
jsclone(msg::String)
29+
30+
Workaround for a JS Error in Electron when parsing proxy objects.
31+
"""
32+
function jsclone(msg::String)
33+
"JSON.parse(JSON.stringify($msg))"
34+
end
35+
2736
function Base.getindex(win::Window, index::Union{AbstractString, JSONText})
2837
index isa JSONText && (index = json(index))
2938
startswith(index, '[') || (index = ".$index")
@@ -293,10 +302,20 @@ function Base.propertynames(app::App)
293302
end
294303
end
295304
296-
function Base.run(app::App, msg::Union{AbstractString, JSONText}; timeout = 1)
305+
function Base.run(app::App, msg::Union{AbstractString, JSONText}; timeout = 1, clone_result::Union{Bool, Nothing} = true)
297306
if app.__window__ !== nothing
298307
msg isa JSONText && (msg = json(msg))
299-
run(app.__window__, unproxy(msg))
308+
if clone_result === nothing # automatically clone if necessary
309+
try
310+
run(app.__window__, unproxy(msg))
311+
catch
312+
run(app.__window__, jsclone(msg))
313+
end
314+
elseif clone_result === true
315+
run(app.__window__, jsclone(msg))
316+
else
317+
run(app.__window__, msg)
318+
end
300319
elseif app.__model__ !== nothing
301320
read(app.__model__, msg; timeout)
302321
end

0 commit comments

Comments
 (0)