After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777724 - [RFC] bootstrap system
[RFC] bootstrap system
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
1.47.x
Other All
: Normal enhancement
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2017-01-25 00:32 UTC by Philip Chimento
Modified: 2017-09-23 04:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add a bootstrap system, allowing us to write JS code at early boot (6.58 KB, patch)
2017-01-25 00:41 UTC, Philip Chimento
none Details | Review
bootstrap: Define Promise in bootstrap (3.74 KB, patch)
2017-01-25 00:41 UTC, Philip Chimento
rejected Details | Review
global: Add a bootstrap system (6.51 KB, patch)
2017-09-10 00:22 UTC, Philip Chimento
committed Details | Review
coverage: Use global bootstrap to add JS coverage code (7.23 KB, patch)
2017-09-10 00:22 UTC, Philip Chimento
committed Details | Review

Description Philip Chimento 2017-01-25 00:32:04 UTC
This idea is from Jasper and I resurrected it from an old branch of his [1]. He was going to use it to rewrite the importer code but I'd like to consider this idea separately from the imports.

It could be used to define the Promise object more easily.

[1] https://git.gnome.org/browse/gjs/log/?h=wip/imports-rewrite
Comment 1 Philip Chimento 2017-01-25 00:41:03 UTC
Created attachment 344191 [details] [review]
Add a bootstrap system, allowing us to write JS code at early boot

This will be used to write a CommonJS style imports system for JS,
but it could also be used for other things, like rewriting window.log,
window.logError, etc. in JS.
Comment 2 Philip Chimento 2017-01-25 00:41:07 UTC
Created attachment 344192 [details] [review]
bootstrap: Define Promise in bootstrap

This takes advantage of the new bootstrap stage to import the promises
module and define the Promise global object.
Comment 3 Philip Chimento 2017-01-25 00:44:27 UTC
Comments welcome!

There are a few problems I've found with this implementation:

- Errors in the bootstrap code are swallowed. (This shouldn't matter to end users, but it makes GJS development difficult.)

- It might be good to make this per-compartment so we can use it for bootstrapping the test coverage stuff as well.
Comment 4 Philip Chimento 2017-07-10 20:43:46 UTC
Review of attachment 344192 [details] [review]:

We have native promises instead of a promises module now, so this is not needed.
Comment 5 Philip Chimento 2017-09-10 00:22:35 UTC
Created attachment 359452 [details] [review]
global: Add a bootstrap system

Based on a patch by Jasper St. Pierre. This allows executing a JS script
(which must be a resource in the directory
resource:///org/gnome/gtk/modules/_bootstrap) in order to define extra
properties on a global object when the global object is created.

This is currently not used for anything, but will be used for the code
coverage compartment, and likely for a debugger as well. It can also be
used to implement things in JS that are currently implemented in C++,
like the log() and logError() functions.
Comment 6 Philip Chimento 2017-09-10 00:22:39 UTC
Created attachment 359453 [details] [review]
coverage: Use global bootstrap to add JS coverage code

This takes advantage of the new bootstrap stage of
gjs_define_global_properties() to run the JS coverage code in the
coverage compartment.

This moves imports.coverage to imports._bootstrap.coverage, which makes
sense because the code in imports.coverage was not useful for GJS
scripts.
Comment 7 Philip Chimento 2017-09-10 00:30:42 UTC
I'm expecting to have to use this for the debugger, so I fixed this up. With the new global.cpp I did end up rewriting it completely.

One thing that Jasper's patch did that this one doesn't do, is allow an "environment object" with native properties to be passed in, and have the bootstrap code evaluated in its scope. That's currently not possible with JS::CloneAndExecuteScript() which we use to make sure the file is evaluated in the correct compartment. But, then again, it's also not currently needed.

This is also an API break in that imports.coverage is now imports._bootstrap.coverage. The coverage module should really have been more clearly marked as internal-only (which I hope the underscore in _bootstrap now indicates!) I could set up a dummy imports.coverage module that just imported the real one, but I doubt any scripts out there actually use the coverage module, since it's not really useful for client code.
Comment 8 Cosimo Cecchi 2017-09-20 02:03:12 UTC
Review of attachment 359452 [details] [review]:

LGTM

::: gjs/global.cpp
@@ +48,3 @@
+        gjs_throw_g_error(cx, error);
+        return false;
+

Optional: use g_resources_lookup_data() and a GBytes to make this code a bit cleaner.
Comment 9 Cosimo Cecchi 2017-09-20 02:06:03 UTC
Review of attachment 359453 [details] [review]:

Nice cleanup!

::: modules/coverage.js
@@ +975,3 @@
 }
+
+printerr('executed the thing');
 No newline at end of file

Hmm...
Comment 10 Philip Chimento 2017-09-22 07:54:53 UTC
Comment on attachment 359452 [details] [review]
global: Add a bootstrap system

Attachment 359452 [details] pushed as 881e6b2 - global: Add a bootstrap system
Comment 11 Philip Chimento 2017-09-23 02:06:05 UTC
Review of attachment 359453 [details] [review]:

Actually I found out that this makes (unrelated!) tests fail. I originally didn't notice because 'make check-code-coverage' doesn't fail if tests fail. But regular 'make check' also fails when code coverage is enabled.
Comment 12 Philip Chimento 2017-09-23 04:12:40 UTC
After digging some more, I found that these exceptions during code coverage collection were always there, just that they were swallowed before! So I'm going to push this anyway (without the debug print of course) and fix the code coverage separately.

Exceptions thrown for three reasons:
- Coverage code tries to load "files" for scripts fed programmatically to the JS engine and fails (was harmless, only it's now logged)
- Coverage code tries to parse files that start with #! and fails (happened before, and caused files starting with #! to be ignored in coverage reports, only it's now logged)
- Function finder doesn't recurse into ES6 class bodies (happened before, so coverage reports have been inaccurate since adding ES6 classes to the code, only the exception is now thrown and fails the tests)
Comment 13 Philip Chimento 2017-09-23 04:13:52 UTC
Attachment 359453 [details] pushed as 9b0beff - coverage: Use global bootstrap to add JS coverage code