Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ESR52 SpiderMonkey & ES6

86 views
Skip to first unread message

Kent Williams

unread,
Jun 20, 2018, 4:11:48 PM6/20/18
to dev-tech-...@lists.mozilla.org
Been beating my head on this for a couple of days.

I'm trying to get ES6 module support working with ESR52 SpiderMonkey.

I can run plain scripts just fine, but if I try using ES6 modules, it
breaks.

I solved one problem: You can't compile anything 'import' in it without
setting the Module resolver with JS::SetModuleResolveHook.

Then it turns out you can't use JS::Compile with any code with 'import'
in it -- even if it isn't a module itself.

But if you use JS::CompileModule, it isn't clear what you have to do to
execute the script.

What should happen is that you do X (where X is unknown) to execute the
script, and then the interpreter handles the 'import' statements in your
code by calling the resolve hook.

So my problem is X -- if you have to use JS::CompileModule if there are
any import statements in a script, how do you execute the script?

Looking at the JS Shell code, the resolve hook is actually in a
Javascript file.  I tried doing what that file does (ModuleLoader.js)
but it doesn't work.  I call ModuleDeclarationInstantiation followed by
ModuleEvaluation -- and both fail without any error message. They return
false, and there's no apparent error message anywhere.

Is it the case that no one uses ES6 modules with SpiderMonkey, except
perhaps the Mozilla Browswer & the js shell included?




Jason Orendorff

unread,
Jun 23, 2018, 3:25:33 PM6/23/18
to Kent Williams, dev-tech-...@lists.mozilla.org
You're right, this is super complicated. :-\

Well, I guess the first task is to get an error message. There's no pending
exception when these functions return false?

-j


On Wed, Jun 20, 2018 at 3:11 PM, Kent Williams <kwil...@leepfrog.com>
wrote:
> _______________________________________________
> dev-tech-js-engine mailing list
> dev-tech-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>

Philip Chimento

unread,
Jul 26, 2018, 11:14:50 AM7/26/18
to
On Saturday, June 23, 2018 at 3:25:33 PM UTC-4, Jason Orendorff wrote:
> You're right, this is super complicated. :-\
>
> Well, I guess the first task is to get an error message. There's no pending
> exception when these functions return false?
>
> -j
>
>
> On Wed, Jun 20, 2018 at 3:11 PM, Kent Williams <k...@l...com>
> wrote:
>
> > Been beating my head on this for a couple of days.
> >
> > I'm trying to get ES6 module support working with ESR52 SpiderMonkey.
> >
> > I can run plain scripts just fine, but if I try using ES6 modules, it
> > breaks.
> >
> > I solved one problem: You can't compile anything 'import' in it without
> > setting the Module resolver with JS::SetModuleResolveHook.
> >
> > Then it turns out you can't use JS::Compile with any code with 'import' in
> > it -- even if it isn't a module itself.
> >
> > But if you use JS::CompileModule, it isn't clear what you have to do to
> > execute the script.
> >
> > What should happen is that you do X (where X is unknown) to execute the
> > script, and then the interpreter handles the 'import' statements in your
> > code by calling the resolve hook.
> >
> > So my problem is X -- if you have to use JS::CompileModule if there are
> > any import statements in a script, how do you execute the script?
> >
> > Looking at the JS Shell code, the resolve hook is actually in a Javascript
> > file. I tried doing what that file does (ModuleLoader.js) but it doesn't
> > work. I call ModuleDeclarationInstantiation followed by ModuleEvaluation
> > -- and both fail without any error message. They return false, and there's
> > no apparent error message anywhere.
> >
> > Is it the case that no one uses ES6 modules with SpiderMonkey, except
> > perhaps the Mozilla Browswer & the js shell included?

We have a branch in progress for this in GJS: https://gitlab.gnome.org/GNOME/gjs/merge_requests/150 It's currently still based on ESR52, but the basics do seem to work.
There's some information there that may help you. I believe the module is executed during the ModuleEvaluation step.

Regards,
Philip

Kent Williams

unread,
Jul 30, 2018, 10:20:47 AM7/30/18
to dev-tech-...@lists.mozilla.org
I resolved this by realizing that I know when something is a module, and
when it is not, based on my application. Will look at your solution also.
0 new messages