node-gtk 0.14.0 → 1.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/README.md +11 -12
- package/lib/binding/node-v127-linux-x64/node_gtk.node +0 -0
- package/package.json +5 -5
- package/scripts/ci.sh +5 -3
- package/src/boxed.cc +14 -14
- package/src/boxed.h +2 -1
- package/src/callback.cc +2 -2
- package/src/closure.cc +12 -8
- package/src/debug.cc +4 -3
- package/src/function.cc +32 -33
- package/src/function.h +3 -3
- package/src/gi.cc +3 -3
- package/src/gobject.cc +45 -32
- package/src/loop.cc +1 -1
- package/src/modules/cairo/glyph.cc +1 -0
- package/src/modules/cairo/text-cluster.cc +1 -0
- package/src/modules/system.cc +2 -2
- package/src/value.cc +13 -13
- package/src/value.h +11 -5
package/README.md
CHANGED
|
@@ -19,8 +19,8 @@ Node-Gtk is a [gobject-introspection](https://gi.readthedocs.io/en/latest) libra
|
|
|
19
19
|
use any introspected library, such as Gtk+, usable. It is similar in essence to [GJS](https://wiki.gnome.org/action/show/Projects/Gjs) or [PyGObject](https://pygobject.readthedocs.io). Please note this project is currently in a _beta_ state and is being developed. Any contributors willing to help
|
|
20
20
|
will be welcomed.
|
|
21
21
|
|
|
22
|
-
Supported Node.js versions: **
|
|
23
|
-
Pre-built binaries available for: **Linux**, **macOS**
|
|
22
|
+
Supported Node.js versions: **20**, **22**, **24** (other versions may work but are untested)<br>
|
|
23
|
+
Pre-built binaries available for: **Linux**, **macOS**
|
|
24
24
|
|
|
25
25
|
### Table of contents
|
|
26
26
|
|
|
@@ -120,9 +120,13 @@ Install basic dependencies:
|
|
|
120
120
|
sudo dnf install \
|
|
121
121
|
@development-tools \
|
|
122
122
|
nodejs \
|
|
123
|
+
nodejs-devel \
|
|
123
124
|
gobject-introspection \
|
|
125
|
+
gobject-introspection-devel \
|
|
124
126
|
gtk3 \
|
|
125
|
-
|
|
127
|
+
gtk3-devel \
|
|
128
|
+
cairo \
|
|
129
|
+
cairo-devel
|
|
126
130
|
```
|
|
127
131
|
|
|
128
132
|
After installing of packages, run `npm install node-gtk`.
|
|
@@ -252,17 +256,12 @@ Once installed, you can `./examples/browser.js google.com` or any other page, an
|
|
|
252
256
|
## Contributing
|
|
253
257
|
|
|
254
258
|
If you'd like to help, we'd be more than happy to have support. To setup your development environment, you can
|
|
255
|
-
run `npm run configure`. You can then build the project with `npm run build`.
|
|
259
|
+
run `npm run configure`. You can then build the project with `npm run build`. To generate the `compile_commands.json`
|
|
260
|
+
for LSP to work nicely, you can use [bear](https://github.com/rizsotto/Bear) as `bear -- npm run build`.
|
|
256
261
|
|
|
257
262
|
- https://developer.gnome.org/gi/stable/index.html
|
|
258
263
|
- https://v8docs.nodesource.com/
|
|
259
264
|
- https://github.com/nodejs/nan#api
|
|
260
265
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
### Contributors
|
|
264
|
-
|
|
265
|
-
- [magcius](https://github.com/magcius)
|
|
266
|
-
- [WebReflection](https://github.com/WebReflection)
|
|
267
|
-
- [romgrk](https://github.com/romgrk)
|
|
268
|
-
- [wotzlaff](https://github.com/wotzlaff)
|
|
266
|
+
There is a [Discord channel](https://discord.gg/r2VqPUV) but it receives little monitoring, use github issues or
|
|
267
|
+
discussions preferably.
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-gtk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "GNOME Gtk+ bindings for NodeJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"lodash.camelcase": "4.3.0",
|
|
37
37
|
"lodash.isequal": "4.5.0",
|
|
38
38
|
"lodash.snakecase": "^4.1.1",
|
|
39
|
-
"nan": "^2.
|
|
40
|
-
"node-gyp": "^
|
|
39
|
+
"nan": "^2.23.0",
|
|
40
|
+
"node-gyp": "^11.2.0",
|
|
41
41
|
"remove-trailing-spaces": "^1.0.7",
|
|
42
42
|
"unindent": "^2.0.0"
|
|
43
43
|
},
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"assert": "^1.5.0",
|
|
46
46
|
"aws-sdk": "^2.452.0",
|
|
47
47
|
"chalk": "^2.4.2",
|
|
48
|
-
"deasync": "^0.1.
|
|
48
|
+
"deasync": "^0.1.30",
|
|
49
49
|
"mocha": "^7.1.0",
|
|
50
50
|
"nid-parser": "0.0.5",
|
|
51
|
-
"node-pre-gyp-github": "^1.4.
|
|
51
|
+
"node-pre-gyp-github": "^1.4.5"
|
|
52
52
|
},
|
|
53
53
|
"files": [
|
|
54
54
|
"/lib",
|
package/scripts/ci.sh
CHANGED
|
@@ -41,13 +41,15 @@ function npm_test() {
|
|
|
41
41
|
echo "### Running tests ###";
|
|
42
42
|
|
|
43
43
|
if [[ $(uname -s) == 'Darwin' ]]; then
|
|
44
|
-
export GST_PLUGIN_SYSTEM_PATH
|
|
44
|
+
export GST_PLUGIN_SYSTEM_PATH=$(brew --prefix gstreamer)/lib/gstreamer-1.0;
|
|
45
45
|
npx mocha \
|
|
46
46
|
--skip=callback \
|
|
47
|
-
--skip=
|
|
47
|
+
--skip=union__fields \
|
|
48
48
|
tests/__run__.js
|
|
49
49
|
else
|
|
50
|
-
xvfb-run -a npm test --
|
|
50
|
+
xvfb-run -a npm test -- \
|
|
51
|
+
--skip=callback \
|
|
52
|
+
--skip=union__fields;
|
|
51
53
|
fi;
|
|
52
54
|
}
|
|
53
55
|
|
package/src/boxed.cc
CHANGED
|
@@ -174,11 +174,11 @@ static void BoxedConstructor(const Nan::FunctionCallbackInfo<Value> &info) {
|
|
|
174
174
|
|
|
175
175
|
if (info[0]->IsExternal ()) {
|
|
176
176
|
/* The External case. This is how WrapperFromBoxed is called. */
|
|
177
|
-
|
|
177
|
+
auto ownership = (ResourceOwnership) Nan::To<int32_t> (info[1]).ToChecked();
|
|
178
178
|
|
|
179
179
|
boxed = External::Cast(*info[0])->Value();
|
|
180
180
|
|
|
181
|
-
if (
|
|
181
|
+
if (ownership == kCopy) {
|
|
182
182
|
if (gtype != G_TYPE_NONE) {
|
|
183
183
|
boxed = g_boxed_copy (gtype, boxed);
|
|
184
184
|
}
|
|
@@ -192,7 +192,7 @@ static void BoxedConstructor(const Nan::FunctionCallbackInfo<Value> &info) {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
else {
|
|
195
|
-
owns_memory =
|
|
195
|
+
owns_memory = ownership == kTransfer;
|
|
196
196
|
}
|
|
197
197
|
} else {
|
|
198
198
|
/* User code calling `new Pango.AttrList()` */
|
|
@@ -286,12 +286,12 @@ static void BoxedDestroyed(const Nan::WeakCallbackInfo<Boxed> &info) {
|
|
|
286
286
|
delete box;
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
static void BoxedClassDestroyed(const
|
|
289
|
+
static void BoxedClassDestroyed(const Nan::WeakCallbackInfo<GIBaseInfo> &info) {
|
|
290
290
|
GIBaseInfo *gi_info = info.GetParameter ();
|
|
291
291
|
GType gtype = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) gi_info);
|
|
292
292
|
|
|
293
|
-
auto *persistent_template = (Persistent<FunctionTemplate> *) g_type_get_qdata (gtype, GNodeJS::template_quark());
|
|
294
|
-
auto *persistent_function = (Persistent<FunctionTemplate> *) g_type_get_qdata (gtype, GNodeJS::function_quark());
|
|
293
|
+
auto *persistent_template = (Nan::Persistent<FunctionTemplate> *) g_type_get_qdata (gtype, GNodeJS::template_quark());
|
|
294
|
+
auto *persistent_function = (Nan::Persistent<FunctionTemplate> *) g_type_get_qdata (gtype, GNodeJS::function_quark());
|
|
295
295
|
delete persistent_template;
|
|
296
296
|
delete persistent_function;
|
|
297
297
|
|
|
@@ -324,7 +324,7 @@ Local<FunctionTemplate> GetBoxedTemplate(GIBaseInfo *info, GType gtype) {
|
|
|
324
324
|
*/
|
|
325
325
|
|
|
326
326
|
if (data) {
|
|
327
|
-
auto *persistent = (Persistent<FunctionTemplate> *) data;
|
|
327
|
+
auto *persistent = (Nan::Persistent<FunctionTemplate> *) data;
|
|
328
328
|
auto tpl = Nan::New<FunctionTemplate> (*persistent);
|
|
329
329
|
return tpl;
|
|
330
330
|
}
|
|
@@ -353,7 +353,7 @@ Local<FunctionTemplate> GetBoxedTemplate(GIBaseInfo *info, GType gtype) {
|
|
|
353
353
|
if (gtype == G_TYPE_NONE)
|
|
354
354
|
return tpl;
|
|
355
355
|
|
|
356
|
-
auto *persistent = new Persistent<FunctionTemplate>(
|
|
356
|
+
auto *persistent = new Nan::Persistent<FunctionTemplate>(tpl);
|
|
357
357
|
persistent->SetWeak(
|
|
358
358
|
g_base_info_ref(info),
|
|
359
359
|
BoxedClassDestroyed,
|
|
@@ -380,7 +380,7 @@ Local<Function> GetBoxedFunction(GIBaseInfo *info, GType gtype) {
|
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
if (data) {
|
|
383
|
-
auto *persistent = (Persistent<Function> *) data;
|
|
383
|
+
auto *persistent = (Nan::Persistent<Function> *) data;
|
|
384
384
|
auto fn = Nan::New<Function> (*persistent);
|
|
385
385
|
return fn;
|
|
386
386
|
}
|
|
@@ -391,7 +391,7 @@ Local<Function> GetBoxedFunction(GIBaseInfo *info, GType gtype) {
|
|
|
391
391
|
if (gtype == G_TYPE_NONE)
|
|
392
392
|
return fn;
|
|
393
393
|
|
|
394
|
-
auto *persistent = new Persistent<Function>(
|
|
394
|
+
auto *persistent = new Nan::Persistent<Function>(fn);
|
|
395
395
|
|
|
396
396
|
g_type_set_qdata(gtype, GNodeJS::function_quark(), persistent);
|
|
397
397
|
|
|
@@ -419,15 +419,15 @@ Local<Function> MakeBoxedClass(GIBaseInfo *info) {
|
|
|
419
419
|
return GetBoxedFunction (info, gtype);
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
Local<Value> WrapperFromBoxed(GIBaseInfo *info, void *data,
|
|
422
|
+
Local<Value> WrapperFromBoxed(GIBaseInfo *info, void *data, ResourceOwnership ownership) {
|
|
423
423
|
if (data == NULL)
|
|
424
424
|
return Nan::Null();
|
|
425
425
|
|
|
426
426
|
Local<Function> constructor = MakeBoxedClass (info);
|
|
427
427
|
|
|
428
|
-
Local<Value>
|
|
429
|
-
Local<Value>
|
|
430
|
-
Local<Value> args[] = {
|
|
428
|
+
Local<Value> jsBoxed = Nan::New<External> (data);
|
|
429
|
+
Local<Value> jsOwnership = Nan::New<v8::Int32> ((int32_t) ownership);
|
|
430
|
+
Local<Value> args[] = { jsBoxed, jsOwnership };
|
|
431
431
|
|
|
432
432
|
MaybeLocal<Object> instance = Nan::NewInstance(constructor, 2, args);
|
|
433
433
|
|
package/src/boxed.h
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
#pragma once
|
|
3
3
|
|
|
4
|
+
#include "value.h"
|
|
4
5
|
#include <nan.h>
|
|
5
6
|
#include <node.h>
|
|
6
7
|
#include <girepository.h>
|
|
@@ -30,7 +31,7 @@ public:
|
|
|
30
31
|
|
|
31
32
|
Local<Function> MakeBoxedClass (GIBaseInfo *info);
|
|
32
33
|
Local<FunctionTemplate> GetBoxedTemplate (GIBaseInfo *info, GType gtype);
|
|
33
|
-
Local<Value> WrapperFromBoxed (GIBaseInfo *info, void *data,
|
|
34
|
+
Local<Value> WrapperFromBoxed (GIBaseInfo *info, void *data, ResourceOwnership ownership = kNone);
|
|
34
35
|
void * PointerFromWrapper (Local<Value>);
|
|
35
36
|
|
|
36
37
|
};
|
package/src/callback.cc
CHANGED
|
@@ -117,14 +117,14 @@ void Callback::Execute (GIArgument *result, GIArgument **args, Callback *callbac
|
|
|
117
117
|
|
|
118
118
|
bool isOutArgument = g_arg_info_get_direction(&arg_info) == GI_DIRECTION_OUT;
|
|
119
119
|
bool isPrimitive = Type::IsPrimitive(&arg_type);
|
|
120
|
-
|
|
120
|
+
ResourceOwnership ownership = isOutArgument ? kNone : kCopy;
|
|
121
121
|
|
|
122
122
|
if (isPrimitive && isOutArgument) {
|
|
123
123
|
n_return_values += 1;
|
|
124
124
|
primitive_out_arguments_mask |= 1 << i;
|
|
125
125
|
js_args[i] = Nan::Null();
|
|
126
126
|
} else {
|
|
127
|
-
js_args[i] = GIArgumentToV8 (&arg_type, args[i + args_offset], -1,
|
|
127
|
+
js_args[i] = GIArgumentToV8 (&arg_type, args[i + args_offset], -1, ownership);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
package/src/closure.cc
CHANGED
|
@@ -63,26 +63,30 @@ void Closure::Execute(GICallableInfo *info, guint signal_id,
|
|
|
63
63
|
g_callable_info_load_arg(info, i - 1, &arg_info);
|
|
64
64
|
g_arg_info_load_type(&arg_info, &type_info);
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
ResourceOwnership ownership = kCopy;
|
|
67
67
|
|
|
68
68
|
if (signal_query.signal_id) {
|
|
69
|
-
|
|
69
|
+
if ((signal_query.param_types[i - 1] & G_SIGNAL_TYPE_STATIC_SCOPE) != 0) {
|
|
70
|
+
ownership = kNone;
|
|
71
|
+
}
|
|
70
72
|
}
|
|
71
73
|
if (g_arg_info_get_direction(&arg_info) == GI_DIRECTION_OUT) {
|
|
72
|
-
|
|
74
|
+
ownership = kNone;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
js_args[i - 1] = GIArgumentToV8(&type_info, &argument, -1,
|
|
77
|
+
js_args[i - 1] = GIArgumentToV8(&type_info, &argument, -1, ownership);
|
|
76
78
|
}
|
|
77
79
|
} else {
|
|
78
80
|
/* CallableInfo is not available: use GValueToV8 */
|
|
79
81
|
for (guint i = 1; i < n_param_values; i++) {
|
|
80
|
-
|
|
82
|
+
ResourceOwnership ownership = kCopy;
|
|
81
83
|
|
|
82
84
|
if (signal_query.signal_id) {
|
|
83
|
-
|
|
85
|
+
if ((signal_query.param_types[i - 1] & G_SIGNAL_TYPE_STATIC_SCOPE) != 0) {
|
|
86
|
+
ownership = kNone;
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
|
-
js_args[i - 1] = GValueToV8(¶m_values[i],
|
|
89
|
+
js_args[i - 1] = GValueToV8(¶m_values[i], ownership);
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
|
|
@@ -101,7 +105,7 @@ void Closure::Execute(GICallableInfo *info, guint signal_id,
|
|
|
101
105
|
&& result.ToLocal(&return_value)) {
|
|
102
106
|
|
|
103
107
|
if (g_return_value) {
|
|
104
|
-
if (!V8ToGValue (g_return_value, return_value,
|
|
108
|
+
if (!V8ToGValue (g_return_value, return_value, kCopy))
|
|
105
109
|
goto throw_exception;
|
|
106
110
|
}
|
|
107
111
|
|
package/src/debug.cc
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#include "type.h"
|
|
11
11
|
|
|
12
12
|
#include <cstdio>
|
|
13
|
+
#include <cinttypes>
|
|
13
14
|
|
|
14
15
|
namespace GNodeJS {
|
|
15
16
|
|
|
@@ -245,16 +246,16 @@ void print_gtype (GType type) {
|
|
|
245
246
|
void print_type (GType type) {
|
|
246
247
|
GType t = type;
|
|
247
248
|
while(!G_TYPE_IS_FUNDAMENTAL(type) && t != 0) {
|
|
248
|
-
printf("\t\x1b[92m -> %s \t (%
|
|
249
|
+
printf("\t\x1b[92m -> %s \t (%" PRIuPTR ")\x1b[0m\n", g_type_name(t), (uintptr_t)t);
|
|
249
250
|
t = g_type_parent(t);
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
|
|
253
254
|
void print_klass (void * klass) {
|
|
254
255
|
printf("\x1b[38;5;202m");
|
|
255
|
-
printf("klass: %s (type: %
|
|
256
|
+
printf("klass: %s (type: %" PRIuPTR " )",
|
|
256
257
|
G_OBJECT_CLASS_NAME (klass),
|
|
257
|
-
G_OBJECT_CLASS_TYPE (klass) );
|
|
258
|
+
(uintptr_t)G_OBJECT_CLASS_TYPE (klass) );
|
|
258
259
|
printf("\x1b[0m\n");
|
|
259
260
|
}
|
|
260
261
|
|
package/src/function.cc
CHANGED
|
@@ -335,7 +335,7 @@ Local<Value> FunctionCall (
|
|
|
335
335
|
|
|
336
336
|
if (func->is_method) {
|
|
337
337
|
GIBaseInfo *container = g_base_info_get_container (gi_info);
|
|
338
|
-
|
|
338
|
+
V8ToGIArgumentInterface(container, &total_arg_values[0], info.This());
|
|
339
339
|
callable_arg_values = &total_arg_values[1];
|
|
340
340
|
} else {
|
|
341
341
|
callable_arg_values = &total_arg_values[0];
|
|
@@ -488,24 +488,29 @@ Local<Value> FunctionCall (
|
|
|
488
488
|
Nan::ThrowError(error_stack->message);
|
|
489
489
|
g_error_free(error_stack);
|
|
490
490
|
}
|
|
491
|
+
|
|
492
|
+
/*
|
|
493
|
+
* Fifth, free the return value and arguments
|
|
494
|
+
*/
|
|
495
|
+
|
|
496
|
+
if (!use_return_value)
|
|
497
|
+
FreeGIArgument(&return_type, &return_value_stack, return_transfer);
|
|
498
|
+
|
|
491
499
|
} else if (!use_return_value) {
|
|
492
|
-
|
|
500
|
+
|
|
501
|
+
// Value transferred to jsReturnValue
|
|
502
|
+
jsReturnValue = func->JsReturnValue (
|
|
493
503
|
info.This(),
|
|
494
504
|
&return_type,
|
|
495
|
-
|
|
496
|
-
callable_arg_values
|
|
505
|
+
&return_value_stack,
|
|
506
|
+
callable_arg_values,
|
|
507
|
+
return_transfer);
|
|
497
508
|
} else {
|
|
509
|
+
|
|
510
|
+
// Value returned in return_value
|
|
498
511
|
jsReturnValue = Nan::Undefined();
|
|
499
512
|
}
|
|
500
513
|
|
|
501
|
-
|
|
502
|
-
/*
|
|
503
|
-
* Fifth, free the return value and arguments
|
|
504
|
-
*/
|
|
505
|
-
|
|
506
|
-
if (!use_return_value)
|
|
507
|
-
FreeGIArgument(&return_type, &return_value_stack, return_transfer);
|
|
508
|
-
|
|
509
514
|
for (int i = 0; i < func->n_callable_args; i++) {
|
|
510
515
|
GIArgInfo arg_info = {};
|
|
511
516
|
GITypeInfo arg_type;
|
|
@@ -553,11 +558,12 @@ Local<Value> FunctionCall (
|
|
|
553
558
|
* Creates the JS return value from the C arguments list
|
|
554
559
|
* @returns the JS return value
|
|
555
560
|
*/
|
|
556
|
-
Local<Value> FunctionInfo::
|
|
561
|
+
Local<Value> FunctionInfo::JsReturnValue (
|
|
557
562
|
Local<Value> self,
|
|
558
563
|
GITypeInfo* return_type,
|
|
559
564
|
GIArgument* return_value,
|
|
560
|
-
GIArgument* callable_arg_values
|
|
565
|
+
GIArgument* callable_arg_values,
|
|
566
|
+
GITransfer return_transfer) {
|
|
561
567
|
|
|
562
568
|
Local<Value> jsReturnValue;
|
|
563
569
|
int jsReturnIndex = 0;
|
|
@@ -591,7 +597,10 @@ Local<Value> FunctionInfo::GetReturnValue (
|
|
|
591
597
|
// When a method returns the instance itself, skip the conversion and just return the
|
|
592
598
|
// existent wrapper
|
|
593
599
|
bool isReturningSelf = is_method && PointerFromWrapper(self) == return_value->v_pointer;
|
|
594
|
-
ADD_RETURN (isReturningSelf ? self :
|
|
600
|
+
ADD_RETURN (isReturningSelf ? self :
|
|
601
|
+
GIArgumentToV8 (
|
|
602
|
+
return_type, return_value, length,
|
|
603
|
+
return_transfer == GI_TRANSFER_EVERYTHING ? kTransfer : kNone))
|
|
595
604
|
}
|
|
596
605
|
|
|
597
606
|
for (int i = 0; i < n_callable_args; i++) {
|
|
@@ -630,13 +639,15 @@ Local<Value> FunctionInfo::GetReturnValue (
|
|
|
630
639
|
ADD_RETURN (result)
|
|
631
640
|
|
|
632
641
|
} else if (param.type == ParameterType::kNORMAL) {
|
|
642
|
+
GITransfer transfer = g_arg_info_get_ownership_transfer(&arg_info);
|
|
643
|
+
ResourceOwnership ownership = transfer == GI_TRANSFER_EVERYTHING ? kTransfer : kNone;
|
|
633
644
|
|
|
634
645
|
if (IsPointerType(&arg_type) && g_arg_info_is_caller_allocates(&arg_info)) {
|
|
635
646
|
void *pointer = &arg_value.v_pointer;
|
|
636
|
-
ADD_RETURN (GIArgumentToV8(&arg_type, (GIArgument*) pointer))
|
|
647
|
+
ADD_RETURN (GIArgumentToV8(&arg_type, (GIArgument*) pointer, -1, ownership))
|
|
637
648
|
}
|
|
638
649
|
else {
|
|
639
|
-
ADD_RETURN (GIArgumentToV8(&arg_type, (GIArgument*) arg_value.v_pointer))
|
|
650
|
+
ADD_RETURN (GIArgumentToV8(&arg_type, (GIArgument*) arg_value.v_pointer, -1, ownership))
|
|
640
651
|
}
|
|
641
652
|
}
|
|
642
653
|
}
|
|
@@ -647,19 +658,6 @@ Local<Value> FunctionInfo::GetReturnValue (
|
|
|
647
658
|
return jsReturnValue;
|
|
648
659
|
}
|
|
649
660
|
|
|
650
|
-
/**
|
|
651
|
-
* Frees the C return value
|
|
652
|
-
* @param return_value the return value pointer
|
|
653
|
-
*/
|
|
654
|
-
void FunctionInfo::FreeReturnValue (GIArgument *return_value) {
|
|
655
|
-
GITypeInfo return_type;
|
|
656
|
-
g_callable_info_load_return_type(info, &return_type);
|
|
657
|
-
GITransfer return_transfer = g_callable_info_get_caller_owns(info);
|
|
658
|
-
|
|
659
|
-
FreeGIArgument(&return_type, return_value, return_transfer);
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
|
|
663
661
|
|
|
664
662
|
Local<Function> MakeFunction(GIBaseInfo *info) {
|
|
665
663
|
FunctionInfo *func = new FunctionInfo(info);
|
|
@@ -673,8 +671,8 @@ Local<Function> MakeFunction(GIBaseInfo *info) {
|
|
|
673
671
|
auto fn = Nan::GetFunction (tpl).ToLocalChecked();
|
|
674
672
|
fn->SetName(name);
|
|
675
673
|
|
|
676
|
-
Persistent<FunctionTemplate>
|
|
677
|
-
persistent
|
|
674
|
+
func->persistent = new Nan::Persistent<FunctionTemplate>(tpl);
|
|
675
|
+
func->persistent->SetWeak(func, FunctionDestroyed, WeakCallbackType::kParameter);
|
|
678
676
|
|
|
679
677
|
return fn;
|
|
680
678
|
}
|
|
@@ -691,8 +689,9 @@ void FunctionInvoker(const Nan::FunctionCallbackInfo<Value> &info) {
|
|
|
691
689
|
Callback::AsyncFree();
|
|
692
690
|
}
|
|
693
691
|
|
|
694
|
-
void FunctionDestroyed(const
|
|
692
|
+
void FunctionDestroyed(const Nan::WeakCallbackInfo<FunctionInfo> &data) {
|
|
695
693
|
FunctionInfo *func = data.GetParameter ();
|
|
694
|
+
delete func->persistent;
|
|
696
695
|
delete func;
|
|
697
696
|
}
|
|
698
697
|
|
package/src/function.h
CHANGED
|
@@ -40,14 +40,14 @@ struct FunctionInfo {
|
|
|
40
40
|
int n_in_args;
|
|
41
41
|
|
|
42
42
|
Parameter* call_parameters;
|
|
43
|
+
Nan::Persistent<FunctionTemplate> *persistent;
|
|
43
44
|
|
|
44
45
|
FunctionInfo(GIBaseInfo* info);
|
|
45
46
|
~FunctionInfo();
|
|
46
47
|
|
|
47
48
|
bool Init();
|
|
48
49
|
bool TypeCheck (const Nan::FunctionCallbackInfo<Value> &info);
|
|
49
|
-
Local<Value>
|
|
50
|
-
void FreeReturnValue (GIArgument *return_value);
|
|
50
|
+
Local<Value> JsReturnValue (Local<Value> self, GITypeInfo* return_type, GIArgument* return_value, GIArgument* callable_arg_values, GITransfer return_transfer);
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
bool IsDestroyNotify (GIBaseInfo *info);
|
|
@@ -55,7 +55,7 @@ bool IsDestroyNotify (GIBaseInfo *info);
|
|
|
55
55
|
Local<Value> FunctionCall (FunctionInfo *func, const Nan::FunctionCallbackInfo<Value> &info, GIArgument *return_value = NULL, GError **error = NULL);
|
|
56
56
|
|
|
57
57
|
void FunctionInvoker (const Nan::FunctionCallbackInfo<Value> &info);
|
|
58
|
-
void FunctionDestroyed (const
|
|
58
|
+
void FunctionDestroyed (const Nan::WeakCallbackInfo<FunctionInfo> &data);
|
|
59
59
|
|
|
60
60
|
Local<Function> MakeFunction (GIBaseInfo *base_info);
|
|
61
61
|
|
package/src/gi.cc
CHANGED
|
@@ -283,7 +283,7 @@ NAN_METHOD(StructFieldGetter) {
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
GIArgument value;
|
|
286
|
-
|
|
286
|
+
GNodeJS::ResourceOwnership ownership = GNodeJS::kCopy;
|
|
287
287
|
BaseInfo typeInfo = g_field_info_get_type(*fieldInfo);
|
|
288
288
|
|
|
289
289
|
if (!g_field_info_get_field(*fieldInfo, boxed, &value)) {
|
|
@@ -300,13 +300,13 @@ NAN_METHOD(StructFieldGetter) {
|
|
|
300
300
|
// auto offset = g_field_info_get_offset(*fieldInfo);
|
|
301
301
|
// auto fieldPtr = G_STRUCT_MEMBER_P(boxed, offset);
|
|
302
302
|
// value.v_pointer = fieldPtr;
|
|
303
|
-
//
|
|
303
|
+
// ownership = kNone;
|
|
304
304
|
|
|
305
305
|
Nan::ThrowError("Converting non-primitive fields is not allowed");
|
|
306
306
|
return;
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
RETURN(GNodeJS::GIArgumentToV8(*typeInfo, &value, -1,
|
|
309
|
+
RETURN(GNodeJS::GIArgumentToV8(*typeInfo, &value, -1, ownership));
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
NAN_METHOD(StartLoop) {
|
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;
|
|
@@ -75,7 +72,7 @@ static GObject* CreateGObjectFromObject(GType gtype, Local<Value> object) {
|
|
|
75
72
|
|
|
76
73
|
g_value_init(&values[index], value_spec->value_type);
|
|
77
74
|
|
|
78
|
-
if (!V8ToGValue(&values[index], value,
|
|
75
|
+
if (!V8ToGValue(&values[index], value, kCopy)) {
|
|
79
76
|
// V8ToGValue throws the error
|
|
80
77
|
goto out;
|
|
81
78
|
}
|
|
@@ -102,7 +99,7 @@ static void ToggleNotify(gpointer user_data, GObject *gobject, gboolean toggle_d
|
|
|
102
99
|
|
|
103
100
|
g_assert (data != NULL);
|
|
104
101
|
|
|
105
|
-
auto *persistent = (Persistent<Object> *) data;
|
|
102
|
+
auto *persistent = (Nan::Persistent<Object> *) data;
|
|
106
103
|
|
|
107
104
|
if (toggle_down) {
|
|
108
105
|
/* We're dropping from 2 refs to 1 ref. We are the last holder. Make
|
|
@@ -120,7 +117,7 @@ static void AssociateGObject(Local<Object> object, GObject *gobject, GType gtype
|
|
|
120
117
|
|
|
121
118
|
SET_OBJECT_GTYPE(object, gtype);
|
|
122
119
|
|
|
123
|
-
|
|
120
|
+
auto *persistent = new Nan::Persistent<Object>(object);
|
|
124
121
|
g_object_set_qdata (gobject, GNodeJS::object_quark(), persistent);
|
|
125
122
|
|
|
126
123
|
// Because we can't sink floating ref and add toggle ref at the same time,
|
|
@@ -184,7 +181,7 @@ static void GObjectDestroyed(const Nan::WeakCallbackInfo<GObject> &data) {
|
|
|
184
181
|
GObject *gobject = data.GetParameter ();
|
|
185
182
|
|
|
186
183
|
void *type_data = g_object_get_qdata (gobject, GNodeJS::object_quark());
|
|
187
|
-
|
|
184
|
+
auto *persistent = (Nan::Persistent<Object> *) type_data;
|
|
188
185
|
delete persistent;
|
|
189
186
|
|
|
190
187
|
/* We're destroying the wrapper object, so make sure to clear out
|
|
@@ -200,9 +197,9 @@ static void GObjectClassDestroyed(const Nan::WeakCallbackInfo<GType> &info) {
|
|
|
200
197
|
|
|
201
198
|
DestroyVFuncs(gtype);
|
|
202
199
|
|
|
203
|
-
auto persistentTpl = (Persistent<FunctionTemplate> *)
|
|
200
|
+
auto persistentTpl = (Nan::Persistent<FunctionTemplate> *)
|
|
204
201
|
g_type_get_qdata (gtype, GNodeJS::template_quark());
|
|
205
|
-
auto persistentFn = (Persistent<Function> *)
|
|
202
|
+
auto persistentFn = (Nan::Persistent<Function> *)
|
|
206
203
|
g_type_get_qdata (gtype, GNodeJS::function_quark());
|
|
207
204
|
delete persistentTpl;
|
|
208
205
|
delete persistentFn;
|
|
@@ -212,8 +209,18 @@ static void GObjectClassDestroyed(const Nan::WeakCallbackInfo<GType> &info) {
|
|
|
212
209
|
g_free(gtypePtr);
|
|
213
210
|
}
|
|
214
211
|
|
|
215
|
-
|
|
216
|
-
|
|
212
|
+
#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
|
|
213
|
+
(V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
|
|
214
|
+
#define PROPERTY_CALLBACK_RETURN_TYPE v8::Intercepted
|
|
215
|
+
#define PROPERTY_CALLBACK_INFO_TYPE v8::PropertyCallbackInfo<void>
|
|
216
|
+
#else
|
|
217
|
+
#define PROPERTY_CALLBACK_RETURN_TYPE void
|
|
218
|
+
#define PROPERTY_CALLBACK_INFO_TYPE v8::PropertyCallbackInfo<Value>
|
|
219
|
+
#endif
|
|
220
|
+
|
|
221
|
+
static PROPERTY_CALLBACK_RETURN_TYPE
|
|
222
|
+
GObjectFallbackPropertyGetter(Local<v8::Name> property,
|
|
223
|
+
const v8::PropertyCallbackInfo<Value>& info) {
|
|
217
224
|
auto self = info.Holder();
|
|
218
225
|
GObject *gobject = GObjectFromWrapper (self);
|
|
219
226
|
|
|
@@ -225,20 +232,25 @@ static void GObjectFallbackPropertyGetter(Local<v8::Name> property,
|
|
|
225
232
|
if (strstr(prop_name_camel, "-")) {
|
|
226
233
|
// Has dash, not a camel-case property name.
|
|
227
234
|
RETURN(Nan::Undefined());
|
|
228
|
-
return;
|
|
235
|
+
return Nan::Intercepted::Yes();
|
|
229
236
|
}
|
|
230
237
|
|
|
231
238
|
char *prop_name = Util::ToDashed(prop_name_camel);
|
|
232
239
|
|
|
233
240
|
auto value = GetGObjectProperty(gobject, prop_name);
|
|
234
|
-
if (!value.IsEmpty())
|
|
241
|
+
if (!value.IsEmpty()) {
|
|
235
242
|
RETURN(value.ToLocalChecked());
|
|
243
|
+
g_free(prop_name);
|
|
244
|
+
return Nan::Intercepted::Yes();
|
|
245
|
+
}
|
|
236
246
|
|
|
237
247
|
g_free(prop_name);
|
|
248
|
+
return Nan::Intercepted::No();
|
|
238
249
|
}
|
|
239
250
|
|
|
240
|
-
static
|
|
241
|
-
|
|
251
|
+
static PROPERTY_CALLBACK_RETURN_TYPE
|
|
252
|
+
GObjectFallbackPropertySetter(Local<v8::Name> property, Local<Value> value,
|
|
253
|
+
const PROPERTY_CALLBACK_INFO_TYPE& info) {
|
|
242
254
|
auto self = info.Holder();
|
|
243
255
|
GObject *gobject = GNodeJS::GObjectFromWrapper (self);
|
|
244
256
|
|
|
@@ -247,7 +259,7 @@ static void GObjectFallbackPropertySetter (Local<v8::Name> property, Local<Value
|
|
|
247
259
|
|
|
248
260
|
if (strstr(prop_name_camel, "-")) {
|
|
249
261
|
// Has dash, not a camel-case property name.
|
|
250
|
-
return;
|
|
262
|
+
return Nan::Intercepted::No();
|
|
251
263
|
}
|
|
252
264
|
|
|
253
265
|
char *prop_name = Util::ToDashed(prop_name_camel);
|
|
@@ -255,20 +267,22 @@ static void GObjectFallbackPropertySetter (Local<v8::Name> property, Local<Value
|
|
|
255
267
|
if (gobject == NULL) {
|
|
256
268
|
WARN("Can't set \"%s\" on null GObject", prop_name);
|
|
257
269
|
g_free(prop_name);
|
|
258
|
-
return;
|
|
270
|
+
return Nan::Intercepted::No();
|
|
259
271
|
}
|
|
260
272
|
|
|
261
273
|
auto setResult = SetGObjectProperty(gobject, prop_name, value);
|
|
262
274
|
if (setResult.IsEmpty()) {
|
|
263
275
|
// Non-existent property. Let node consider the set not intercepted
|
|
264
276
|
// by not setting return value;
|
|
277
|
+
g_free(prop_name);
|
|
278
|
+
return Nan::Intercepted::No();
|
|
265
279
|
} else {
|
|
266
280
|
// Property exists. Whether we can convert the value and set the
|
|
267
281
|
// property or not, consider the set intercepted.
|
|
268
282
|
RETURN(value);
|
|
283
|
+
g_free(prop_name);
|
|
284
|
+
return Nan::Intercepted::Yes();
|
|
269
285
|
}
|
|
270
|
-
|
|
271
|
-
g_free(prop_name);
|
|
272
286
|
}
|
|
273
287
|
|
|
274
288
|
static GISignalInfo* FindSignalInfo(GIObjectInfo *info, const char *signal_detail) {
|
|
@@ -463,9 +477,9 @@ NAN_METHOD(SignalEmit) {
|
|
|
463
477
|
g_value_init(gvalue, signal_query.param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE);
|
|
464
478
|
|
|
465
479
|
if ((signal_query.param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE) != 0)
|
|
466
|
-
failed = !V8ToGValue(gvalue, info[i + 1],
|
|
480
|
+
failed = !V8ToGValue(gvalue, info[i + 1], kNone); // no-copy
|
|
467
481
|
else
|
|
468
|
-
failed = !V8ToGValue(gvalue, info[i + 1],
|
|
482
|
+
failed = !V8ToGValue(gvalue, info[i + 1], kCopy); // copy
|
|
469
483
|
|
|
470
484
|
if (failed)
|
|
471
485
|
break;
|
|
@@ -551,9 +565,8 @@ static MaybeLocal<FunctionTemplate> NewClassTemplate (GType gtype) {
|
|
|
551
565
|
// Set the fallback accessor to allow non-introspected property.
|
|
552
566
|
// Nan::SetNamedPropertyHandler() does not support flags. Thus, using
|
|
553
567
|
// V8 interface directly.
|
|
554
|
-
v8::NamedPropertyHandlerConfiguration config
|
|
555
|
-
|
|
556
|
-
config.setter = GObjectFallbackPropertySetter;
|
|
568
|
+
v8::NamedPropertyHandlerConfiguration config(GObjectFallbackPropertyGetter,
|
|
569
|
+
GObjectFallbackPropertySetter);
|
|
557
570
|
config.flags = static_cast<v8::PropertyHandlerFlags>(
|
|
558
571
|
static_cast<int>(v8::PropertyHandlerFlags::kNonMasking) |
|
|
559
572
|
static_cast<int>(v8::PropertyHandlerFlags::kOnlyInterceptStrings));
|
|
@@ -566,7 +579,7 @@ static MaybeLocal<FunctionTemplate> GetClassTemplate(GType gtype) {
|
|
|
566
579
|
void *data = g_type_get_qdata (gtype, GNodeJS::template_quark());
|
|
567
580
|
|
|
568
581
|
if (data) {
|
|
569
|
-
auto *persistent = (Persistent<FunctionTemplate> *) data;
|
|
582
|
+
auto *persistent = (Nan::Persistent<FunctionTemplate> *) data;
|
|
570
583
|
auto tpl = New<FunctionTemplate> (*persistent);
|
|
571
584
|
return tpl;
|
|
572
585
|
}
|
|
@@ -577,8 +590,8 @@ static MaybeLocal<FunctionTemplate> GetClassTemplate(GType gtype) {
|
|
|
577
590
|
|
|
578
591
|
auto tpl = maybeTpl.ToLocalChecked();
|
|
579
592
|
auto fn = Nan::GetFunction (tpl).ToLocalChecked();
|
|
580
|
-
auto persistentTpl = new Persistent<FunctionTemplate>(tpl);
|
|
581
|
-
auto persistentFn = new Persistent<Function>(fn);
|
|
593
|
+
auto persistentTpl = new Nan::Persistent<FunctionTemplate>(tpl);
|
|
594
|
+
auto persistentFn = new Nan::Persistent<Function>(fn);
|
|
582
595
|
|
|
583
596
|
GType *gtypePtr = g_new(GType, 1);
|
|
584
597
|
*gtypePtr = gtype;
|
|
@@ -596,7 +609,7 @@ static MaybeLocal<Function> GetClass(GType gtype) {
|
|
|
596
609
|
void *data = g_type_get_qdata (gtype, GNodeJS::function_quark());
|
|
597
610
|
|
|
598
611
|
if (data) {
|
|
599
|
-
auto persistent = (Persistent<Function> *) data;
|
|
612
|
+
auto persistent = (Nan::Persistent<Function> *) data;
|
|
600
613
|
auto fn = New<Function> (*persistent);
|
|
601
614
|
return MaybeLocal<Function> (fn);
|
|
602
615
|
}
|
|
@@ -611,7 +624,7 @@ static MaybeLocal<Function> GetClass(GType gtype) {
|
|
|
611
624
|
data = g_type_get_qdata (gtype, GNodeJS::function_quark());
|
|
612
625
|
|
|
613
626
|
if (data) {
|
|
614
|
-
auto persistent = (Persistent<Function> *) data;
|
|
627
|
+
auto persistent = (Nan::Persistent<Function> *) data;
|
|
615
628
|
auto fn = New<Function> (*persistent);
|
|
616
629
|
return MaybeLocal<Function> (fn);
|
|
617
630
|
}
|
|
@@ -640,7 +653,7 @@ Local<Value> WrapperFromGObject(GObject *gobject) {
|
|
|
640
653
|
|
|
641
654
|
if (data) {
|
|
642
655
|
/* Easy case: we already have an object. */
|
|
643
|
-
auto *persistent = (Persistent<Object> *) data;
|
|
656
|
+
auto *persistent = (Nan::Persistent<Object> *) data;
|
|
644
657
|
auto obj = New<Object> (*persistent);
|
|
645
658
|
return obj;
|
|
646
659
|
}
|
|
@@ -680,7 +693,7 @@ MaybeLocal<Value> GetGObjectProperty(GObject * gobject, const char *prop_name) {
|
|
|
680
693
|
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
|
|
681
694
|
g_object_get_property (gobject, prop_name, &value);
|
|
682
695
|
|
|
683
|
-
auto ret = GNodeJS::GValueToV8(&value,
|
|
696
|
+
auto ret = GNodeJS::GValueToV8(&value, kCopy);
|
|
684
697
|
|
|
685
698
|
g_value_unset(&value);
|
|
686
699
|
|
|
@@ -699,7 +712,7 @@ MaybeLocal<v8::Boolean> SetGObjectProperty(GObject * gobject, const char *prop_n
|
|
|
699
712
|
GValue gvalue = G_VALUE_INIT;
|
|
700
713
|
g_value_init(&gvalue, G_PARAM_SPEC_VALUE_TYPE (pspec));
|
|
701
714
|
|
|
702
|
-
if (GNodeJS::V8ToGValue (&gvalue, value,
|
|
715
|
+
if (GNodeJS::V8ToGValue (&gvalue, value, kCopy)) {
|
|
703
716
|
g_object_set_property (gobject, prop_name, &gvalue);
|
|
704
717
|
ret = Nan::True();
|
|
705
718
|
} 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);
|
|
@@ -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
|
|
package/src/modules/system.cc
CHANGED
|
@@ -65,8 +65,8 @@ NAN_METHOD(ConvertGValue) {
|
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
void *ptr = obj->GetAlignedPointerFromInternalField (0);
|
|
68
|
-
|
|
69
|
-
RETURN(GValueToV8(reinterpret_cast<GValue *>(ptr),
|
|
68
|
+
ResourceOwnership ownership = kCopy;
|
|
69
|
+
RETURN(GValueToV8(reinterpret_cast<GValue *>(ptr), ownership));
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
NAN_METHOD(GetMemoryContent) {
|
package/src/value.cc
CHANGED
|
@@ -36,7 +36,7 @@ static void HashPointerToGIArgument (GIArgument *arg, GITypeInfo *type_info);
|
|
|
36
36
|
static bool IsUint8Array (GITypeInfo *type_info);
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
Local<Value> GIArgumentToV8(GITypeInfo *type_info, GIArgument *arg, long length,
|
|
39
|
+
Local<Value> GIArgumentToV8(GITypeInfo *type_info, GIArgument *arg, long length, ResourceOwnership ownership) {
|
|
40
40
|
GITypeTag type_tag = g_type_info_get_tag (type_info);
|
|
41
41
|
|
|
42
42
|
switch (type_tag) {
|
|
@@ -128,7 +128,7 @@ Local<Value> GIArgumentToV8(GITypeInfo *type_info, GIArgument *arg, long length,
|
|
|
128
128
|
case GI_INFO_TYPE_BOXED:
|
|
129
129
|
case GI_INFO_TYPE_STRUCT:
|
|
130
130
|
case GI_INFO_TYPE_UNION:
|
|
131
|
-
value = WrapperFromBoxed (interface_info, arg->v_pointer,
|
|
131
|
+
value = WrapperFromBoxed (interface_info, arg->v_pointer, ownership);
|
|
132
132
|
break;
|
|
133
133
|
case GI_INFO_TYPE_ENUM:
|
|
134
134
|
value = New<Number>(arg->v_int);
|
|
@@ -162,7 +162,7 @@ Local<Value> GIArgumentToV8(GITypeInfo *type_info, GIArgument *arg, long length,
|
|
|
162
162
|
return GHashToV8(type_info, (GHashTable *)arg->v_pointer);
|
|
163
163
|
|
|
164
164
|
case GI_TYPE_TAG_ERROR:
|
|
165
|
-
return GErrorToV8(type_info, (GError *)arg->v_pointer);
|
|
165
|
+
return GErrorToV8(type_info, (GError *)arg->v_pointer, ownership);
|
|
166
166
|
|
|
167
167
|
default:
|
|
168
168
|
ERROR("Unhandled tag type: %s", g_type_tag_to_string(type_tag));
|
|
@@ -232,9 +232,9 @@ Local<Value> GHashToV8 (GITypeInfo *type_info, GHashTable *hash_table) {
|
|
|
232
232
|
return object;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
Local<Value> GErrorToV8 (GITypeInfo *type_info, GError *err) {
|
|
236
|
-
auto err_info =
|
|
237
|
-
auto obj = WrapperFromBoxed (err_info, err,
|
|
235
|
+
Local<Value> GErrorToV8 (GITypeInfo *type_info, GError *err, ResourceOwnership ownership) {
|
|
236
|
+
auto err_info = g_irepository_find_by_gtype(NULL, g_error_get_type());
|
|
237
|
+
auto obj = WrapperFromBoxed (err_info, err, ownership);
|
|
238
238
|
return obj;
|
|
239
239
|
}
|
|
240
240
|
|
|
@@ -682,7 +682,7 @@ item_error:
|
|
|
682
682
|
return hash_table;
|
|
683
683
|
}
|
|
684
684
|
|
|
685
|
-
bool
|
|
685
|
+
bool V8ToGIArgumentInterface(GIBaseInfo *gi_info, GIArgument *arg, Local<Value> value) {
|
|
686
686
|
GIInfoType type = g_base_info_get_type (gi_info);
|
|
687
687
|
|
|
688
688
|
memset(arg, 0, sizeof(GIArgument));
|
|
@@ -828,7 +828,7 @@ bool V8ToGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> value,
|
|
|
828
828
|
case GI_TYPE_TAG_INTERFACE:
|
|
829
829
|
{
|
|
830
830
|
GIBaseInfo *interface_info = g_type_info_get_interface (type_info);
|
|
831
|
-
|
|
831
|
+
V8ToGIArgumentInterface (interface_info, arg, value);
|
|
832
832
|
g_base_info_unref(interface_info);
|
|
833
833
|
}
|
|
834
834
|
break;
|
|
@@ -1241,7 +1241,7 @@ void FreeGIArgument(GITypeInfo *type_info, GIArgument *arg, GITransfer transfer,
|
|
|
1241
1241
|
|
|
1242
1242
|
case GI_TYPE_TAG_ERROR:
|
|
1243
1243
|
{
|
|
1244
|
-
g_error_free
|
|
1244
|
+
// no g_error_free as the ptr is taken directly from box
|
|
1245
1245
|
break;
|
|
1246
1246
|
}
|
|
1247
1247
|
|
|
@@ -1424,7 +1424,7 @@ bool CanConvertV8ToGValue(GValue *gvalue, Local<Value> value) {
|
|
|
1424
1424
|
G_VALUE_TYPE_NAME (gvalue));
|
|
1425
1425
|
}
|
|
1426
1426
|
|
|
1427
|
-
bool V8ToGValue(GValue *gvalue, Local<Value> value,
|
|
1427
|
+
bool V8ToGValue(GValue *gvalue, Local<Value> value, ResourceOwnership ownership) {
|
|
1428
1428
|
if (!CanConvertV8ToGValue(gvalue, value)) {
|
|
1429
1429
|
auto maybeDetailString = Nan::ToDetailString(value);
|
|
1430
1430
|
Nan::Utf8String utf8String(
|
|
@@ -1487,7 +1487,7 @@ bool V8ToGValue(GValue *gvalue, Local<Value> value, bool mustCopy) {
|
|
|
1487
1487
|
Throw::CannotConvertGType("boxed", G_VALUE_TYPE (gvalue));
|
|
1488
1488
|
return false;
|
|
1489
1489
|
}
|
|
1490
|
-
if (
|
|
1490
|
+
if (ownership == kCopy)
|
|
1491
1491
|
g_value_set_boxed (gvalue, PointerFromWrapper(value));
|
|
1492
1492
|
else
|
|
1493
1493
|
g_value_set_static_boxed (gvalue, PointerFromWrapper(value));
|
|
@@ -1508,7 +1508,7 @@ bool V8ToGValue(GValue *gvalue, Local<Value> value, bool mustCopy) {
|
|
|
1508
1508
|
return true;
|
|
1509
1509
|
}
|
|
1510
1510
|
|
|
1511
|
-
Local<Value> GValueToV8(const GValue *gvalue,
|
|
1511
|
+
Local<Value> GValueToV8(const GValue *gvalue, ResourceOwnership ownership) {
|
|
1512
1512
|
// by-value types
|
|
1513
1513
|
if (G_VALUE_HOLDS_BOOLEAN (gvalue)) {
|
|
1514
1514
|
return New<v8::Boolean>(g_value_get_boolean (gvalue));
|
|
@@ -1555,7 +1555,7 @@ Local<Value> GValueToV8(const GValue *gvalue, bool mustCopy) {
|
|
|
1555
1555
|
Throw::InvalidGType(gtype);
|
|
1556
1556
|
return Nan::Null(); // FIXME(return a MaybeLocal instead?)
|
|
1557
1557
|
}
|
|
1558
|
-
Local<Value> obj = WrapperFromBoxed(info, g_value_get_boxed(gvalue),
|
|
1558
|
+
Local<Value> obj = WrapperFromBoxed(info, g_value_get_boxed(gvalue), ownership);
|
|
1559
1559
|
g_base_info_unref(info);
|
|
1560
1560
|
return obj;
|
|
1561
1561
|
} else if (G_VALUE_HOLDS_PARAM (gvalue)) {
|
package/src/value.h
CHANGED
|
@@ -11,23 +11,29 @@ using v8::Local;
|
|
|
11
11
|
|
|
12
12
|
namespace GNodeJS {
|
|
13
13
|
|
|
14
|
+
enum ResourceOwnership {
|
|
15
|
+
kNone,
|
|
16
|
+
kCopy,
|
|
17
|
+
kTransfer
|
|
18
|
+
};
|
|
19
|
+
|
|
14
20
|
Local<Value> GListToV8 (GITypeInfo *info, GList *glist);
|
|
15
21
|
Local<Value> GSListToV8 (GITypeInfo *info, GSList *glist);
|
|
16
22
|
Local<Value> GHashToV8 (GITypeInfo *info, GHashTable *hash);
|
|
17
23
|
Local<Value> ArrayToV8 (GITypeInfo *info, gpointer data, long length = -1);
|
|
18
|
-
Local<Value> GErrorToV8 (GITypeInfo *type_info, GError *err);
|
|
19
|
-
Local<Value> GIArgumentToV8 (GITypeInfo *type_info, GIArgument *argument, long length = -1,
|
|
24
|
+
Local<Value> GErrorToV8 (GITypeInfo *type_info, GError *err, ResourceOwnership ownership = kNone);
|
|
25
|
+
Local<Value> GIArgumentToV8 (GITypeInfo *type_info, GIArgument *argument, long length = -1, ResourceOwnership ownership = kNone);
|
|
20
26
|
long GIArgumentToLength(GITypeInfo *type_info, GIArgument *arg, bool is_pointer);
|
|
21
27
|
|
|
22
|
-
bool
|
|
28
|
+
bool V8ToGIArgumentInterface (GIBaseInfo *gi_info, GIArgument *argument, Local<Value> value);
|
|
23
29
|
bool V8ToGIArgument (GITypeInfo *type_info, GIArgument *argument, Local<Value> value, bool may_be_null);
|
|
24
30
|
bool V8ToOutGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> value, bool may_be_null);
|
|
25
31
|
void FreeGIArgument (GITypeInfo *type_info, GIArgument *argument, GITransfer transfer = GI_TRANSFER_EVERYTHING, GIDirection direction = GI_DIRECTION_OUT);
|
|
26
32
|
void FreeGIArgumentArray (GITypeInfo *type_info, GIArgument *arg, GITransfer transfer = GI_TRANSFER_EVERYTHING, GIDirection direction = GI_DIRECTION_OUT, long length = -1);
|
|
27
33
|
bool CanConvertV8ToGIArgument (GITypeInfo *type_info, Local<Value> value, bool may_be_null);
|
|
28
34
|
|
|
29
|
-
bool V8ToGValue(GValue *gvalue, Local<Value> value,
|
|
30
|
-
Local<Value> GValueToV8(const GValue *gvalue,
|
|
35
|
+
bool V8ToGValue(GValue *gvalue, Local<Value> value, ResourceOwnership ownership = kNone);
|
|
36
|
+
Local<Value> GValueToV8(const GValue *gvalue, ResourceOwnership ownership = kNone);
|
|
31
37
|
bool CanConvertV8ToGValue(GValue *gvalue, Local<Value> value);
|
|
32
38
|
|
|
33
39
|
bool ValueHasInternalField (Local<Value> value);
|