node-gtk 0.14.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/gobject.cc CHANGED
@@ -4,13 +4,11 @@
4
4
  #include "boxed.h"
5
5
  #include "callback.h"
6
6
  #include "closure.h"
7
- #include "debug.h"
8
7
  #include "error.h"
9
8
  #include "function.h"
10
9
  #include "gi.h"
11
10
  #include "gobject.h"
12
11
  #include "macros.h"
13
- #include "type.h"
14
12
  #include "util.h"
15
13
  #include "value.h"
16
14
 
@@ -21,7 +19,6 @@ using v8::Function;
21
19
  using v8::FunctionTemplate;
22
20
  using v8::Local;
23
21
  using v8::MaybeLocal;
24
- using v8::Number;
25
22
  using v8::Object;
26
23
  using v8::String;
27
24
  using Nan::New;
@@ -62,12 +59,18 @@ static GObject* CreateGObjectFromObject(GType gtype, Local<Value> object) {
62
59
 
63
60
  for (int i = 0; i < n_properties; i++) {
64
61
  Local<String> name = TO_STRING (Nan::Get(properties, i).ToLocalChecked());
65
- const char *name_string = g_strdup (*Nan::Utf8String(name));
62
+ // Accept camelCase property names (e.g. iconName) in addition to
63
+ // dashed/underscored ones; GObject canonicalizes '_' to '-' but not
64
+ // camelCase, so convert here (#320). The original spelling is kept so
65
+ // an unknown name is reported as the user wrote it.
66
+ Nan::Utf8String name_original (name);
67
+ char *name_string = Util::ToDashed (*name_original);
66
68
  Local<Value> value = Nan::Get(property_hash, name).ToLocalChecked();
67
69
 
68
70
  auto value_spec = g_object_class_find_property (G_OBJECT_CLASS (klass), name_string);
69
71
  if (value_spec == NULL) {
70
- Throw::InvalidPropertyName(name_string);
72
+ Throw::InvalidPropertyName(*name_original);
73
+ g_free(name_string);
71
74
  goto out;
72
75
  }
73
76
 
@@ -75,7 +78,7 @@ static GObject* CreateGObjectFromObject(GType gtype, Local<Value> object) {
75
78
 
76
79
  g_value_init(&values[index], value_spec->value_type);
77
80
 
78
- if (!V8ToGValue(&values[index], value, true)) {
81
+ if (!V8ToGValue(&values[index], value, kCopy)) {
79
82
  // V8ToGValue throws the error
80
83
  goto out;
81
84
  }
@@ -102,7 +105,7 @@ static void ToggleNotify(gpointer user_data, GObject *gobject, gboolean toggle_d
102
105
 
103
106
  g_assert (data != NULL);
104
107
 
105
- auto *persistent = (Persistent<Object> *) data;
108
+ auto *persistent = (Nan::Persistent<Object> *) data;
106
109
 
107
110
  if (toggle_down) {
108
111
  /* We're dropping from 2 refs to 1 ref. We are the last holder. Make
@@ -120,7 +123,7 @@ static void AssociateGObject(Local<Object> object, GObject *gobject, GType gtype
120
123
 
121
124
  SET_OBJECT_GTYPE(object, gtype);
122
125
 
123
- Persistent<Object> *persistent = new Persistent<Object>(object);
126
+ auto *persistent = new Nan::Persistent<Object>(object);
124
127
  g_object_set_qdata (gobject, GNodeJS::object_quark(), persistent);
125
128
 
126
129
  // Because we can't sink floating ref and add toggle ref at the same time,
@@ -184,7 +187,7 @@ static void GObjectDestroyed(const Nan::WeakCallbackInfo<GObject> &data) {
184
187
  GObject *gobject = data.GetParameter ();
185
188
 
186
189
  void *type_data = g_object_get_qdata (gobject, GNodeJS::object_quark());
187
- Persistent<Object> *persistent = (Persistent<Object> *) type_data;
190
+ auto *persistent = (Nan::Persistent<Object> *) type_data;
188
191
  delete persistent;
189
192
 
190
193
  /* We're destroying the wrapper object, so make sure to clear out
@@ -200,9 +203,9 @@ static void GObjectClassDestroyed(const Nan::WeakCallbackInfo<GType> &info) {
200
203
 
201
204
  DestroyVFuncs(gtype);
202
205
 
203
- auto persistentTpl = (Persistent<FunctionTemplate> *)
206
+ auto persistentTpl = (Nan::Persistent<FunctionTemplate> *)
204
207
  g_type_get_qdata (gtype, GNodeJS::template_quark());
205
- auto persistentFn = (Persistent<Function> *)
208
+ auto persistentFn = (Nan::Persistent<Function> *)
206
209
  g_type_get_qdata (gtype, GNodeJS::function_quark());
207
210
  delete persistentTpl;
208
211
  delete persistentFn;
@@ -212,8 +215,18 @@ static void GObjectClassDestroyed(const Nan::WeakCallbackInfo<GType> &info) {
212
215
  g_free(gtypePtr);
213
216
  }
214
217
 
215
- static void GObjectFallbackPropertyGetter(Local<v8::Name> property,
216
- const v8::PropertyCallbackInfo<Value>& info) {
218
+ #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
219
+ (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
220
+ #define PROPERTY_CALLBACK_RETURN_TYPE v8::Intercepted
221
+ #define PROPERTY_CALLBACK_INFO_TYPE v8::PropertyCallbackInfo<void>
222
+ #else
223
+ #define PROPERTY_CALLBACK_RETURN_TYPE void
224
+ #define PROPERTY_CALLBACK_INFO_TYPE v8::PropertyCallbackInfo<Value>
225
+ #endif
226
+
227
+ static PROPERTY_CALLBACK_RETURN_TYPE
228
+ GObjectFallbackPropertyGetter(Local<v8::Name> property,
229
+ const v8::PropertyCallbackInfo<Value>& info) {
217
230
  auto self = info.Holder();
218
231
  GObject *gobject = GObjectFromWrapper (self);
219
232
 
@@ -225,20 +238,25 @@ static void GObjectFallbackPropertyGetter(Local<v8::Name> property,
225
238
  if (strstr(prop_name_camel, "-")) {
226
239
  // Has dash, not a camel-case property name.
227
240
  RETURN(Nan::Undefined());
228
- return;
241
+ return Nan::Intercepted::Yes();
229
242
  }
230
243
 
231
244
  char *prop_name = Util::ToDashed(prop_name_camel);
232
245
 
233
246
  auto value = GetGObjectProperty(gobject, prop_name);
234
- if (!value.IsEmpty())
247
+ if (!value.IsEmpty()) {
235
248
  RETURN(value.ToLocalChecked());
249
+ g_free(prop_name);
250
+ return Nan::Intercepted::Yes();
251
+ }
236
252
 
237
253
  g_free(prop_name);
254
+ return Nan::Intercepted::No();
238
255
  }
239
256
 
240
- static void GObjectFallbackPropertySetter (Local<v8::Name> property, Local<Value> value,
241
- const v8::PropertyCallbackInfo<Value>& info) {
257
+ static PROPERTY_CALLBACK_RETURN_TYPE
258
+ GObjectFallbackPropertySetter(Local<v8::Name> property, Local<Value> value,
259
+ const PROPERTY_CALLBACK_INFO_TYPE& info) {
242
260
  auto self = info.Holder();
243
261
  GObject *gobject = GNodeJS::GObjectFromWrapper (self);
244
262
 
@@ -247,7 +265,7 @@ static void GObjectFallbackPropertySetter (Local<v8::Name> property, Local<Value
247
265
 
248
266
  if (strstr(prop_name_camel, "-")) {
249
267
  // Has dash, not a camel-case property name.
250
- return;
268
+ return Nan::Intercepted::No();
251
269
  }
252
270
 
253
271
  char *prop_name = Util::ToDashed(prop_name_camel);
@@ -255,20 +273,22 @@ static void GObjectFallbackPropertySetter (Local<v8::Name> property, Local<Value
255
273
  if (gobject == NULL) {
256
274
  WARN("Can't set \"%s\" on null GObject", prop_name);
257
275
  g_free(prop_name);
258
- return;
276
+ return Nan::Intercepted::No();
259
277
  }
260
278
 
261
279
  auto setResult = SetGObjectProperty(gobject, prop_name, value);
262
280
  if (setResult.IsEmpty()) {
263
281
  // Non-existent property. Let node consider the set not intercepted
264
282
  // by not setting return value;
283
+ g_free(prop_name);
284
+ return Nan::Intercepted::No();
265
285
  } else {
266
286
  // Property exists. Whether we can convert the value and set the
267
287
  // property or not, consider the set intercepted.
268
288
  RETURN(value);
289
+ g_free(prop_name);
290
+ return Nan::Intercepted::Yes();
269
291
  }
270
-
271
- g_free(prop_name);
272
292
  }
273
293
 
274
294
  static GISignalInfo* FindSignalInfo(GIObjectInfo *info, const char *signal_detail) {
@@ -319,8 +339,7 @@ static void StoreVFunc(GType gtype, Callback *callback) {
319
339
  static void DestroyVFuncs(GType gtype) {
320
340
  /* Destroy vfunc list, if any */
321
341
  GSList *list = (GSList *) g_type_get_qdata (gtype, GNodeJS::vfuncs_quark());
322
- GSList *item = list;
323
- while ((item = g_slist_next (item)) != NULL) {
342
+ for (GSList *item = list; item != NULL; item = item->next) {
324
343
  auto callback = (Callback *) item->data;
325
344
  delete callback;
326
345
  }
@@ -463,9 +482,9 @@ NAN_METHOD(SignalEmit) {
463
482
  g_value_init(gvalue, signal_query.param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE);
464
483
 
465
484
  if ((signal_query.param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE) != 0)
466
- failed = !V8ToGValue(gvalue, info[i + 1], false); // no-copy
485
+ failed = !V8ToGValue(gvalue, info[i + 1], kNone); // no-copy
467
486
  else
468
- failed = !V8ToGValue(gvalue, info[i + 1], true); // copy
487
+ failed = !V8ToGValue(gvalue, info[i + 1], kCopy); // copy
469
488
 
470
489
  if (failed)
471
490
  break;
@@ -551,9 +570,8 @@ static MaybeLocal<FunctionTemplate> NewClassTemplate (GType gtype) {
551
570
  // Set the fallback accessor to allow non-introspected property.
552
571
  // Nan::SetNamedPropertyHandler() does not support flags. Thus, using
553
572
  // V8 interface directly.
554
- v8::NamedPropertyHandlerConfiguration config;
555
- config.getter = GObjectFallbackPropertyGetter;
556
- config.setter = GObjectFallbackPropertySetter;
573
+ v8::NamedPropertyHandlerConfiguration config(GObjectFallbackPropertyGetter,
574
+ GObjectFallbackPropertySetter);
557
575
  config.flags = static_cast<v8::PropertyHandlerFlags>(
558
576
  static_cast<int>(v8::PropertyHandlerFlags::kNonMasking) |
559
577
  static_cast<int>(v8::PropertyHandlerFlags::kOnlyInterceptStrings));
@@ -566,7 +584,7 @@ static MaybeLocal<FunctionTemplate> GetClassTemplate(GType gtype) {
566
584
  void *data = g_type_get_qdata (gtype, GNodeJS::template_quark());
567
585
 
568
586
  if (data) {
569
- auto *persistent = (Persistent<FunctionTemplate> *) data;
587
+ auto *persistent = (Nan::Persistent<FunctionTemplate> *) data;
570
588
  auto tpl = New<FunctionTemplate> (*persistent);
571
589
  return tpl;
572
590
  }
@@ -577,8 +595,8 @@ static MaybeLocal<FunctionTemplate> GetClassTemplate(GType gtype) {
577
595
 
578
596
  auto tpl = maybeTpl.ToLocalChecked();
579
597
  auto fn = Nan::GetFunction (tpl).ToLocalChecked();
580
- auto persistentTpl = new Persistent<FunctionTemplate>(tpl);
581
- auto persistentFn = new Persistent<Function>(fn);
598
+ auto persistentTpl = new Nan::Persistent<FunctionTemplate>(tpl);
599
+ auto persistentFn = new Nan::Persistent<Function>(fn);
582
600
 
583
601
  GType *gtypePtr = g_new(GType, 1);
584
602
  *gtypePtr = gtype;
@@ -596,7 +614,7 @@ static MaybeLocal<Function> GetClass(GType gtype) {
596
614
  void *data = g_type_get_qdata (gtype, GNodeJS::function_quark());
597
615
 
598
616
  if (data) {
599
- auto persistent = (Persistent<Function> *) data;
617
+ auto persistent = (Nan::Persistent<Function> *) data;
600
618
  auto fn = New<Function> (*persistent);
601
619
  return MaybeLocal<Function> (fn);
602
620
  }
@@ -611,7 +629,7 @@ static MaybeLocal<Function> GetClass(GType gtype) {
611
629
  data = g_type_get_qdata (gtype, GNodeJS::function_quark());
612
630
 
613
631
  if (data) {
614
- auto persistent = (Persistent<Function> *) data;
632
+ auto persistent = (Nan::Persistent<Function> *) data;
615
633
  auto fn = New<Function> (*persistent);
616
634
  return MaybeLocal<Function> (fn);
617
635
  }
@@ -640,7 +658,7 @@ Local<Value> WrapperFromGObject(GObject *gobject) {
640
658
 
641
659
  if (data) {
642
660
  /* Easy case: we already have an object. */
643
- auto *persistent = (Persistent<Object> *) data;
661
+ auto *persistent = (Nan::Persistent<Object> *) data;
644
662
  auto obj = New<Object> (*persistent);
645
663
  return obj;
646
664
  }
@@ -680,7 +698,7 @@ MaybeLocal<Value> GetGObjectProperty(GObject * gobject, const char *prop_name) {
680
698
  g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
681
699
  g_object_get_property (gobject, prop_name, &value);
682
700
 
683
- auto ret = GNodeJS::GValueToV8(&value, true);
701
+ auto ret = GNodeJS::GValueToV8(&value, kCopy);
684
702
 
685
703
  g_value_unset(&value);
686
704
 
@@ -699,7 +717,7 @@ MaybeLocal<v8::Boolean> SetGObjectProperty(GObject * gobject, const char *prop_n
699
717
  GValue gvalue = G_VALUE_INIT;
700
718
  g_value_init(&gvalue, G_PARAM_SPEC_VALUE_TYPE (pspec));
701
719
 
702
- if (GNodeJS::V8ToGValue (&gvalue, value, true)) {
720
+ if (GNodeJS::V8ToGValue (&gvalue, value, kCopy)) {
703
721
  g_object_set_property (gobject, prop_name, &gvalue);
704
722
  ret = Nan::True();
705
723
  } else {
package/src/loop.cc CHANGED
@@ -73,7 +73,7 @@ static gboolean loop_source_dispatch (GSource *base, GSourceFunc callback, gpoin
73
73
  v8::Context::Scope context_scope(context);
74
74
 
75
75
  // Perform microtask checkpoint after running JavaScript.
76
- MicrotasksScope micro_scope(isolate, MicrotasksScope::kRunMicrotasks);
76
+ MicrotasksScope micro_scope(isolate, NULL, MicrotasksScope::kRunMicrotasks);
77
77
 
78
78
  // Deal with uv events.
79
79
  uv_run (source->loop, UV_RUN_NOWAIT);
@@ -103,6 +103,7 @@ NAN_INDEX_GETTER(Glyph::IndexGetter) {
103
103
  Nan::Set (returnValue, UTF8("x"), Nan::New<Number> (glyph->x));
104
104
  Nan::Set (returnValue, UTF8("y"), Nan::New<Number> (glyph->y));
105
105
  RETURN(returnValue);
106
+ return Nan::Intercepted::Yes();
106
107
  }
107
108
 
108
109
 
@@ -110,6 +110,7 @@ NAN_INDEX_GETTER(TextCluster::IndexGetter) {
110
110
  Nan::Set (returnValue, UTF8("num_bytes"), Nan::New<Number> (text_cluster->num_bytes));
111
111
  Nan::Set (returnValue, UTF8("num_glyphs"), Nan::New<Number> (text_cluster->num_glyphs));
112
112
  RETURN(returnValue);
113
+ return Nan::Intercepted::Yes();
113
114
  }
114
115
 
115
116
 
@@ -65,8 +65,8 @@ NAN_METHOD(ConvertGValue) {
65
65
  return;
66
66
  }
67
67
  void *ptr = obj->GetAlignedPointerFromInternalField (0);
68
- bool mustCopy = true;
69
- RETURN(GValueToV8(reinterpret_cast<GValue *>(ptr), mustCopy));
68
+ ResourceOwnership ownership = kCopy;
69
+ RETURN(GValueToV8(reinterpret_cast<GValue *>(ptr), ownership));
70
70
  }
71
71
 
72
72
  NAN_METHOD(GetMemoryContent) {
package/src/type.cc CHANGED
@@ -15,11 +15,12 @@ char *GetInfoName (GIBaseInfo* info) {
15
15
 
16
16
  char* name = g_strdup (info_name);
17
17
 
18
- GIBaseInfo *parent;
19
- while ((parent = g_base_info_get_container (info)) != NULL) {
18
+ GIBaseInfo *parent = g_base_info_get_container (info);
19
+ while (parent != NULL) {
20
20
  char *new_name = g_strconcat (g_base_info_get_name(parent), ".", name, NULL);
21
21
  g_free (name);
22
22
  name = new_name;
23
+ parent = g_base_info_get_container (parent);
23
24
  }
24
25
 
25
26
  char *new_name = g_strconcat (g_base_info_get_namespace(info), ".", name, NULL);