Verified Commit 33263da4 authored by Camil Staps's avatar Camil Staps 🙂

Add jsDeserializeJSVal to avoid unnecessary copying of strings to webassembly

parent 575ec017
......@@ -253,6 +253,9 @@ jsSerializeGraph :: a !PrelinkedInterpretationEnvironment -> String
//* Deserialize a graph that was serialized with `jsSerializeGraph`.
jsDeserializeGraph :: !*String !*JSWorld -> *(!.a, !*JSWorld)
//* Like `jsDeserializeGraph`, but works on a String in the JavaScript world.
jsDeserializeJSVal :: !JSVal !*JSWorld -> *(!.a, !*JSWorld)
/**
* Serialize a graph on the client side. The resulting value is a `String`, but
* is by default not copied to the Clean world (as it is usually not needed
......
......@@ -582,7 +582,7 @@ where
// of the constructors which it needs to know.
init :: !{!JSVal} -> Bool
init _ = code {
instruction 8
instruction 9
pop_a 1
pushB FALSE
}
......@@ -619,12 +619,25 @@ where
instruction 6
}
jsDeserializeJSVal :: !JSVal !*JSWorld -> *(!.a, !*JSWorld)
jsDeserializeJSVal v w
# (val,ok) = deserialize (js_val_to_string v)
| ok
= (val, w)
= abort_with_node v
where
deserialize :: !*String -> (!.a, !Bool)
deserialize _ = code {
instruction 7
pushB TRUE
}
jsSerializeOnClient :: .a !*JSWorld -> (!JSVal, !*JSWorld)
jsSerializeOnClient graph w = (serialize graph, w)
where
serialize :: .a -> JSVal
serialize _ = code {
instruction 7
instruction 8
}
jsDeserializeFromClient :: !String !PrelinkedInterpretationEnvironment -> (.a, !Int)
......@@ -636,7 +649,7 @@ addCSSFromUrl css w = case add_css css of
where
add_css :: !String -> Bool
add_css _ = code {
instruction 10
instruction 11
pop_a 1
pushB TRUE
}
......@@ -652,7 +665,7 @@ where
add_js :: !String !*String -> Bool
add_js _ _ = code {
instruction 11
instruction 12
pop_a 2
pushB TRUE
}
......
......@@ -829,7 +829,13 @@ ABCInterpreter.interpreter_imports={
var hp_ptr=me.memory_array[asp/4];
me.memory_array[asp/4]=me.deserialize_from_unique_string(hp_ptr);
break;
case 7: /* ABC.Interpreter.Javascript: jsSerializeOnClient */
case 7: /* ABC.Interpreter.JavaScript: deserializeJSVal */
var string=me.get_clean_string (me.memory_array[asp/4],true);
if (ABC_DEBUG)
console.log ('deserialize',string);
me.memory_array[asp/4]=me.deserialize (eval (string));
break;
case 8: /* ABC.Interpreter.JavaScript: jsSerializeOnClient */
me.require_hp(2);
var string=me.copy_to_string(me.memory_array[asp/4]);
asp-=8;
......@@ -842,7 +848,7 @@ ABCInterpreter.interpreter_imports={
me.interpreter.instance.exports.set_hp(hp+16);
me.interpreter.instance.exports.set_hp_free(hp_free-2);
break;
case 8: /* ABC.Interpreter.JavaScript: initialize_client in wrapInitUIFunction */
case 9: /* ABC.Interpreter.JavaScript: initialize_client in wrapInitUIFunction */
var array=me.memory_array[asp/4]+24;
me.addresses.JSInt= me.memory_array[me.memory_array[array/4]/4];
me.addresses.JSBool= me.memory_array[me.memory_array[array/4+2]/4];
......@@ -856,7 +862,7 @@ ABCInterpreter.interpreter_imports={
me.util.instance.exports.set_js_ref_constructor(me.addresses.JSRef);
me.initialized=true;
break;
case 10: /* ABC.Interpreter.JavaScript: add CSS */
case 11: /* ABC.Interpreter.JavaScript: add CSS */
var url=me.get_clean_string(me.memory_array[asp/4], false);
var css=document.createElement('link');
css.rel='stylesheet';
......@@ -865,7 +871,7 @@ ABCInterpreter.interpreter_imports={
css.href=url;
document.head.appendChild(css);
break;
case 11: /* ABC.Interpreter.JavaScript: add JS */
case 12: /* ABC.Interpreter.JavaScript: add JS */
var url=me.get_clean_string(me.memory_array[asp/4], false);
var callback=me.get_clean_string(me.memory_array[asp/4-2], true);
var js=document.createElement('script');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment