-
Notifications
You must be signed in to change notification settings - Fork 194
Compiler: use globalThis, drop joo_global_object #1193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cc @copy, @jchavarri, @TyOverby |
I can try to test this on the Jane Street codebase next week |
Tests pass on node 10 (which doesn't have support for globalThis) and node 14 and 16. @TyOverby, I'd like to make a new release soon including this change. Please let me know once you've run your testing |
It also fixed the issue reported by @jchavarri in #699 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I have more questions than anything else, but otherwise looks great to me.
Thanks for the review, can you close threads once you're happy with the answer |
@hhugo I don't think I can resolve conversations as I didn't open the pull request nor have write access to the repo. |
@hhugo I got this branch building internally, but we have so much javascript that uses "joo_global_object" that it'll take a long time for me to make the necessary changes in order to tell if there are any other issues. Also, I must admit that this feature confuses me a bit; I would have expected that you'd use globalThis to generate wrapping-functions that look like this: (function (joo_global_object) {
// ... code goes here ...
})(globalThis) Where we still keep Instead, it appears that the function-parameter name is also changed, which requires all of the rest of the changes in this feature. |
Also, what does "implement compatibility for the old joo_global_object" refer to? |
Here's how I assumed that the feature would be implemented: #1195 |
@TyOverby , it is better to read this PR commit by commit. The first commit just changes how we compute the global object (using globalThis), similar to your #1195. The second commit cleans up the old joo_global_object name, renaming it to globalThis. We don't need a Jsoo-specific name, just use what the JS ecosystem uses. The third commit make the stubs using the old joo_global_object work again (by introducing a |
I don't understand. You don't need to change anything, it should just work out of the box |
Sadly something appears to be broken as every test in the tree fails with the message "undefined variable joo_global_object" |
What is the benefit of this approach? |
I won't be able to investigate this further for a few days due to the holidays, but I'll dig deeper on Monday |
the failure happens here: https://github.com/janestreet/core/blob/master/core/src/strftime.js#L43
|
Fixing that instance just causes the same error to happen in other places that we use |
I can confirm that some sections get this added to the top of them, but not all. Of note, at least two sections use |
Thanks for testing, I have a theory that I should be able to test/fix early next year |
@TyOverby, I think I've fixed your issues in my last commit. (Also note that core_kernel declare |
Yep! I can confirm that the issue is no longer present! Sadly it made another problem visible; I don't know if it's directly caused by this pull-request, but I'm seeing some strange behavior. A single javascript file (it's a 3rd party js library that we pull in) is being split between IIFEs like so: runtime.js var x = (function () { ...})();
if (typeof window !== 'undefined') window.x = x;
if (typeof globalThis !== 'undefined') globalThis.x = x; Goes through Js_of_ocaml and out comes this: output.bc.js (function(globalThis) {
var x = (function () { ...})();
}(globalThis));
(function(globalThis) {
if (typeof window !== 'undefined') window.x = x;
if (typeof globalThis !== 'undefined') globalThis.x = x;
}(globalThis)); Because the definition of |
I spent a few hours trying to get a minimal repro but could not. |
It looks like I'm able to work around that specific issue by wrapping the whole file in another IIFE. |
@TyOverby, I've managed to reproduce your issue with the following var x = (function () { ...})();
//Always .. a comment starting by //Always
if (typeof window !== 'undefined') window.x = x;
if (typeof globalThis !== 'undefined') globalThis.x = x; The behavior was introduced by c6d8608 I'll rebase this PR to make it easier to test for you |
Co-authored-by: Javier Chávarri <javier.chavarri@gmail.com>
@TyOverby, I'm going to merge now, please make sure master works for you when you return from vacation. |
@hhugo all of our automated tests are passing; we're going to do some more manual testing next week. Thanks for all the help! |
…s_of_ocaml-ppx_deriving_json, js_of_ocaml-ppx, js_of_ocaml-lwt and js_of_ocaml-compiler (4.0.0) CHANGES: ## Features/Changes * Compiler: add --target-env flag, for JS runtime specific compilation targets (ocsigen/js_of_ocaml#1160). * Compiler: static evaluation of backend_type (ocsigen/js_of_ocaml#1166) * Compiler: speedup emitting js files (ocsigen/js_of_ocaml#1174) * Compiler: simplify (a | 0) >>> 0 into (a >>> 0) (ocsigen/js_of_ocaml#1177) * Compiler: improve static evaluation of cond (ocsigen/js_of_ocaml#1178) * Compiler: be more consistent dealing with js vs ocaml strings (ocsigen/js_of_ocaml#984) * Compiler: Compiler: add BigInt to provided symbols (fix ocsigen/js_of_ocaml#1168) (ocsigen/js_of_ocaml#1191) * Compiler: use globalThis, drop joo_global_object ocsigen/js_of_ocaml#1193 * Compiler: new -Werror flag to turn wanrings into errors (ocsigen/js_of_ocaml#1222) * Compiler: make the inlining less agressive, reduce size, improve pref (ocsigen/js_of_ocaml#1220) * Compiler: rename internal library js_of_ocaml-compiler.runtime to js_of_ocaml-compiler.runtime-files * Lib: new runtime library to improve compatibility with Brr and gen_js_api * Lib: add messageEvent to Dom_html (ocsigen/js_of_ocaml#1164) * Lib: add PerformanceObserver API (ocsigen/js_of_ocaml#1164) * Lib: add CSSStyleDeclaration.{setProperty, getPropertyValue, getPropertyPriority, removeProperty} (ocsigen/js_of_ocaml#1170) * Lib: make window.{inner,outer}{Width,Height} non-optional * Lib: introduce Js_of_ocaml.Js_error module, deprecate Js_of_ocaml.Js.Error exception. * Lib: add deprecation warning for deprecated code * PPX: json can now be derived for mutable records (ocsigen/js_of_ocaml#1184) * Runtime: use crypto.getRandomValues when available (ocsigen/js_of_ocaml#1209) * Misc: move js_of_ocaml-ocamlbuild out to its own repo * Misc: add support for OCaml 4.14 (ocsigen/js_of_ocaml#1173) ## Bug fixes * Compiler: fix sourcemap warning for empty cma (ocsigen/js_of_ocaml#1169) * Compiler: Strengthen bound checks. (ocsigen/js_of_ocaml#1172) * Compiler: fix `--wrap-with-fun` under node (ocsigen/js_of_ocaml#653, ocsigen/js_of_ocaml#1171) * Compiler: fix parsing of annotaions in js stubs (ocsigen/js_of_ocaml#1212, fix ocsigen/js_of_ocaml#1213) * Ppx: allow apostrophe in lident (fix ocsigen/js_of_ocaml#1183) (ocsigen/js_of_ocaml#1192) * Runtime: fix float parsing in hexadecimal form * Runtime: fix implementation of caml_js_instanceof * Graphics: fix mouse_{x,y} (ocsigen/js_of_ocaml#1206)
fix #699