[gnode] value: Add support for NULL values
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnode] value: Add support for NULL values
- Date: Wed, 15 Oct 2014 01:12:45 +0000 (UTC)
commit b5d0a7faa6d53559a475c637d3c94fe561b057a0
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Tue Oct 14 10:19:37 2014 -0700
value: Add support for NULL values
src/function.cc | 3 ++-
src/value.cc | 13 +++++++++++--
src/value.h | 2 +-
3 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/src/function.cc b/src/function.cc
index 6e7f1b5..cfd403e 100644
--- a/src/function.cc
+++ b/src/function.cc
@@ -62,8 +62,9 @@ static Handle<Value> FunctionInvoker(const Arguments &args) {
for (int i = 0; i < n_in_args; i++) {
GIArgInfo *arg_info = g_callable_info_get_arg ((GICallableInfo *) info, i);
GITypeInfo type_info;
+ bool may_be_null = g_arg_info_may_be_null (arg_info);
g_arg_info_load_type (arg_info, &type_info);
- V8ToGIArgument (&type_info, &in_args[i], args[i]);
+ V8ToGIArgument (&type_info, &in_args[i], args[i], may_be_null);
g_base_info_unref ((GIBaseInfo *) arg_info);
}
diff --git a/src/value.cc b/src/value.cc
index 715a0fe..5af3931 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -109,7 +109,7 @@ static GArray * V8ToGArray(GITypeInfo *type_info, v8::Handle<v8::Value> value) {
v8::Local<v8::Value> value = array->Get (i);
GIArgument arg;
- V8ToGIArgument (elem_info, &arg, value);
+ V8ToGIArgument (elem_info, &arg, value, false);
g_array_append_val (garray, arg);
}
@@ -117,9 +117,18 @@ static GArray * V8ToGArray(GITypeInfo *type_info, v8::Handle<v8::Value> value) {
return garray;
}
-void V8ToGIArgument(GITypeInfo *type_info, GIArgument *arg, v8::Handle<v8::Value> value) {
+void V8ToGIArgument(GITypeInfo *type_info, GIArgument *arg, v8::Handle<v8::Value> value, bool may_be_null) {
GITypeTag type_tag = g_type_info_get_tag (type_info);
+ if (value->IsNull ()) {
+ if (may_be_null)
+ arg->v_pointer = NULL;
+ else
+ ThrowException (v8::Exception::TypeError (v8::String::New ("Argument may not be null.")));
+
+ return;
+ }
+
switch (type_tag) {
case GI_TYPE_TAG_VOID:
arg->v_pointer = NULL;
diff --git a/src/value.h b/src/value.h
index 4fd2198..48dcbb3 100644
--- a/src/value.h
+++ b/src/value.h
@@ -28,7 +28,7 @@
namespace GNodeJS {
v8::Handle<v8::Value> GIArgumentToV8(GITypeInfo *type_info, GIArgument *argument);
-void V8ToGIArgument(GITypeInfo *type_info, GIArgument *argument, v8::Handle<v8::Value> value);
+void V8ToGIArgument(GITypeInfo *type_info, GIArgument *argument, v8::Handle<v8::Value> value, bool
may_be_null);
void FreeGIArgument(GITypeInfo *type_info, GIArgument *argument);
void V8ToGValue(GValue *gvalue, v8::Handle<v8::Value> value);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]