Skip to content

Commit 0239708

Browse files
alainfrischhhugo
authored andcommitted
caml_js_get and caml_js_delete should not be eliminated even if their result is not used
1 parent 8464de2 commit 0239708

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* Compiler: fix rewriter bug in share_constant (fix #1247)
3333
* Compiler: fix miscompilation of mutually recursive functions in loop (#1321)
3434
* Compiler: fix bug while minifying/renaming try-catch blocks
35+
* Compiler: no dead code elimination for caml_js_get
3536
* Runtime: fix ocamlyacc parse engine (#1307)
3637
* Runtime: fix Out_channel.is_buffered, set_buffered
3738
* Runtime: fix format wrt alternative

compiler/lib/generate.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,9 @@ let _ =
965965

966966
register_tern_prim "caml_js_set" (fun cx cy cz _ ->
967967
J.EBin (J.Eq, J.EAccess (cx, cy), cz));
968-
register_bin_prim "caml_js_get" `Mutable (fun cx cy _ -> J.EAccess (cx, cy));
968+
(* [caml_js_get] can have side effect, we declare it as mutator.
969+
see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get *)
970+
register_bin_prim "caml_js_get" `Mutator (fun cx cy _ -> J.EAccess (cx, cy));
969971
register_bin_prim "caml_js_delete" `Mutator (fun cx cy _ ->
970972
J.EUn (J.Delete, J.EAccess (cx, cy)));
971973
register_bin_prim "caml_js_equals" `Mutable (fun cx cy _ ->

runtime/jslib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function caml_js_pure_expr (f) { return f(); }
2424

2525
//Provides: caml_js_set (mutable, const, const)
2626
function caml_js_set(o,f,v) { o[f]=v;return 0}
27-
//Provides: caml_js_get mutable (const, const)
27+
//Provides: caml_js_get (const, const)
2828
function caml_js_get(o,f) { return o[f]; }
2929
//Provides: caml_js_delete (mutable, const)
3030
function caml_js_delete(o,f) { delete o[f]; return 0}

0 commit comments

Comments
 (0)