Permalink
Browse files

Update js_of_ocaml

  • Loading branch information...
1 parent a7eee7b commit e6986f246c129e38a300e7bd1efacfc57cbe97c4 @OCamlPro-Bozman OCamlPro-Bozman committed Sep 27, 2012
View
2 js_of_ocaml/compiler/js_simpl.ml
@@ -66,7 +66,7 @@ let rec enot_rec e =
end
| J.EUn (J.Not, e) ->
(e, 0)
- | J.EUn ((J.Neg | J.Pl | J.Typeof), _) ->
+ | J.EUn ((J.Neg | J.Pl | J.Typeof | J.Delete), _) ->
(J.EUn (J.Not, e), 0)
| J.EBool b ->
(J.EBool (not b), 0)
View
6 js_of_ocaml/compiler/parse.ml
@@ -431,14 +431,16 @@ let get_global state instrs i =
(x, state, instrs)
end
+let tagged_blocks = ref AddrSet.empty
let compiled_blocks = ref AddrMap.empty
let rec compile_block code pc state =
- if not (AddrMap.mem pc !compiled_blocks) then begin
+ if not (AddrSet.mem pc !tagged_blocks) then begin
let len = String.length code / 4 in
let limit = next_block len pc in
if debug () then Format.eprintf "Compiling from %d to %d@." pc (limit - 1);
let state = State.start_block state in
+ tagged_blocks := AddrSet.add pc !tagged_blocks;
let (instr, last, state') = compile code limit pc state [] in
compiled_blocks :=
AddrMap.add pc (state, List.rev instr, last) !compiled_blocks;
@@ -1561,6 +1563,7 @@ let parse_bytecode code state standalone_info =
!compiled_blocks
in
compiled_blocks := AddrMap.empty;
+ tagged_blocks := AddrSet.empty;
let free_pc = String.length code / 4 in
let g = State.globals state in
@@ -1581,6 +1584,7 @@ let parse_bytecode code state standalone_info =
register_global 2; (* Failure *)
register_global 3; (* Invalid_argument *)
register_global 5; (* Division_by_zero *)
+ register_global 6; (* Not_found *)
for i = Array.length g.constants - 1 downto 0 do
match g.vars.(i) with
Some x when g.is_const.(i) ->
View
54 js_of_ocaml/lib/dom_html.ml
@@ -1062,24 +1062,46 @@ let opt_iter x f = match x with None -> () | Some v -> f v
let createElement (doc : document t) name = doc##createElement(Js.string name)
let unsafeCreateElement doc name = Js.Unsafe.coerce (createElement doc name)
-let unsafeCreateElementEx ?_type ?name doc elt =
+
+let createElementSyntax = ref `Unknown
+
+let rec unsafeCreateElementEx ?_type ?name doc elt =
if _type = None && name = None then
Js.Unsafe.coerce (createElement doc elt)
- else if not onIE then begin
- let res = Js.Unsafe.coerce (createElement doc elt) in
- opt_iter _type (fun t -> res##_type <- t);
- opt_iter name (fun n -> res##name <- n);
- res
- end else begin
- let a = jsnew Js.array_empty () in
- ignore (a##push_2(Js.string "<", Js.string elt));
- opt_iter _type (fun t ->
- ignore (a##push_3(Js.string " type=\"", html_escape t, Js.string "\"")));
- opt_iter name (fun n ->
- ignore (a##push_3(Js.string " name=\"", html_escape n, Js.string "\"")));
- ignore (a##push(Js.string ">"));
- Js.Unsafe.coerce (doc##createElement (a##join (Js.string "")))
- end
+ else
+ match !createElementSyntax with
+ `Standard ->
+ let res = Js.Unsafe.coerce (createElement doc elt) in
+ opt_iter _type (fun t -> res##_type <- t);
+ opt_iter name (fun n -> res##name <- n);
+ res
+ | `Extended ->
+ let a = jsnew Js.array_empty () in
+ ignore (a##push_2(Js.string "<", Js.string elt));
+ opt_iter _type (fun t ->
+ ignore
+ (a##push_3(Js.string " type=\"", html_escape t, Js.string "\"")));
+ opt_iter name (fun n ->
+ ignore
+ (a##push_3(Js.string " name=\"", html_escape n, Js.string "\"")));
+ ignore (a##push(Js.string ">"));
+ Js.Unsafe.coerce (doc##createElement (a##join (Js.string "")))
+ | `Unknown ->
+ createElementSyntax :=
+ if
+ try
+ let el : inputElement Js.t =
+ Js.Unsafe.coerce
+ (document##createElement(Js.string "<input name=\"x\">")) in
+ el##tagName##toLowerCase() == Js.string "input" &&
+ el##name == Js.string "x"
+ with _ ->
+ false
+ then
+ `Extended
+ else
+ `Standard;
+ unsafeCreateElementEx ?_type ?name doc elt
let createHtml doc : htmlElement t = unsafeCreateElement doc "html"
let createHead doc : headElement t = unsafeCreateElement doc "head"
View
2 js_of_ocaml/lib/js.mli
@@ -479,7 +479,7 @@ val coerce_opt : 'a Opt.t -> ('a -> 'b Opt.t) -> ('a -> 'b) -> 'b
If [v] is [null] or the coercion returns [null], function [f] is
called.
Typical usage is the following:
- {[Js.coerce_opt (Dom_html.getElementById id)
+ {[Js.coerce_opt (Dom_html.document##getElementById(id))
Dom_html.CoerceTo.div (fun _ -> assert false)]} *)
(** {2 Type checking operators.} *)
View
31 js_of_ocaml/lib/lwt_js_events.ml
@@ -184,4 +184,33 @@ let touchends ?use_capture t =
let touchcancels ?use_capture t =
seq_loop touchcancel ?use_capture t
-
+let transition_evn =
+ let e = Dom_html.createDiv Dom_html.document in
+ try
+ snd (List.find
+ (fun (propname, evname) ->
+ Js.Unsafe.get (e##style) propname != Js.undefined)
+ [("WebkitTransition", [Dom.Event.make "webkitTransitionEnd"]);
+ ("MozTransition", [Dom.Event.make "transitionend"]);
+ ("OTransition", [Dom.Event.make "oTransitionEnd";
+ Dom.Event.make "otransitionend"]);
+ ("transition", [Dom.Event.make "transitionend"])])
+ with Not_found -> []
+
+let transitionend elt =
+ match transition_evn with
+ | [] -> Lwt.return ()
+ | _ -> Lwt.pick
+ (List.map
+ (fun ev -> make_event ev elt)
+ transition_evn) >>= fun _ ->
+ Lwt.return ()
+
+let transitionends t =
+ seq_loop (fun ?use_capture e -> transitionend e) t
+
+let request_animation_frame () =
+ let t, s = Lwt.wait () in
+ Dom_html._requestAnimationFrame
+ (Js.wrap_callback (fun () -> Lwt.wakeup s ()));
+ t
View
6 js_of_ocaml/lib/lwt_js_events.mli
@@ -159,6 +159,8 @@ val touchcancel :
?use_capture:bool ->
#Dom_html.eventTarget Js.t -> Dom_html.touchEvent Js.t Lwt.t
+(** Returns when a CSS transition terminates on the element. *)
+val transitionend : #Dom_html.eventTarget Js.t -> unit Lwt.t
val clicks :
@@ -253,3 +255,7 @@ val touchcancels :
?use_capture:bool ->
#Dom_html.eventTarget Js.t ->
(Dom_html.touchEvent Js.t -> unit Lwt.t) -> 'a Lwt.t
+
+(** Returns when a repaint of the window by the browser starts.
+ (see JS method [window.requestAnimationFrame]) *)
+val request_animation_frame : unit -> unit Lwt.t
View
7 js_of_ocaml/runtime/stdlib.js
@@ -84,6 +84,10 @@ function caml_raise_zero_divide () {
caml_raise_constant(caml_global_data[6]);
}
+//Provides: caml_raise_not_found
+//Requires: caml_raise_constant, caml_global_data
+function caml_raise_not_found () { caml_raise_constant(caml_global_data[7]); }
+
//Provides: caml_update_dummy
function caml_update_dummy (x, y) {
if( typeof y==="function" ) { x.fun = y; return 0; }
@@ -734,3 +738,6 @@ function caml_get_exception_backtrace () {
caml_invalid_argument
("Primitive 'caml_get_exception_backtrace' not implemented");
}
+//Provides: caml_sys_getenv
+//Requires: caml_raise_not_found
+function caml_sys_getenv () { caml_raise_not_found (); }

0 comments on commit e6986f2

Please sign in to comment.