diff --git a/CHANGES.md b/CHANGES.md index 44a9738d0d..87c950bd4e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,7 +6,8 @@ * Compiler: simplify (a | 0) >>> 0 into (a >>> 0) (#1177) * Compiler: improve static evaluation of cond (#1178) * Compiler: be more consistent dealing with js vs ocaml strings (#984) -* Compiler: Compiler: add BigInt to provided symbols (fix #1168) (#1191) +* Compiler: add BigInt to provided symbols (fix #1168) (#1191) +* Compiler: use globalThis to find joo_global_object (fix #699) (#1195) * Lib: add messageEvent to Dom_html (#1164) * Lib: add PerformanceObserver API (#1164) * Lib: add CSSStyleDeclaration.{setProperty, getPropertyValue, getPropertyPriority, removeProperty} (#1170) diff --git a/compiler/lib/driver.ml b/compiler/lib/driver.ml index 49673cf880..fdf4d86bdd 100644 --- a/compiler/lib/driver.ml +++ b/compiler/lib/driver.ml @@ -363,20 +363,7 @@ let pack ~global { Linker.runtime_code = js; always_required_codes } = | `Function -> f | `Bind_to _ -> f | `Custom name -> J.ECall (f, [ J.EVar (J.ident name), `Not_spread ], J.N) - | `Auto -> - let global = - J.ECall - ( J.EFun - ( None - , [] - , [ ( J.Statement (J.Return_statement (Some (J.EVar (J.ident "this")))) - , J.N ) - ] - , J.N ) - , [] - , J.N ) - in - J.ECall (f, [ global, `Not_spread ], J.N) + | `Auto -> J.ECall (f, [ J.EVar (J.ident "globalThis"), `Not_spread ], J.N) in match global with | `Bind_to name -> diff --git a/compiler/tests-compiler/empty_cma.ml b/compiler/tests-compiler/empty_cma.ml index 45dc62e0c1..fece9667ee 100644 --- a/compiler/tests-compiler/empty_cma.ml +++ b/compiler/tests-compiler/empty_cma.ml @@ -29,7 +29,7 @@ let%expect_test _ = Sys.remove "empty.js"; [%expect {| - (function(joo_global_object){"use strict";return}(function(){return this}())); + (function(joo_global_object){"use strict";return}(globalThis)); //# sourceMappingURL=empty.map |}] diff --git a/compiler/tests-compiler/sourcemap.ml b/compiler/tests-compiler/sourcemap.ml index 28b92b1b91..ddbb519734 100644 --- a/compiler/tests-compiler/sourcemap.ml +++ b/compiler/tests-compiler/sourcemap.ml @@ -66,7 +66,7 @@ let%expect_test _ = 5: var Test=[0,id]; 6: runtime.caml_register_global(0,Test,"Test"); 7: return} - 8: (function(){return this}())); + 8: (globalThis)); 9: 10: //# sourceMappingURL=test.map null:-1:-1 -> 3:4