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 691108 - context: Only call JS_SetCStringsAreUTF8() once
context: Only call JS_SetCStringsAreUTF8() once
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks: 691109
 
 
Reported: 2013-01-04 04:58 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2013-01-07 20:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
context: Only call JS_SetCStringsAreUTF8() once (1.45 KB, patch)
2013-01-04 04:58 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
Fix GJS tests with debug builds of Spidermonkey (4.99 KB, patch)
2013-01-04 23:40 UTC, Giovanni Campagna
reviewed Details | Review
unit-test-utils: Use a standard gjs context (2.12 KB, patch)
2013-01-07 19:05 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
test: Refactor the unit test framework (28.25 KB, patch)
2013-01-07 19:05 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
context: Only call JS_SetCStringsAreUTF8() once (1.64 KB, patch)
2013-01-07 19:41 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review

Description Jasper St. Pierre (not reading bugmail) 2013-01-04 04:58:04 UTC
Otherwise, this fails some tests with debug builds of libmozjs.
Unfortunately, this still fails with some unit tests that call
JS_NewRuntime manually. Trying to make them gjs_context_new()
ends with disaster, complaining about reregistering types.
Comment 1 Jasper St. Pierre (not reading bugmail) 2013-01-04 04:58:06 UTC
Created attachment 232700 [details] [review]
context: Only call JS_SetCStringsAreUTF8() once

The JS engine mandates that this is called once, and before
the first runtime is constructed. This is enforced by an
assertion that's turned on in debug builds.
Comment 2 Giovanni Campagna 2013-01-04 13:41:19 UTC
Review of attachment 232700 [details] [review]:

::: gjs/context.c
@@ +563,3 @@
+            JS_SetCStringsAreUTF8();
+            new_runtime_called = TRUE;
+        }

I would move this into a separate initialization helper, and maybe use GOnce just for consistency with other initializers.
Comment 3 Giovanni Campagna 2013-01-04 13:44:05 UTC
(In reply to comment #0)
> Otherwise, this fails some tests with debug builds of libmozjs.
> Unfortunately, this still fails with some unit tests that call
> JS_NewRuntime manually. Trying to make them gjs_context_new()
> ends with disaster, complaining about reregistering types.

The JS_SetCStringAreUTF8 call for that is in _gjs_unit_test_fixture_begin (gjs/unit-test-utils.c). You should be able to apply the same logic there.
Comment 4 Jasper St. Pierre (not reading bugmail) 2013-01-04 13:45:43 UTC
I'd rather figure out why GTester is messing up. It makes sense to me to go through the same code path in unit tests that we do everywhere else.
Comment 5 Giovanni Campagna 2013-01-04 13:50:47 UTC
(In reply to comment #4)
> I'd rather figure out why GTester is messing up. It makes sense to me to go
> through the same code path in unit tests that we do everywhere else.

We're compiling the code with different flags to get at the test functions. If we also link to libgjs, we get duplicate symbols and thus wrong type registration.
Comment 6 Giovanni Campagna 2013-01-04 23:40:26 UTC
Created attachment 232793 [details] [review]
Fix GJS tests with debug builds of Spidermonkey

SetCStringsAreUTF8 must be called only before any runtime is created
Switching text fixtures to use GjsContext reveals that gjs-tests have
been linking to libgjs all the time, despite exporting symbols with
the same names. We must instead compile the libgjs sources separately.

If you're interested, with this I completed a make check on debug
js 185.
Comment 7 Jasper St. Pierre (not reading bugmail) 2013-01-05 00:15:35 UTC
I was hoping to get rid of the crazy gjstests python file that generates a bunch of boilerplate we could manually write in each test file, because it's not enough code to manually write to want a code generator.
Comment 8 Jasper St. Pierre (not reading bugmail) 2013-01-07 19:05:27 UTC
Created attachment 232917 [details] [review]
unit-test-utils: Use a standard gjs context

Rather than construct ourselves our own JSContext, use GjsContext,
which will initialize the engine and call JS_SetCStringsAreUTF8(),
which can only be called once.
Comment 9 Jasper St. Pierre (not reading bugmail) 2013-01-07 19:05:29 UTC
Created attachment 232918 [details] [review]
test: Refactor the unit test framework

Rather than fight with a system which autogenerates a gtest for about
ten tests, simply put tests manually in the file for now.

By putting these tests in separate files, it also means that we won't
have strange dual symbol issues by compiling the same source file twice.
A test framework should represent usage in the real world, after all.
Comment 10 Jasper St. Pierre (not reading bugmail) 2013-01-07 19:09:07 UTC
(In reply to comment #2)
> Review of attachment 232700 [details] [review]:
> 
> ::: gjs/context.c
> @@ +563,3 @@
> +            JS_SetCStringsAreUTF8();
> +            new_runtime_called = TRUE;
> +        }
> 
> I would move this into a separate initialization helper, and maybe use GOnce
> just for consistency with other initializers.

I started this, but expected you would say "lose the GOnce, we don't need thread safety here".
Comment 11 Jasper St. Pierre (not reading bugmail) 2013-01-07 19:09:59 UTC
Review of attachment 232793 [details] [review]:

I like my approach that removes the insanity better.
Comment 12 Jasper St. Pierre (not reading bugmail) 2013-01-07 19:41:50 UTC
Created attachment 232921 [details] [review]
context: Only call JS_SetCStringsAreUTF8() once

The JS engine mandates that this is called once, and before
the first runtime is constructed. This is enforced by an
assertion that's turned on in debug builds.
Comment 13 Colin Walters 2013-01-07 19:55:05 UTC
Review of attachment 232918 [details] [review]:

Two minor bits, feel free to commit after addressing.

::: test/gjs-tests.c
@@ +27,3 @@
 #include <glib.h>
 #include <glib-object.h>
+#include <gjs/gjs-module.h>

gjs-module.h should pull in jsapi.h, no?

::: test/test.h
@@ +20,3 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  * IN THE SOFTWARE.
  */

Shouldn't this file be deleted entirely now?
Comment 14 Colin Walters 2013-01-07 19:55:27 UTC
Review of attachment 232917 [details] [review]:

Right.
Comment 15 Colin Walters 2013-01-07 19:55:53 UTC
Review of attachment 232921 [details] [review]:

Looks right.
Comment 16 Jasper St. Pierre (not reading bugmail) 2013-01-07 20:03:18 UTC
Attachment 232917 [details] pushed as 30d3fc0 - unit-test-utils: Use a standard gjs context
Attachment 232918 [details] pushed as c4bd39e - test: Refactor the unit test framework
Attachment 232921 [details] pushed as 9148ed0 - context: Only call JS_SetCStringsAreUTF8() once


Thanks for spotting those -- I meant to delete test.h but I guess I forgot.
Other things fixed.