GNOME Bugzilla – Bug 781623
Can't call exports using top-level variable toString
Last modified: 2017-07-27 00:41:08 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
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.
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.
Review of attachment 356250 [details] [review]: Looks good to me.