Skip to content

Commit 04cdcea

Browse files
committed
add an indirection to register to avoid name pollution in the future
1 parent 8e120b1 commit 04cdcea

5 files changed

+19
-27
lines changed

Diff for: jscomp/runtime/caml_external_polyfill.ml

+8
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ let resolve = fun%raw s -> {|
3939
return myGlobal[s]
4040
|}
4141

42+
(* FIXME: it does not have to global states *)
43+
type fn
4244

45+
46+
let register : string -> fn -> unit = fun%raw s fn -> {|
47+
var myGlobal = getGlobalThis();
48+
myGlobal[s] = fn
49+
return 0
50+
|}

Diff for: jscomp/test/external_polyfill_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ function eq(loc, x, y) {
1212
}
1313

1414

15-
global.caml_fancy_add= function(x,y){
15+
require('../../lib/js/caml_external_polyfill.js').register("caml_fancy_add", function(x,y){
1616
return + ((""+x ) + (""+y))
17-
}
17+
})
1818

1919
;
2020

Diff for: jscomp/test/external_polyfill_test.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ external ff : int -> int -> int = "caml_fancy_add"
77

88

99
[%%raw{|
10-
global.caml_fancy_add= function(x,y){
10+
require('../../lib/js/caml_external_polyfill.js').register("caml_fancy_add", function(x,y){
1111
return + ((""+x ) + (""+y))
12-
}
12+
})
1313
|}]
1414

1515

Diff for: lib/js/caml_external_polyfill.js

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ function resolve (s){
1818
return myGlobal[s]
1919
};
2020

21+
function register (s,fn){
22+
var myGlobal = getGlobalThis();
23+
myGlobal[s] = fn
24+
return 0
25+
};
26+
2127
exports.getGlobalThis = getGlobalThis;
2228
exports.resolve = resolve;
29+
exports.register = register;
2330
/* No side effect */

Diff for: lib/js/caml_missing_polyfill.js

-23
This file was deleted.

0 commit comments

Comments
 (0)