From 7463b805e4510b4f187851e91c53bb28db3ba044 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 24 Nov 2009 09:24:25 -0500 Subject: Explicitly abort in-flight RPCs onunload --- src/c/urweb.c | 10 ++++++++++ src/monoize.sml | 48 ++++++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/c/urweb.c b/src/c/urweb.c index e75d0c66..344ef2ad 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -1173,6 +1173,16 @@ uw_Basis_string uw_Basis_maybe_onload(uw_context ctx, uw_Basis_string s) { } } +uw_Basis_string uw_Basis_maybe_onunload(uw_context ctx, uw_Basis_string s) { + if (ctx->script_header[0] == 0) + return ""; + else { + char *r = uw_malloc(ctx, 22 + strlen(s)); + sprintf(r, " onunload='unload();%s'", s); + return r; + } +} + extern uw_Basis_string uw_cookie_sig(uw_context); const char *uw_Basis_get_settings(uw_context ctx, uw_unit u) { diff --git a/src/monoize.sml b/src/monoize.sml index 4e337388..7effa885 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -2483,13 +2483,14 @@ fun monoExp (env, st, fm) (all as (e, loc)) = else attrs - fun findOnload (attrs, acc) = + fun findOnload (attrs, onload, onunload, acc) = case attrs of - [] => (NONE, acc) - | ("Onload", e, _) :: rest => (SOME e, List.revAppend (acc, rest)) - | x :: rest => findOnload (rest, x :: acc) + [] => (onload, onunload, acc) + | ("Onload", e, _) :: rest => findOnload (rest, SOME e, onunload, acc) + | ("Onunload", e, _) :: rest => findOnload (rest, onload, SOME e, acc) + | x :: rest => findOnload (rest, onload, onunload, x :: acc) - val (onload, attrs) = findOnload (attrs, []) + val (onload, onunload, attrs) = findOnload (attrs, NONE, NONE, []) val (class, fm) = monoExp (env, st, fm) class @@ -2669,26 +2670,33 @@ fun monoExp (env, st, fm) (all as (e, loc)) = :: str ";" :: assgns) end + + fun execify e = + case e of + NONE => (L'.EPrim (Prim.String ""), loc) + | SOME e => + let + val e = (L'.EApp (e, (L'.ERecord [], loc)), loc) + in + (L'.EStrcat ((L'.EPrim (Prim.String "exec("), loc), + (L'.EStrcat ((L'.EJavaScript (L'.Attribute, e), loc), + (L'.EPrim (Prim.String ")"), loc)), loc)), loc) + end in case tag of "body" => let - val onload = case onload of - NONE => (L'.EPrim (Prim.String ""), loc) - | SOME e => - let - val e = (L'.EApp (e, (L'.ERecord [], loc)), loc) - in - (L'.EStrcat ((L'.EPrim (Prim.String "exec("), loc), - (L'.EStrcat ((L'.EJavaScript (L'.Attribute, e), loc), - (L'.EPrim (Prim.String ")"), loc)), loc)), loc) - end + val onload = execify onload + val onunload = execify onunload in normal ("body", - SOME (L'.EFfiApp ("Basis", "maybe_onload", - [(L'.EStrcat ((L'.EFfiApp ("Basis", "get_settings", - [(L'.ERecord [], loc)]), loc), - onload), loc)]), - loc), + SOME (L'.EStrcat ((L'.EFfiApp ("Basis", "maybe_onload", + [(L'.EStrcat ((L'.EFfiApp ("Basis", "get_settings", + [(L'.ERecord [], loc)]), loc), + onload), loc)]), + loc), + (L'.EFfiApp ("Basis", "maybe_onunload", + [onunload]), + loc)), loc), SOME (L'.EFfiApp ("Basis", "get_script", [(L'.ERecord [], loc)]), loc)) end -- cgit v1.2.3