Re: cgjs VS cgj + esm progress



Hi Andrea,

Thanks for finding that out. This is good news.

Unfortunately it's not that simple - I checked and the module loader is not part of SpiderMonkey, it's part of the SpiderMonkey test shell. We don't run that directly, so we can't simply pass the -m flag. However, the good news is that it should be possible to build something similar to what's in in the test shell, by copying it mostly.

Source code: https://searchfox.org/mozilla-central/source/js/src/shell

If you or anyone wants to pick this up, here's how I would start: copy the JS module loader into modules/_bootstrap/default.js, and copy the missing functions such as setModuleResolveHook from the test shell's js.cpp and define them in the bootstrap module's environment in gjs/global.cpp. The difficult part might be due to the test shell code having access to private SpiderMonkey API, whereas we don't.
Then we could hopefully reimplement the existing importer in terms of the module loader so that existing code using the old imports would continue to work, but we could get rid of importer.cpp.

I could probably do this for GNOME 3.30, but I would do it after the things that I currently have in progress, like the debugger and the port to SpiderMonkey 60. So it would be a great project for someone else to pick up!

Regards,
Philip C

On Sun, Feb 4, 2018 at 1:48 AM Andrea Giammarchi <andrea giammarchi gmail com> wrote:
Hi Philip,
  SpiderMonkey already supports ESM indeed, you just need to start the project with a `-m` or `--module=PATH` flag.

If GJS would be so kind to pass along such flag when used, developers could arbitrary decide to start GJS as module or not.

Test case

a.js
```
import {cwd} from './b.js';
print(cwd());
```

b.js
```
const GLib = imports.gi.GLib;
export const cwd = () => GLib.get_current_dir();
```

gjs -m a.js

should not produce syntax error, should pass -m flag along and let SpiderMonkey handle the ESM module system.

Where should I look to pass along flags ?

Thanks!




On Sun, Feb 4, 2018 at 2:18 AM, <philip chimento gmail com> wrote:
On Sat, Feb 3, 2018 at 5:00 AM Andrea Giammarchi <andrea giammarchi gmail com> wrote:
I know CGJS progress is quite slow, I've been busy with other projects, but I wonder if it's possible to know what's the actual ESM status in GJS in general.

It would be awesome to be able to use just `import module from "./file.js"` in GJS so that I can make CGJS also compatible with published ESM which start appearing in npm.

Thanks in advance for any sort of update about this.

Best Regards

P.S. the global process just landed in core https://github.com/cgjs/process#cgjsprocess-

Hi Andrea,

Nothing has happened with this yet.

I would welcome some help. I think enough of ES6 modules are implemented in SpiderMonkey 52 that it should be possible to get a proof of concept working.

Regards,
Philip C



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]