GNOME Bugzilla – Bug 694355
gjs crash when iterating content array
Last modified: 2013-02-21 15:58:38 UTC
The following script crashes gjs : ----------------------------------------- const Gio = imports.gi.Gio; let file = Gio.File.new_for_path('COPYING'); let [success, fileContent, tag] = file.load_contents(null); for (let i in fileContent) { log(fileContent[i]); } ----------------------------------------- just replace 'COPYING' by whatever file on your filesystem.
Adding backtrace : Program received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? () (gdb) bt
+ Trace 231541
Uh oh: the fileContent object is a ByteArray, not a regular Array, and it's enumerate hook is NULL. We need to fix it, or replace it JS_EnumerateStub. Btw, a simple workaround is to use C-style looping, as recommended in the style guide: for (let i = 0; i < fileContent.length; i++) { ... }
(In reply to comment #2) > JS_EnumerateStub. I think this is the better solution for now.
Created attachment 237052 [details] [review] ByteArray: restore enumerability Having a NULL JSClass.enum hook causes a segmentation fault, use JS_EnumerateStub instead, until we implement proper enumeration.
Review of attachment 237052 [details] [review]: OK.
Attachment 237052 [details] pushed as 99208f7 - ByteArray: restore enumerability