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 781623 - Can't call exports using top-level variable toString
Can't call exports using top-level variable toString
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
1.48.x
Other Linux
: Normal minor
: ---
Assigned To: Philip Chimento
gjs-maint
Depends on: 784196
Blocks:
 
 
Reported: 2017-04-22 19:45 UTC by makepost
Modified: 2017-07-27 00:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
importer: Give module objects a [Symbol.toStringTag] (5.53 KB, patch)
2017-07-24 02:01 UTC, Philip Chimento
committed Details | Review

Description makepost 2017-04-22 19:45:07 UTC
Hi

A module contains a top-level variable named toString

I can't call its exports that make use of this variable anymore

Works as expected on Ubuntu 16.10 with gjs 1.46.0-1

Broken on Ubuntu 17.04 with gjs 1.48.0-0ubuntu1

Steps to reproduce:

```
rm -rf ~/gjs-toString-regression
mkdir ~/gjs-toString-regression

cat <<EOF > ~/gjs-toString-regression/foo.js
var toString = x => x

this.default = function (x) {
  print(x, toString(x))
}
EOF

cat <<EOF > ~/gjs-toString-regression/test.js
const foo = imports.foo.default
foo('bar')
// Expected: bar bar
// Actual: bar [GjsModule foo]
EOF

cd ~/gjs-toString-regression
gjs -I `pwd` test.js
```

In this simplified example it can be fixed by renaming toString

But in real word toString is a complex import deep in an external dependency

Luckily my case is simple, using the module was just a matter of convenience

Someone will run into this in future though
Comment 1 Philip Chimento 2017-04-23 05:09:42 UTC
Thanks for the report. This is an obscure case indeed. I'm pretty sure it was caused by the fix for bug 636283.

I would like to fix it by moving module objects to Symbol.toStringTag instead of a custom toString(), after we've upgraded to SpiderMonkey 52.
Comment 2 Philip Chimento 2017-07-24 02:01:52 UTC
Created attachment 356250 [details] [review]
importer: Give module objects a [Symbol.toStringTag]

Instead of defining a toString() function on module objects, give them a
[Symbol.toStringTag] property. This avoids overwriting a toString()
property that the module may have defined itself.
Comment 3 Cosimo Cecchi 2017-07-26 08:55:49 UTC
Review of attachment 356250 [details] [review]:

Looks good to me.