Exemplo n.º 1
0
static SeedValue
seed_cairo_surface_create_similar (SeedContext ctx,
				   SeedObject function,
				   SeedObject this_object,
				   gsize argument_count,
				   const SeedValue arguments[],
				   SeedException *exception)
{
  gint width, height;
  cairo_surface_t *surface, *ret;
  cairo_content_t content;
  CHECK_THIS();
  if (argument_count != 3)
    {
      EXPECTED_EXCEPTION("create_similar", "3 arguments");
    }

  surface = seed_object_to_cairo_surface (ctx, this_object, exception);
  if (!surface)
    return seed_make_undefined (ctx);
  content = seed_value_to_long (ctx, arguments[0], exception);
  width = seed_value_to_int (ctx, arguments[1], exception);
  height = seed_value_to_int (ctx, arguments[2], exception);

  ret = cairo_surface_create_similar (surface, content, width, height);
  return seed_object_from_cairo_surface (ctx, ret);
}
Exemplo n.º 2
0
static SeedValue
seed_cairo_surface_mark_dirty_rectangle(SeedContext ctx,
					SeedObject function,
					SeedObject this_object,
					gsize argument_count,
					const SeedValue arguments[],
					SeedException *exception)
{
  cairo_surface_t *surf;
  guint x, y, width, height;
  CHECK_THIS();
  if (argument_count != 4)
    {
      EXPECTED_EXCEPTION("mark_dirty_rectangle", "4 arguments");
    }
  surf = seed_object_to_cairo_surface (ctx, this_object, exception);
  x = seed_value_to_int (ctx, arguments[0], exception);
  y = seed_value_to_int (ctx, arguments[1], exception);
  width = seed_value_to_int (ctx, arguments[2], exception);
  height = seed_value_to_int (ctx, arguments[3], exception);

  cairo_surface_mark_dirty_rectangle (surf, x, y, width, height);

  return seed_make_undefined (ctx);
}
Exemplo n.º 3
0
static SeedValue
seed_gettext_dcngettext (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException * exception)
{
	gchar * domainname, * msgid, * msgid_plural;
	guint n;
	gint category;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.dcngettext", 5);

	domainname = seed_value_to_string (ctx, args[0], exception);
	msgid = seed_value_to_string (ctx, args[1], exception);
	msgid_plural = seed_value_to_string (ctx, args[2], exception);
	n = seed_value_to_uint (ctx, args[3], exception);
	category = seed_value_to_int (ctx, args[4], exception);

	ret = seed_value_from_string (ctx,
	                              dcngettext(domainname, msgid, msgid_plural, n, category),
	                              exception);
	g_free(domainname);
	g_free(msgid);
	g_free(msgid_plural);

	return ret;
}
Exemplo n.º 4
0
SeedValue seed_mpfr_setsign (SeedContext ctx,
                             SeedObject function,
                             SeedObject this_object,
                             gsize argument_count,
                             const SeedValue args[],
                             SeedException *exception)
{
    mpfr_ptr rop, op;
    gint ret;
    gint s;
    mpfr_rnd_t rnd;

    CHECK_ARG_COUNT("mpfr.signbit", 3);

    rop = seed_object_get_private(this_object);
    s = seed_value_to_int(ctx, args[1], exception);
    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);

    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
    {
        op = seed_object_get_private(args[0]);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.setsign", "mpfr_t");
    }

    ret = mpfr_setsign(rop, op, s, rnd);

    return seed_value_from_int(ctx, ret, exception);
}
Exemplo n.º 5
0
static gboolean
seed_ffi_build_signature (SeedContext ctx,
			  seed_ffi_function_priv *priv,
			  SeedObject sig,
			  SeedException *exception)
{
  SeedObject arguments;
  SeedValue ret_type_ref, length_ref;
  guint length, i;
  
  arguments = seed_object_get_property (ctx, sig, "arguments");
  ret_type_ref = seed_object_get_property (ctx, sig, "returns");
  
  if (!seed_value_is_object (ctx, arguments))
    {
      seed_make_exception (ctx, exception, "FFIError", 
			   "Signature arguments member must be an array describing argument types");
      return FALSE;
    }
  length_ref = seed_object_get_property (ctx, arguments, "length");
  
  length = seed_value_to_uint (ctx, length_ref, exception);
  priv->n_args = length;
  priv->args = g_slice_alloc (length * sizeof (GType));
  
  for (i = 0; i < length; i++)
    {
      SeedValue type = seed_object_get_property_at_index (ctx, arguments, 
							  i, exception);
      priv->args[i] = seed_value_to_int (ctx, type, exception);
    }
  priv->ret_val = seed_value_to_int (ctx, ret_type_ref, exception);
  
  priv->signature_obj = sig;
  seed_value_protect (ctx, sig);

  return TRUE;
}
Exemplo n.º 6
0
SeedValue ghtml_webview_js_quit (SeedContext ctx, SeedObject function, SeedObject thisObject, gsize argumentCount, const SeedValue arguments[], SeedException * exception) {

	if (argumentCount == 1) {

		ghtml_die(seed_value_to_int(ctx, arguments[0], exception));
		return NULL;

	} else if (argumentCount > 1) {

		seed_make_exception( ctx, exception, GHTML_JS_INVALID_PARAMS,
			"quit expected 1 argument, got %zd", argumentCount
		);
		return NULL;

	}

	ghtml_die(EXIT_SUCCESS);

}
Exemplo n.º 7
0
static SeedValue
seed_gettext_setlocale (SeedContext ctx,
                        SeedObject function,
                        SeedObject this_object,
                        gsize argument_count,
                        const SeedValue args[],
                        SeedException * exception)
{
	gchar * locale;
	gint category;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.setlocale", 2);

	category = seed_value_to_int (ctx, args[0], exception);
	locale = seed_value_to_string (ctx, args[1], exception);

	ret = seed_value_from_string (ctx,
	                              setlocale(category, locale),
	                              exception);
	g_free(locale);

	return ret;
}
Exemplo n.º 8
0
static ffi_type *
gtype_to_ffi_type (SeedContext ctx, 
		   SeedValue value,
		   GType otype,
		   GArgument *garg,
		   gpointer *arg,
		   SeedException *exception)
{
  ffi_type *return_type;
  GType type = g_type_fundamental (otype);
  g_assert (type != G_TYPE_INVALID);

  switch (type)
    {
    case G_TYPE_BOOLEAN:
    case G_TYPE_CHAR:
    case G_TYPE_INT:
      return_type = &ffi_type_sint;
      garg->v_int = seed_value_to_int (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_UCHAR:
    case G_TYPE_UINT:
      return_type = &ffi_type_uint;
      garg->v_uint = seed_value_to_uint (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_STRING:
      return_type = &ffi_type_pointer;
      garg->v_pointer = seed_value_to_string (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_OBJECT:
      //    case G_TYPE_BOXED:
    case G_TYPE_POINTER:
      return_type = &ffi_type_pointer;
      garg->v_pointer = seed_pointer_get_pointer (ctx, value);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_FLOAT:
      return_type = &ffi_type_float;
      garg->v_float = seed_value_to_float (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_DOUBLE:
      return_type = &ffi_type_double;
      garg->v_double = seed_value_to_double (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_LONG:
      return_type = &ffi_type_slong;
      garg->v_uint = seed_value_to_uint (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_ULONG:
      return_type = &ffi_type_ulong;
      garg->v_ulong = seed_value_to_ulong (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_INT64:
      return_type = &ffi_type_sint64;
      garg->v_int64 = seed_value_to_int64 (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_UINT64:
      return_type = &ffi_type_uint64;
      garg->v_uint64 = seed_value_to_uint64 (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    default:
      g_warning ("Unsupported fundamental in type: %s", g_type_name (type));
      return_type = &ffi_type_pointer;
      garg->v_pointer = NULL;
      *arg = (garg->v_pointer);
      break;
    }
  return return_type;
}
Exemplo n.º 9
0
void basic_types(TestSimpleFixture * fixture, gconstpointer _data)
{
	// bool to/from JS equality

	gboolean bool_test_in = TRUE;
	SeedValue *bool_test = seed_value_from_boolean(fixture->context,
												   bool_test_in, NULL);
	gboolean bool_test_out = seed_value_to_boolean(fixture->context,
												   bool_test, NULL);

	g_assert(bool_test_in == bool_test_out);

	// uint to/from JS equality

	guint uint_test_in = 2946623;
	SeedValue *uint_test = seed_value_from_uint(fixture->context,
												uint_test_in, NULL);
	guint uint_test_out = seed_value_to_uint(fixture->context,
											 uint_test, NULL);

	g_assert(uint_test_in == uint_test_out);

	// int to/from JS equality

	gint int_test_in = -54374;
	SeedValue *int_test = seed_value_from_int(fixture->context,
											  int_test_in, NULL);
	gint int_test_out = seed_value_to_int(fixture->context,
										  int_test, NULL);

	g_assert(int_test_in == int_test_out);

	// char to/from JS equality

	gchar char_test_in = -126;
	SeedValue *char_test = seed_value_from_char(fixture->context,
												char_test_in, NULL);
	gchar char_test_out = seed_value_to_char(fixture->context,
											 char_test, NULL);

	g_assert(char_test_in == char_test_out);

	// uchar to/from JS equality

	guchar uchar_test_in = 250;
	SeedValue *uchar_test = seed_value_from_uchar(fixture->context,
												  uchar_test_in, NULL);
	guchar uchar_test_out = seed_value_to_uchar(fixture->context,
												uchar_test, NULL);

	g_assert(uchar_test_in == uchar_test_out);

	// long to/from JS equality

	glong long_test_in = -454250;
	SeedValue *long_test = seed_value_from_long(fixture->context,
												long_test_in, NULL);
	glong long_test_out = seed_value_to_long(fixture->context,
											 long_test, NULL);

	g_assert(long_test_in == long_test_out);

	// ulong to/from JS equality

	gulong ulong_test_in = 250;
	SeedValue *ulong_test = seed_value_from_ulong(fixture->context,
												  ulong_test_in, NULL);
	gulong ulong_test_out = seed_value_to_ulong(fixture->context,
												ulong_test, NULL);

	g_assert(ulong_test_in == ulong_test_out);

	// int64 to/from JS equality

	gint64 int64_test_in = -54374;
	SeedValue *int64_test = seed_value_from_int64(fixture->context,
												  int64_test_in, NULL);
	gint64 int64_test_out = seed_value_to_int64(fixture->context,
												int64_test, NULL);

	g_assert(int64_test_in == int64_test_out);

	// uint64 to/from JS equality

	guint64 uint64_test_in = 2946623;
	SeedValue *uint64_test = seed_value_from_uint64(fixture->context,
													uint64_test_in, NULL);
	guint64 uint64_test_out = seed_value_to_uint64(fixture->context,
												   uint64_test, NULL);

	g_assert(uint64_test_in == uint64_test_out);

	// float to/from JS equality

	gfloat float_test_in = 1.618;
	SeedValue *float_test = seed_value_from_float(fixture->context,
												  float_test_in, NULL);
	gfloat float_test_out = seed_value_to_float(fixture->context,
												float_test, NULL);

	g_assert(float_test_in == float_test_out);

	// double to/from JS equality

	gdouble double_test_in = 1.6134857638;
	SeedValue *double_test = seed_value_from_double(fixture->context,
													double_test_in, NULL);
	gdouble double_test_out = seed_value_to_double(fixture->context,
												   double_test, NULL);

	g_assert(double_test_in == double_test_out);

	// string to/from JS equality

	gchar *string_test_in = "Hello, world!";
	SeedValue *string_test = seed_value_from_string(fixture->context,
													string_test_in, NULL);
	gchar *string_test_out = seed_value_to_string(fixture->context,
												  string_test, NULL);

	g_assert(strncmp(string_test_in, string_test_out,
					 strlen(string_test_in)) == 0);

	// filename to/from JS equality

	gchar *filename_test_in = "/bin";
	SeedValue *filename_test = seed_value_from_filename(fixture->context,
														filename_test_in,
														NULL);
	gchar *filename_test_out = seed_value_to_filename(fixture->context,
													  filename_test, NULL);

	g_assert(strncmp(filename_test_in, filename_test_out,
					 strlen(filename_test_in)) == 0);
	SeedValue si[2];
	si[0] = seed_value_from_string (fixture->context, "Hi", NULL);
	si[1] = seed_value_from_int (fixture->context, 1, NULL);
	gint ni;
	gchar *ns;

	seed_value_to_format (fixture->context, "si", si, NULL, &ns, &ni, NULL);
	g_assert (ni == 1);
	g_assert (!strcmp(ns, "Hi"));


}
Exemplo n.º 10
0
static SeedValue
async_call_callback(SeedContext ctx,
		    SeedObject function,
		    SeedObject this_object,
		    gsize argument_count,
		    const SeedValue arguments[],
		    SeedException *exception)
{
    DBusConnection *connection;
    DBusBusType which_bus;
    DBusMessage *reply;
    const char *sender;
    dbus_uint32_t serial;
    SeedValue prop_value, retval;
    const char *signature;
    gboolean thrown;

    retval = seed_make_undefined (ctx);
    reply = NULL;
    thrown = FALSE;

    prop_value = seed_object_get_property (ctx, function, "_dbusSender");
    sender = seed_value_to_string (ctx, prop_value, exception);
    if (!sender)
      return FALSE;

    prop_value = seed_object_get_property(ctx,
                                     function,
					  "_dbusSerial");


    serial = seed_value_to_uint (ctx, prop_value, exception);
    prop_value = seed_object_get_property(ctx,
					  function,
					  "_dbusBusType");

    which_bus = seed_value_to_int(ctx, prop_value, exception);

    /* From now we have enough information to
     * send the exception back to the callee so we'll do so
     */
    prop_value = seed_object_get_property(ctx,
					  function,
					  "_dbusOutSignature");

    signature = seed_value_to_string (ctx, prop_value, exception);
    if (!signature)
        return FALSE;

    if (argument_count != 1) {
      seed_make_exception(ctx, exception, "ArgumentError",
			  "The callback to async DBus calls takes one argument, "
			  "the return value or array of return values");
        thrown = TRUE;
        goto out;
    }

    reply = build_reply_from_jsval(ctx,
                                   signature,
                                   sender,
                                   serial,
                                   arguments[0],
				   exception);

out:
    if (!reply && thrown)
      {
	if (!dbus_reply_from_exception_and_sender(ctx, sender, serial, &reply, exception))
	  g_warning("dbus method invocation failed but no exception was set?");
      }

    if (reply)
      {
        big_dbus_add_bus_weakref(which_bus, &connection);
        if (!connection)
	  {
            seed_make_exception(ctx, exception, "DBusError",
				"We were disconnected from the bus before the callback "
				"to some async remote call was called");
            dbus_message_unref(reply);
            big_dbus_remove_bus_weakref(which_bus, &connection);
            return FALSE;
	  }
        dbus_connection_send(connection, reply, NULL);
        big_dbus_remove_bus_weakref(which_bus, &connection);
        dbus_message_unref(reply);
    }

    return retval;
}