Codebase list gjs / 2d103ac
Merge branch 'february-maintenance' into 'master' February maintenance See merge request GNOME/gjs!735 Philip Chimento 2 years ago
7 changed file(s) with 42 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
+0
-25
examples/clutter.js less more
0 // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
1 // SPDX-FileCopyrightText: 2008 litl, LLC
2
3 const Clutter = imports.gi.Clutter;
4
5 Clutter.init(null);
6
7 const stage = new Clutter.Stage({visible: true});
8
9 let texture = new Clutter.Texture({
10 filename: 'test.jpg',
11 reactive: true,
12 });
13
14 texture.connect('button-press-event', () => {
15 log('Clicked!');
16 return Clutter.EVENT_STOP;
17 });
18
19 const [, color] = Clutter.Color.from_string('Black');
20 stage.background_color = color;
21
22 stage.add_child(texture);
23
24 Clutter.main();
262262 const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
263263 JS::RootedObject array_obj(cx, &value.toObject());
264264
265 if (!JS_HasPropertyById(cx, array_obj, atoms.length(), &found_length)) {
266 throw_invalid_argument(cx, value, type_info, arg_name, arg_type);
265 if (!JS_HasPropertyById(cx, array_obj, atoms.length(), &found_length))
267266 return false;
268 }
269
270267 if (!found_length) {
271268 throw_invalid_argument(cx, value, type_info, arg_name, arg_type);
272269 return false;
338335 }
339336
340337 [[nodiscard]] static GHashTable* create_hash_table_for_key_type(
341 GITypeInfo* key_param_info) {
338 GITypeTag key_type) {
342339 /* Don't use key/value destructor functions here, because we can't
343340 * construct correct ones in general if the value type is complex.
344341 * Rely on the type-aware g_argument_release functions. */
345
346 GITypeTag key_type = g_type_info_get_tag(key_param_info);
347
348342 if (key_type == GI_TYPE_TAG_UTF8 || key_type == GI_TYPE_TAG_FILENAME)
349343 return g_hash_table_new(g_str_hash, g_str_equal);
350344 return g_hash_table_new(NULL, NULL);
374368 * possible, otherwise giving the location of an allocated key in @pointer_out.
375369 */
376370 GJS_JSAPI_RETURN_CONVENTION
377 static bool
378 value_to_ghashtable_key(JSContext *cx,
379 JS::HandleValue value,
380 GITypeInfo *type_info,
381 gpointer *pointer_out)
382 {
383 GITypeTag type_tag = g_type_info_get_tag((GITypeInfo*) type_info);
371 static bool value_to_ghashtable_key(JSContext* cx, JS::HandleValue value,
372 GITypeTag type_tag, void** pointer_out) {
384373 bool unsupported = false;
385374
386 g_return_val_if_fail(value.isString() || value.isInt32(), false);
375 g_assert((value.isString() || value.isInt32()) &&
376 "keys from JS_Enumerate must be non-symbol property keys");
387377
388378 gjs_debug_marshal(GJS_DEBUG_GFUNCTION,
389379 "Converting JS::Value to GHashTable key %s",
535525 if (!JS_Enumerate(context, props, &ids))
536526 return false;
537527
528 GITypeTag key_tag = g_type_info_get_tag(key_param_info);
538529 GjsAutoPointer<GHashTable, GHashTable, g_hash_table_destroy> result =
539 create_hash_table_for_key_type(key_param_info);
530 create_hash_table_for_key_type(key_tag);
540531
541532 JS::RootedValue key_js(context), val_js(context);
542533 JS::RootedId cur_id(context);
547538
548539 if (!JS_IdToValue(context, cur_id, &key_js) ||
549540 // Type check key type.
550 !value_to_ghashtable_key(context, key_js, key_param_info,
551 &key_ptr) ||
541 !value_to_ghashtable_key(context, key_js, key_tag, &key_ptr) ||
552542 !JS_GetPropertyById(context, props, cur_id, &val_js) ||
553543 // Type check and convert value to a C type
554544 !gjs_value_to_g_argument(context, val_js, val_param_info, nullptr,
684674 }
685675
686676 GJS_JSAPI_RETURN_CONVENTION
687 static bool
688 gjs_string_to_intarray(JSContext *context,
689 JS::HandleString str,
690 GITypeInfo *param_info,
691 void **arr_p,
692 size_t *length)
693 {
694 GITypeTag element_type;
677 static bool gjs_string_to_intarray(JSContext* context, JS::HandleString str,
678 GITypeTag element_type, void** arr_p,
679 size_t* length) {
695680 char16_t *result16;
696
697 element_type = g_type_info_get_tag(param_info);
698681
699682 switch (element_type) {
700683 case GI_TYPE_TAG_INT8:
11191102 } else if (value.isString()) {
11201103 /* Allow strings as int8/uint8/int16/uint16 arrays */
11211104 JS::RootedString str(context, value.toString());
1122 if (!gjs_string_to_intarray(context, str, param_info, contents, length_p))
1105 GITypeTag element_tag = g_type_info_get_tag(param_info);
1106 if (!gjs_string_to_intarray(context, str, element_tag, contents, length_p))
11231107 return false;
11241108 } else {
11251109 JS::RootedObject array_obj(context, &value.toObject());
1126 const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
11271110 GITypeTag element_type = g_type_info_get_tag(param_info);
11281111 if (JS_IsUint8Array(array_obj) && (element_type == GI_TYPE_TAG_INT8 ||
11291112 element_type == GI_TYPE_TAG_UINT8)) {
11301113 GBytes* bytes = gjs_byte_array_get_bytes(array_obj);
11311114 *contents = g_bytes_unref_to_data(bytes, length_p);
1132 } else if (JS_HasPropertyById(context, array_obj, atoms.length(),
1133 &found_length) &&
1134 found_length) {
1115 return true;
1116 }
1117
1118 const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
1119 if (!JS_HasPropertyById(context, array_obj, atoms.length(),
1120 &found_length))
1121 return false;
1122 if (found_length) {
11351123 guint32 length;
11361124
11371125 if (!gjs_object_require_converted_property(
550550
551551 const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
552552 JS::RootedObject array_obj(context, &value.toObject());
553 if (JS_HasPropertyById(context, array_obj, atoms.length(),
554 &found_length) &&
555 found_length) {
553 if (!JS_HasPropertyById(context, array_obj, atoms.length(),
554 &found_length))
555 return false;
556 if (found_length) {
556557 guint32 length;
557558
558559 if (!gjs_object_require_converted_property(
537537 if (!str)
538538 return "<null string>";
539539 if (!JS_StringIsLinear(str)) {
540 std::ostringstream out("<non-flat string of length ");
540 std::ostringstream out("<non-flat string of length ",
541 std::ios_base::ate);
541542 out << JS_GetStringLength(str) << '>';
542543 return out.str();
543544 }
761761 };
762762 testInParameter('ghashtable_uint64', uint64Dict);
763763 });
764
765 it('symbol keys are ignored', function () {
766 const symbolDict = {
767 [Symbol('foo')]: 2,
768 '-1': 1,
769 0: 0,
770 1: -1,
771 2: -2,
772 };
773 expect(() => GIMarshallingTests.ghashtable_int_none_in(symbolDict)).not.toThrow();
774 });
764775 });
765776
766777 describe('GValue', function () {
7777 expect(Regress[method](-42)).toBe(-42);
7878
7979 if (['float', 'double'].includes(type)) {
80 expect(Number.isNaN(Regress[method](undefined))).toBeTruthy();
80 expect(Regress[method](undefined)).toBeNaN();
8181 expect(Regress[method](42.42)).toBeCloseTo(42.42);
8282 expect(Regress[method](-42.42)).toBeCloseTo(-42.42);
8383 } else {
155155 elif test "$1" = "CPPLINT"; then
156156 do_Print_Labels 'C/C++ Linter report '
157157
158 cpplint --quiet $(find . -name \*.cpp -or -name \*.c -or -name \*.h | sort) 2>&1 >/dev/null | \
158 cpplint --quiet $(find . -name \*.cpp -or -name \*.h | sort) 2>&1 >/dev/null | \
159159 tee "$save_dir"/analysis/head-report.txt | \
160160 sed -E -e 's/:[0-9]+:/:LINE:/' -e 's/ +/ /g' \
161161 > /cwd/head-report.txt
171171 exit 0
172172 fi
173173 git checkout ci-upstream-base
174 cpplint --quiet $(find . -name \*.cpp -or -name \*.c -or -name \*.h | sort) 2>&1 >/dev/null | \
174 cpplint --quiet $(find . -name \*.cpp -or -name \*.h | sort) 2>&1 >/dev/null | \
175175 tee "$save_dir"/analysis/base-report.txt | \
176176 sed -E -e 's/:[0-9]+:/:LINE:/' -e 's/ +/ /g' \
177177 > /cwd/base-report.txt