comparison src/monoize.sml @ 1042:a8a825861397

Explicitly abort in-flight RPCs onunload
author Adam Chlipala <adamc@hcoop.net>
date Tue, 24 Nov 2009 09:24:25 -0500
parents c1f49f6ba856
children d73cf02427df
comparison
equal deleted inserted replaced
1041:0d767c8d2923 1042:a8a825861397
2481 List.filter (fn ("Href", _, _) => false 2481 List.filter (fn ("Href", _, _) => false
2482 | _ => true) attrs 2482 | _ => true) attrs
2483 else 2483 else
2484 attrs 2484 attrs
2485 2485
2486 fun findOnload (attrs, acc) = 2486 fun findOnload (attrs, onload, onunload, acc) =
2487 case attrs of 2487 case attrs of
2488 [] => (NONE, acc) 2488 [] => (onload, onunload, acc)
2489 | ("Onload", e, _) :: rest => (SOME e, List.revAppend (acc, rest)) 2489 | ("Onload", e, _) :: rest => findOnload (rest, SOME e, onunload, acc)
2490 | x :: rest => findOnload (rest, x :: acc) 2490 | ("Onunload", e, _) :: rest => findOnload (rest, onload, SOME e, acc)
2491 | x :: rest => findOnload (rest, onload, onunload, x :: acc)
2491 2492
2492 val (onload, attrs) = findOnload (attrs, []) 2493 val (onload, onunload, attrs) = findOnload (attrs, NONE, NONE, [])
2493 2494
2494 val (class, fm) = monoExp (env, st, fm) class 2495 val (class, fm) = monoExp (env, st, fm) class
2495 2496
2496 fun tagStart tag = 2497 fun tagStart tag =
2497 let 2498 let
2667 | _ => strcat (str "var d=" 2668 | _ => strcat (str "var d="
2668 :: jexp 2669 :: jexp
2669 :: str ";" 2670 :: str ";"
2670 :: assgns) 2671 :: assgns)
2671 end 2672 end
2673
2674 fun execify e =
2675 case e of
2676 NONE => (L'.EPrim (Prim.String ""), loc)
2677 | SOME e =>
2678 let
2679 val e = (L'.EApp (e, (L'.ERecord [], loc)), loc)
2680 in
2681 (L'.EStrcat ((L'.EPrim (Prim.String "exec("), loc),
2682 (L'.EStrcat ((L'.EJavaScript (L'.Attribute, e), loc),
2683 (L'.EPrim (Prim.String ")"), loc)), loc)), loc)
2684 end
2672 in 2685 in
2673 case tag of 2686 case tag of
2674 "body" => let 2687 "body" => let
2675 val onload = case onload of 2688 val onload = execify onload
2676 NONE => (L'.EPrim (Prim.String ""), loc) 2689 val onunload = execify onunload
2677 | SOME e =>
2678 let
2679 val e = (L'.EApp (e, (L'.ERecord [], loc)), loc)
2680 in
2681 (L'.EStrcat ((L'.EPrim (Prim.String "exec("), loc),
2682 (L'.EStrcat ((L'.EJavaScript (L'.Attribute, e), loc),
2683 (L'.EPrim (Prim.String ")"), loc)), loc)), loc)
2684 end
2685 in 2690 in
2686 normal ("body", 2691 normal ("body",
2687 SOME (L'.EFfiApp ("Basis", "maybe_onload", 2692 SOME (L'.EStrcat ((L'.EFfiApp ("Basis", "maybe_onload",
2688 [(L'.EStrcat ((L'.EFfiApp ("Basis", "get_settings", 2693 [(L'.EStrcat ((L'.EFfiApp ("Basis", "get_settings",
2689 [(L'.ERecord [], loc)]), loc), 2694 [(L'.ERecord [], loc)]), loc),
2690 onload), loc)]), 2695 onload), loc)]),
2691 loc), 2696 loc),
2697 (L'.EFfiApp ("Basis", "maybe_onunload",
2698 [onunload]),
2699 loc)), loc),
2692 SOME (L'.EFfiApp ("Basis", "get_script", [(L'.ERecord [], loc)]), loc)) 2700 SOME (L'.EFfiApp ("Basis", "get_script", [(L'.ERecord [], loc)]), loc))
2693 end 2701 end
2694 2702
2695 | "dyn" => 2703 | "dyn" =>
2696 let 2704 let