summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-03-16 08:42:51 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-03-16 08:42:51 -0400
commit929cad6c0cf499d4c4bb658d92383734da45794a (patch)
tree3c3cb780abb8c262dab321cbadb323a0cfb66957
parent88e83065e0855559fb32638ac1585827f74eedbe (diff)
Change ID generation scheme to conform to HTML standards (thanks to Edward Yang for the catch)
-rw-r--r--lib/js/urweb.js2
-rw-r--r--src/c/urweb.c9
-rw-r--r--tests/id.ur11
3 files changed, 20 insertions, 2 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 5a18e17c..74badd36 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -1731,7 +1731,7 @@ function bless(s) {
var nextId = 0;
function fresh() {
- return (--nextId).toString();
+ return "uw" + (--nextId);
}
diff --git a/src/c/urweb.c b/src/c/urweb.c
index dc6ef4e6..b105d5ff 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -3962,7 +3962,14 @@ void uw_cutErrorLocation(char *s) {
}
uw_Basis_string uw_Basis_fresh(uw_context ctx) {
- return uw_Basis_htmlifyInt(ctx, ctx->nextId++);
+ int len;
+ char *r;
+
+ uw_check_heap(ctx, 2+INTS_MAX);
+ r = ctx->heap.front;
+ sprintf(r, "uw%u%n", ctx->nextId++, &len);
+ ctx->heap.front += len+1;
+ return r;
}
uw_Basis_float uw_Basis_floatFromInt(uw_context ctx, uw_Basis_int n) {
diff --git a/tests/id.ur b/tests/id.ur
new file mode 100644
index 00000000..2178cf4f
--- /dev/null
+++ b/tests/id.ur
@@ -0,0 +1,11 @@
+fun main () : transaction page =
+ id1 <- fresh;
+ id2 <- fresh;
+ x <- source <xml/>;
+ return <xml><body>
+ <span id={id1}>Hi!</span>
+ <span id={id2}>Ho!</span>
+ <dyn signal={signal x}/>
+ <button value="Set" onclick={id <- fresh; set x <xml><span id={id}>He!</span></xml>}/>
+ <button value="Show" onclick={x <- get x; alert (show x)}/>
+ </body></xml>