Skip to content

arg-cache: Never throw when building the argument cache

Previously, the methods for building the argument cache for a function could fail, and throw an exception. Normally this was not a problem, since the argument cache was built when creating the Function object, and that was generally created right before it was about to be called.

However, static methods are created eagerly when defining a type's constructor, so if a type contained a method that would throw when building the argument cache, then merely resolving that type would throw. (For example, resolving GLib.ByteArray would throw.)

Instead, change all the argument cache building methods to be infallible. If an argument is not supported in GJS, then its in-marshaller throws instead. This causes the error to happen when the Function object is called, not when it is created.

In order to give good exception messages, we add a "reason" field to the GjsArgumentCache union, used by the new gjs_marshal_not_introspectable_in marshaller, and a display_name() method to GjsFunctionCallState.

Closes: #386 (closed)

Merge request reports