Commit 833c6459 authored by Marco Trevisan's avatar Marco Trevisan 🎺 Committed by Philip Chimento

js: Use gjs_arg_value to get, set and access GIArgument values

This allows to automatically use the proper union value depending on the
type without having to do it manually.

(Philip: changed some formatting, added char32_t for GI_TYPE_TAG_UNICHAR
and changed gjs_arg_value() to gjs_arg_get() if the union member wasn't
needed)
parent 8f220e66
This diff is collapsed.
......@@ -44,6 +44,7 @@
#include <mozilla/HashTable.h>
#include <mozilla/Vector.h>
#include "gi/arg-inl.h"
#include "gi/arg.h"
#include "gi/boxed.h"
#include "gi/function.h"
......@@ -374,7 +375,7 @@ bool BoxedInstance::constructor_impl(JSContext* context, JS::HandleObject obj,
return false;
}
own_ptr(rval_arg.v_pointer);
own_ptr(g_steal_pointer(&gjs_arg_member<void*>(&rval_arg)));
debug_lifecycle("Boxed pointer created from zero-args constructor");
......
......@@ -123,27 +123,32 @@ set_return_ffi_arg_from_giargument (GITypeInfo *ret_type,
case GI_TYPE_TAG_VOID:
g_assert_not_reached();
case GI_TYPE_TAG_INT8:
*(ffi_sarg *) result = return_value->v_int8;
*static_cast<ffi_sarg*>(result) = gjs_arg_get<int8_t>(return_value);
break;
case GI_TYPE_TAG_UINT8:
*(ffi_arg *) result = return_value->v_uint8;
*static_cast<ffi_arg*>(result) = gjs_arg_get<uint8_t>(return_value);
break;
case GI_TYPE_TAG_INT16:
*(ffi_sarg *) result = return_value->v_int16;
*static_cast<ffi_sarg*>(result) = gjs_arg_get<int16_t>(return_value);
break;
case GI_TYPE_TAG_UINT16:
*(ffi_arg *) result = return_value->v_uint16;
*static_cast<ffi_arg*>(result) = gjs_arg_get<uint16_t>(return_value);
break;
case GI_TYPE_TAG_INT32:
*(ffi_sarg *) result = return_value->v_int32;
*static_cast<ffi_sarg*>(result) = gjs_arg_get<int32_t>(return_value);
break;
case GI_TYPE_TAG_UINT32:
*static_cast<ffi_arg*>(result) = gjs_arg_get<uint32_t>(return_value);
break;
case GI_TYPE_TAG_BOOLEAN:
*static_cast<ffi_arg*>(result) =
gjs_arg_get<gboolean, GI_TYPE_TAG_BOOLEAN>(return_value);
break;
case GI_TYPE_TAG_UNICHAR:
*(ffi_arg *) result = return_value->v_uint32;
*static_cast<ffi_arg*>(result) = gjs_arg_get<char32_t>(return_value);
break;
case GI_TYPE_TAG_INT64:
*(ffi_sarg *) result = return_value->v_int64;
*static_cast<ffi_sarg*>(result) = gjs_arg_get<int64_t>(return_value);
break;
case GI_TYPE_TAG_INTERFACE:
{
......@@ -155,9 +160,11 @@ set_return_ffi_arg_from_giargument (GITypeInfo *ret_type,
if (interface_type == GI_INFO_TYPE_ENUM ||
interface_type == GI_INFO_TYPE_FLAGS)
*(ffi_sarg *) result = return_value->v_int;
*static_cast<ffi_sarg*>(result) =
gjs_arg_get<int, GI_TYPE_TAG_INTERFACE>(return_value);
else
*(ffi_arg *) result = (ffi_arg) return_value->v_pointer;
*static_cast<ffi_arg*>(result) =
gjs_arg_get<ffi_arg>(return_value);
g_base_info_unref(interface_info);
}
......@@ -175,7 +182,7 @@ set_return_ffi_arg_from_giargument (GITypeInfo *ret_type,
case GI_TYPE_TAG_GHASH:
case GI_TYPE_TAG_ERROR:
default:
*(ffi_arg *) result = (ffi_arg) return_value->v_uint64;
*static_cast<ffi_arg*>(result) = gjs_arg_get<ffi_arg>(return_value);
break;
}
}
......@@ -254,7 +261,7 @@ static void gjs_callback_closure(ffi_cif* cif G_GNUC_UNUSED, void* result,
JS::RootedObject this_object(context);
if (trampoline->is_vfunc) {
GObject* gobj = G_OBJECT(args[0]->v_pointer);
GObject* gobj = G_OBJECT(gjs_arg_get<GObject*>(args[0]));
if (gobj) {
this_object = ObjectInstance::wrapper_from_gobject(context, gobj);
if (!this_object) {
......@@ -485,7 +492,7 @@ out:
/* the GError ** pointer is the last argument, and is not
* included in the n_args */
GIArgument *error_argument = args[n_args + c_args_offset];
auto gerror = static_cast<GError **>(error_argument->v_pointer);
auto* gerror = gjs_arg_get<GError**>(error_argument);
g_propagate_error(gerror, local_error);
JS_ClearPendingException(context); /* don't log */
}
......@@ -615,26 +622,27 @@ GjsCallbackTrampoline* gjs_callback_trampoline_new(
(letting the compiler generate good instructions in case of
big endian machines) */
GJS_USE
static unsigned long
get_length_from_arg (GArgument *arg, GITypeTag tag)
{
if (tag == GI_TYPE_TAG_INT8)
return arg->v_int8;
if (tag == GI_TYPE_TAG_UINT8)
return arg->v_uint8;
if (tag == GI_TYPE_TAG_INT16)
return arg->v_int16;
if (tag == GI_TYPE_TAG_UINT16)
return arg->v_uint16;
if (tag == GI_TYPE_TAG_INT32)
return arg->v_int32;
if (tag == GI_TYPE_TAG_UINT32)
return arg->v_uint32;
if (tag == GI_TYPE_TAG_INT64)
return arg->v_int64;
if (tag == GI_TYPE_TAG_UINT64)
return arg->v_uint64;
g_assert_not_reached();
static size_t get_length_from_arg(GArgument* arg, GITypeTag tag) {
switch (tag) {
case GI_TYPE_TAG_INT8:
return gjs_arg_get<int8_t>(arg);
case GI_TYPE_TAG_UINT8:
return gjs_arg_get<uint8_t>(arg);
case GI_TYPE_TAG_INT16:
return gjs_arg_get<int16_t>(arg);
case GI_TYPE_TAG_UINT16:
return gjs_arg_get<uint16_t>(arg);
case GI_TYPE_TAG_INT32:
return gjs_arg_get<int32_t>(arg);
case GI_TYPE_TAG_UINT32:
return gjs_arg_get<uint32_t>(arg);
case GI_TYPE_TAG_INT64:
return gjs_arg_get<int64_t>(arg);
case GI_TYPE_TAG_UINT64:
return gjs_arg_get<uint64_t>(arg);
default:
g_assert_not_reached();
}
}
GJS_JSAPI_RETURN_CONVENTION
......@@ -683,7 +691,7 @@ gjs_fill_method_instance(JSContext *context,
else
klass = g_type_class_peek(actual_gtype);
out_arg->v_pointer = klass;
gjs_arg_set(out_arg, klass);
} else {
if (!BoxedBase::transfer_to_gi_argument(context, obj, out_arg,
GI_DIRECTION_OUT, transfer,
......@@ -706,9 +714,9 @@ gjs_fill_method_instance(JSContext *context,
} else if (g_type_is_a(gtype, G_TYPE_PARAM)) {
if (!gjs_typecheck_param(context, obj, G_TYPE_PARAM, true))
return false;
out_arg->v_pointer = gjs_g_param_from_param(context, obj);
gjs_arg_set(out_arg, gjs_g_param_from_param(context, obj));
if (transfer == GI_TRANSFER_EVERYTHING)
g_param_spec_ref ((GParamSpec*) out_arg->v_pointer);
g_param_spec_ref(gjs_arg_get<GParamSpec*>(out_arg));
} else if (G_TYPE_IS_INTERFACE(gtype)) {
if (ObjectBase::check_jsclass(context, obj)) {
if (!ObjectBase::transfer_to_gi_argument(context, obj, out_arg,
......@@ -962,8 +970,11 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
g_base_info_unref((GIBaseInfo*)interface_info);
if (!failed) {
in_arg_cvalues[c_arg_pos].v_pointer = g_slice_alloc0(size);
out_arg_cvalues[c_arg_pos].v_pointer = in_arg_cvalues[c_arg_pos].v_pointer;
gjs_arg_set(&in_arg_cvalues[c_arg_pos],
g_slice_alloc0(size));
gjs_arg_set(
&out_arg_cvalues[c_arg_pos],
gjs_arg_get<void*>(&in_arg_cvalues[c_arg_pos]));
}
} else {
failed = true;
......@@ -971,8 +982,10 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
if (failed)
gjs_throw(context, "Unsupported type %s for (out caller-allocates)", g_type_tag_to_string(type_tag));
} else {
out_arg_cvalues[c_arg_pos].v_pointer = NULL;
in_arg_cvalues[c_arg_pos].v_pointer = &out_arg_cvalues[c_arg_pos];
gjs_arg_unset<void*>(&out_arg_cvalues[c_arg_pos]);
gjs_arg_set(
&in_arg_cvalues[c_arg_pos],
&gjs_arg_member<void*>(&out_arg_cvalues[c_arg_pos]));
}
} else {
GArgument *in_value;
......@@ -1039,12 +1052,14 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
if (destroy_pos >= 0) {
gint c_pos = is_method ? destroy_pos + 1 : destroy_pos;
g_assert (function->param_types[destroy_pos] == PARAM_SKIPPED);
in_arg_cvalues[c_pos].v_pointer = trampoline ? (gpointer) gjs_destroy_notify_callback : NULL;
gjs_arg_set(
&in_arg_cvalues[c_pos],
trampoline ? gjs_destroy_notify_callback : nullptr);
}
if (closure_pos >= 0) {
gint c_pos = is_method ? closure_pos + 1 : closure_pos;
g_assert (function->param_types[closure_pos] == PARAM_SKIPPED);
in_arg_cvalues[c_pos].v_pointer = trampoline;
gjs_arg_set(&in_arg_cvalues[c_pos], trampoline);
}
if (trampoline && scope != GI_SCOPE_TYPE_CALL) {
......@@ -1052,7 +1067,7 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
async calls, or when GDestroyNotify is called */
gjs_callback_trampoline_ref(trampoline);
}
in_value->v_pointer = closure;
gjs_arg_set(in_value, closure);
break;
}
case PARAM_SKIPPED:
......@@ -1081,17 +1096,21 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
}
/* Also handle the INOUT for the length here */
if (direction == GI_DIRECTION_INOUT) {
if (in_value->v_pointer == NULL) {
if (!gjs_arg_get<void*>(in_value)) {
/* Special case where we were given JS null to
* also pass null for length, and not a
* pointer to an integer that derefs to 0.
*/
in_arg_cvalues[array_length_pos].v_pointer = NULL;
out_arg_cvalues[array_length_pos].v_pointer = NULL;
inout_original_arg_cvalues[array_length_pos].v_pointer = NULL;
gjs_arg_set(&in_arg_cvalues[array_length_pos], nullptr);
gjs_arg_set(&out_arg_cvalues[array_length_pos],
nullptr);
gjs_arg_set(
&inout_original_arg_cvalues[array_length_pos],
nullptr);
} else {
out_arg_cvalues[array_length_pos] = inout_original_arg_cvalues[array_length_pos] = *(in_arg_cvalues + array_length_pos);
in_arg_cvalues[array_length_pos].v_pointer = &out_arg_cvalues[array_length_pos];
gjs_arg_set(&in_arg_cvalues[array_length_pos],
&out_arg_cvalues[array_length_pos]);
}
}
break;
......@@ -1124,7 +1143,8 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
if (direction == GI_DIRECTION_INOUT && !arg_removed && !failed) {
out_arg_cvalues[c_arg_pos] = inout_original_arg_cvalues[c_arg_pos] = in_arg_cvalues[c_arg_pos];
in_arg_cvalues[c_arg_pos].v_pointer = &out_arg_cvalues[c_arg_pos];
gjs_arg_set(&in_arg_cvalues[c_arg_pos],
&out_arg_cvalues[c_arg_pos]);
}
if (failed) {
......@@ -1151,7 +1171,7 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
if (can_throw_gerror) {
g_assert_cmpuint(c_arg_pos, <, c_argc);
in_arg_cvalues[c_arg_pos].v_pointer = &local_error;
gjs_arg_set(&in_arg_cvalues[c_arg_pos], &local_error);
ffi_arg_pointers[c_arg_pos] = &(in_arg_cvalues[c_arg_pos]);
c_arg_pos++;
......@@ -1288,14 +1308,14 @@ release:
gi_arg_pos, gi_argc, c_arg_pos, processed_c_args);
if (param_type == PARAM_CALLBACK) {
ffi_closure *closure = (ffi_closure *) arg->v_pointer;
auto* closure = gjs_arg_get<ffi_closure*>(arg);
if (closure) {
GjsCallbackTrampoline *trampoline = (GjsCallbackTrampoline *) closure->user_data;
/* CallbackTrampolines are refcounted because for notified/async closures
it is possible to destroy it while in call, and therefore we cannot check
its scope at this point */
gjs_callback_trampoline_unref(trampoline);
arg->v_pointer = NULL;
gjs_arg_unset<void*>(arg);
}
} else if (param_type == PARAM_ARRAY) {
gsize length;
......@@ -1423,7 +1443,8 @@ release:
g_assert_not_reached();
}
g_slice_free1(size, out_arg_cvalues[c_arg_pos].v_pointer);
g_slice_free1(size,
gjs_arg_get<void*>(&out_arg_cvalues[c_arg_pos]));
g_base_info_unref((GIBaseInfo*)interface_info);
}
......
......@@ -37,6 +37,7 @@
#include <jsapi.h> // for InformalValueTypeName, JS_GetClass
#include <mozilla/HashTable.h>
#include "gi/arg-inl.h"
#include "gi/arg.h"
#include "gi/function.h"
#include "gi/fundamental.h"
......@@ -210,7 +211,7 @@ bool FundamentalInstance::constructor_impl(JSContext* cx,
GITypeInfo return_info;
if (!invoke_constructor(cx, object, argv, &ret_value) ||
!associate_js_instance(cx, object, ret_value.v_pointer))
!associate_js_instance(cx, object, gjs_arg_get<void*>(&ret_value)))
return false;
GICallableInfo* constructor_info = get_prototype()->constructor_info();
......
......@@ -39,6 +39,7 @@
#include <jsapi.h> // for JS_DefinePropertyById, JS_GetProp...
#include <jspubtd.h> // for JSProtoKey, JSProto_Error, JSProt...
#include "gi/arg-inl.h"
#include "gi/boxed.h"
#include "gi/enumeration.h"
#include "gi/gerror.h"
......@@ -419,21 +420,21 @@ bool ErrorBase::transfer_to_gi_argument(JSContext* cx, JS::HandleObject obj,
"transfer_to_gi_argument() must choose between in or out");
if (!ErrorBase::typecheck(cx, obj)) {
arg->v_pointer = nullptr;
gjs_arg_unset<void*>(arg);
return false;
}
arg->v_pointer = ErrorBase::to_c_ptr(cx, obj);
if (!arg->v_pointer)
gjs_arg_set(arg, ErrorBase::to_c_ptr(cx, obj));
if (!gjs_arg_get<void*>(arg))
return false;
if ((transfer_direction == GI_DIRECTION_IN &&
transfer_ownership != GI_TRANSFER_NOTHING) ||
(transfer_direction == GI_DIRECTION_OUT &&
transfer_ownership == GI_TRANSFER_EVERYTHING)) {
arg->v_pointer =
ErrorInstance::copy_ptr(cx, G_TYPE_ERROR, arg->v_pointer);
if (!arg->v_pointer)
gjs_arg_set(arg, ErrorInstance::copy_ptr(cx, G_TYPE_ERROR,
gjs_arg_get<void*>(arg)));
if (!gjs_arg_get<void*>(arg))
return false;
}
......
......@@ -56,6 +56,7 @@
#include <mozilla/HashTable.h>
#include <mozilla/Vector.h>
#include "gi/arg-inl.h"
#include "gi/arg.h"
#include "gi/closure.h"
#include "gi/function.h"
......@@ -2421,7 +2422,7 @@ bool ObjectBase::transfer_to_gi_argument(JSContext* cx, JS::HandleObject obj,
"transfer_to_gi_argument() must choose between in or out");
if (!ObjectBase::typecheck(cx, obj, expected_info, expected_gtype)) {
arg->v_pointer = nullptr;
gjs_arg_unset<void*>(arg);
return false;
}
......@@ -2429,21 +2430,19 @@ bool ObjectBase::transfer_to_gi_argument(JSContext* cx, JS::HandleObject obj,
if (!ObjectBase::to_c_ptr(cx, obj, &ptr))
return false;
gjs_arg_set(arg, ptr);
// Pointer can be null if object was already disposed by C code
if (!ptr) {
arg->v_pointer = nullptr;
if (!ptr)
return true;
}
arg->v_pointer = ptr;
if ((transfer_direction == GI_DIRECTION_IN &&
transfer_ownership != GI_TRANSFER_NOTHING) ||
(transfer_direction == GI_DIRECTION_OUT &&
transfer_ownership == GI_TRANSFER_EVERYTHING)) {
arg->v_pointer =
ObjectInstance::copy_ptr(cx, expected_gtype, arg->v_pointer);
if (!arg->v_pointer)
gjs_arg_set(arg, ObjectInstance::copy_ptr(cx, expected_gtype,
gjs_arg_get<void*>(arg)));
if (!gjs_arg_get<void*>(arg))
return false;
}
......
......@@ -31,6 +31,7 @@
#include <js/TypeDecls.h>
#include <js/Warnings.h>
#include "gi/arg-inl.h"
#include "gi/function.h"
#include "gi/repo.h"
#include "gi/union.h"
......@@ -115,7 +116,7 @@ static void* union_new(JSContext* context, JS::HandleObject this_obj,
args, &rval))
return nullptr;
if (!rval.v_pointer) {
if (!gjs_arg_get<void*>(&rval)) {
gjs_throw(context,
"Unable to construct union type %s as its"
"constructor function returned null",
......@@ -123,7 +124,7 @@ static void* union_new(JSContext* context, JS::HandleObject this_obj,
return nullptr;
}
return rval.v_pointer;
return gjs_arg_get<void*>(&rval);
}
}
......
......@@ -41,6 +41,7 @@
#include <jsapi.h> // for InformalValueTypeName, JS_ClearPendingException
#include <mozilla/Unused.h>
#include "gi/arg-inl.h"
#include "gi/arg.h"
#include "gi/boxed.h"
#include "gi/closure.h"
......@@ -125,7 +126,7 @@ gjs_value_from_array_and_length_values(JSContext *context,
signal_query, array_length_arg_n))
return false;
array_arg.v_pointer = g_value_get_pointer(array_value);
gjs_arg_set(&array_arg, g_value_get_pointer(array_value));
return gjs_value_from_explicit_array(context, value_p, array_type_info,
&array_arg, array_length.toInt32());
......@@ -584,7 +585,7 @@ gjs_value_to_g_value_internal(JSContext *context,
true, &arg))
return false;
gboxed = arg.v_pointer;
gboxed = gjs_arg_get<void*>(&arg);
}
}
......@@ -910,7 +911,7 @@ gjs_value_from_g_value_internal(JSContext *context,
if (info.type() == GI_INFO_TYPE_STRUCT &&
g_struct_info_is_foreign(info)) {
GIArgument arg;
arg.v_pointer = gboxed;
gjs_arg_set(&arg, gboxed);
return gjs_struct_foreign_convert_from_g_argument(context, value_p,
info, &arg);
}
......@@ -961,7 +962,7 @@ gjs_value_from_g_value_internal(JSContext *context,
" calling gjs_value_from_g_value_internal()",
g_type_info_get_array_length(&type_info) == -1));
arg.v_pointer = g_value_get_pointer(gvalue);
gjs_arg_set(&arg, g_value_get_pointer(gvalue));
res = gjs_value_from_g_argument(context, value_p, &type_info, &arg, true);
......
......@@ -45,6 +45,7 @@
#include <jsapi.h> // for JS_GetPrivate, JS_SetPrivate, JS_Ge...
#include <jspubtd.h> // for JSProto_TypeError
#include "gi/arg-inl.h"
#include "gjs/atoms.h"
#include "gjs/context-private.h"
#include "gjs/jsapi-class.h" // IWYU pragma: keep
......@@ -623,14 +624,14 @@ class GIWrapperBase {
* @expected_info: Introspection info to perform a typecheck with
*
* Prepares @arg for passing the value from @obj into C code. It will get a
* C pointer from @obj and assign it to @arg->v_pointer, taking a reference
* with GIWrapperInstance::copy_ptr() if @transfer_direction and
* C pointer from @obj and assign it to @arg's pointer field, taking a
* reference with GIWrapperInstance::copy_ptr() if @transfer_direction and
* @transfer_ownership indicate that it should.
*
* Includes a typecheck using GIWrapperBase::typecheck(), to which
* @expected_gtype and @expected_info are passed.
*
* If returning false, then @arg->v_pointer is null.
* If returning false, then @arg's pointer field is null.
*/
GJS_JSAPI_RETURN_CONVENTION
static bool transfer_to_gi_argument(JSContext* cx, JS::HandleObject obj,
......@@ -643,21 +644,21 @@ class GIWrapperBase {
"transfer_to_gi_argument() must choose between in or out");
if (!Base::typecheck(cx, obj, expected_info, expected_gtype)) {
arg->v_pointer = nullptr;
gjs_arg_unset<void*>(arg);
return false;
}
arg->v_pointer = Base::to_c_ptr(cx, obj);
if (!arg->v_pointer)
gjs_arg_set(arg, Base::to_c_ptr(cx, obj));
if (!gjs_arg_get<void*>(arg))
return false;
if ((transfer_direction == GI_DIRECTION_IN &&
transfer_ownership != GI_TRANSFER_NOTHING) ||
(transfer_direction == GI_DIRECTION_OUT &&
transfer_ownership == GI_TRANSFER_EVERYTHING)) {
arg->v_pointer =
Instance::copy_ptr(cx, expected_gtype, arg->v_pointer);
if (!arg->v_pointer)
gjs_arg_set(arg, Instance::copy_ptr(cx, expected_gtype,
gjs_arg_get<void*>(arg)));
if (!gjs_arg_get<void*>(arg))
return false;
}
......
......@@ -40,6 +40,7 @@
#include <js/Value.h>
#include <jsapi.h> // for JS_SetElement, JS_NewArrayObject
#include "gi/arg-inl.h"
#include "gi/arg.h"
#include "gi/foreign.h"
#include "gjs/jsapi-class.h"
......@@ -984,7 +985,7 @@ context_to_g_argument(JSContext *context,
return false;
}
arg->v_pointer = nullptr;
gjs_arg_unset<void*>(arg);
return true;
}
......@@ -997,7 +998,7 @@ context_to_g_argument(JSContext *context,
if (transfer == GI_TRANSFER_EVERYTHING)
cairo_reference(cr);
arg->v_pointer = cr;
gjs_arg_set(arg, cr);
return true;
}
......@@ -1007,9 +1008,8 @@ context_from_g_argument(JSContext *context,
JS::MutableHandleValue value_p,
GIArgument *arg)
{
JSObject *obj;
obj = gjs_cairo_context_from_context(context, (cairo_t*)arg->v_pointer);
JSObject* obj =
gjs_cairo_context_from_context(context, gjs_arg_get<cairo_t*>(arg));
if (!obj) {
gjs_throw(context, "Could not create Cairo context");
return false;
......@@ -1022,7 +1022,7 @@ context_from_g_argument(JSContext *context,
static bool context_release_argument(JSContext*, GITransfer transfer,
GIArgument* arg) {
if (transfer != GI_TRANSFER_NOTHING)
cairo_destroy(static_cast<cairo_t*>(arg->v_pointer));
cairo_destroy(gjs_arg_get<cairo_t*>(arg));
return true;
}
......
......@@ -37,6 +37,7 @@
#include <js/Value.h>
#include <jsapi.h> // for JS_GetPropertyById, JS_SetPropert...
#include "gi/arg-inl.h"
#include "gi/arg.h"
#include "gi/foreign.h"
#include "gjs/atoms.h"
......@@ -313,7 +314,7 @@ region_to_g_argument(JSContext *context,
return false;
}
arg->v_pointer = nullptr;
gjs_arg_unset<void*>(arg);
return true;
}
......@@ -326,7 +327,7 @@ region_to_g_argument(JSContext *context,
if (transfer == GI_TRANSFER_EVERYTHING)
cairo_region_destroy(region);
arg->v_pointer = region;
gjs_arg_set(arg, region);
return true;
}
......@@ -336,9 +337,8 @@ region_from_g_argument(JSContext *context,
JS::MutableHandleValue value_p,
GIArgument *arg)
{
JSObject *obj;
obj = gjs_cairo_region_from_region(context, (cairo_region_t*)arg->v_pointer);
JSObject* obj = gjs_cairo_region_from_region(
context, gjs_arg_get<cairo_region_t*>(arg));
if (!obj)
return false;
......@@ -349,7 +349,7 @@ region_from_g_argument(JSContext *context,
static bool region_release_argument(JSContext*, GITransfer transfer,
GIArgument* arg) {
if (transfer != GI_TRANSFER_NOTHING)
cairo_region_destroy(static_cast<cairo_region_t*>(arg->v_pointer));
cairo_region_destroy(gjs_arg_get<cairo_region_t*>(arg));
return true;
}
......
......@@ -36,6 +36,7 @@
#include <js/Value.h>
#include <jsapi.h> // for JS_GetPrivate, JS_GetClass, ...
#include "gi/arg-inl.h"
#include "gi/arg.h"
#include "gi/foreign.h"
#include "gjs/jsapi-class.h"
......@@ -257,7 +258,7 @@ surface_to_g_argument(JSContext *context,
return false;
}
arg->v_pointer = nullptr;
gjs_arg_unset<void*>(arg);
return true;
}
......@@ -276,7 +277,7 @@ surface_to_g_argument(JSContext *context,
if (transfer == GI_TRANSFER_EVERYTHING)
cairo_surface_destroy(s);
arg->v_pointer = s;
gjs_arg_set(arg, s);
return true;
}
......@@ -286,9 +287,8 @@ surface_from_g_argument(JSContext *context,
JS::MutableHandleValue value_p,
GIArgument *arg)
{
JSObject *obj;
obj = gjs_cairo_surface_from_surface(context, (cairo_surface_t*)arg->v_pointer);
JSObject* obj = gjs_cairo_surface_from_surface(
context, gjs_arg_get<cairo_surface_t*>(arg));
if (!obj)
return false;
......@@ -299,7 +299,7 @@ surface_from_g_argument(JSContext *context,
static bool surface_release_argument(JSContext*, GITransfer transfer,
GIArgument* arg) {
if (transfer != GI_TRANSFER_NOTHING)
cairo_surface_destroy(static_cast<cairo_surface_t*>(arg->v_pointer));
cairo_surface_destroy(gjs_arg_get<cairo_surface_t*>(arg));
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment