• Philip Chimento's avatar
    jsapi-util: Rooting-safe gjs_parse_call_args() · 11d96aa9
    Philip Chimento authored
    This removes the old unused gjs_parse_args(), and moves
    gjs_parse_call_args() into new files jsapi-util-args.cpp and
    jsapi-util-args.h.
    
    In order to ensure that JSObjects unpacked from gjs_parse_call_args()
    land in GC roots, we need to add some type safety to its variable
    arguments. Instead of accepting a JSObject** pointer for the "o" format
    character, it must accept a JS::MutableHandleObject.
    
    We can do this (and make the whole thing type safe as well) by using C++
    templates instead of C varargs. Now we can issue a compile-time error
    when an unknown type is passed in as a return location for an argument,
    in particular JSObject**.
    
    This also fixes some undefined behaviour: the old signature of
    gjs_parse_call_args() placed the varargs parameter right after the
    JS::CallArgs& parameter, and using a reference parameter in va_start() is
    undefined. Here's a good explanation of what can go wrong:
    http://stackoverflow.com/a/222288/172999
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742249
    11d96aa9
Makefile.am 6.48 KB