summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2022-01-20 21:00:26 -0800
committerPhilip Chimento <philip.chimento@gmail.com>2022-02-03 22:07:09 -0800
commitc4c6fd328c3a6f4222ce46e627bea7da8498e629 (patch)
treefb28b7cb108c5287c2a43d92c0d41a4e5905fbe2
parent20da419bf09d0d73b4b08d58cbe2da9f22b13677 (diff)
downloadgjs-c4c6fd328c3a6f4222ce46e627bea7da8498e629.tar.gz
GLib: Add MAXINT64_BIGINT, MININT64_BIGINT, MAXUINT64_BIGINT constants
The normal GLib.MAXINT64 constants will log a warning when used because their values won't fit into a JS Number. Add overrides that give these values as purely BigInt constants.
-rw-r--r--installed-tests/js/testGObjectClass.js29
-rw-r--r--modules/core/overrides/GLib.js6
2 files changed, 15 insertions, 20 deletions
diff --git a/installed-tests/js/testGObjectClass.js b/installed-tests/js/testGObjectClass.js
index ee07b61d..92e60b8c 100644
--- a/installed-tests/js/testGObjectClass.js
+++ b/installed-tests/js/testGObjectClass.js
@@ -153,17 +153,6 @@ const MyCustomInit = GObject.registerClass(class MyCustomInit extends GObject.Ob
}
});
-const BigIntLimits = {
- int64: {
- min: -0x7fff_ffff_ffff_ffffn - 1n,
- max: 0x7fff_ffff_ffff_ffffn,
- },
- uint64: {
- min: 0n,
- max: 0xffff_ffff_ffff_ffffn,
- },
-};
-
const NoName = GObject.registerClass(class extends GObject.Object {});
describe('GObject class with decorator', function () {
@@ -381,26 +370,26 @@ describe('GObject class with decorator', function () {
Properties: {
'int64': GObject.ParamSpec.int64('int64', 'int64', 'int64',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
- BigIntLimits.int64.min, BigIntLimits.int64.max, 0),
+ GLib.MININT64_BIGINT, GLib.MAXINT64_BIGINT, 0),
},
}, class PropInt64 extends GObject.Object {});
- let int64 = BigIntLimits.int64.max - 5n;
+ let int64 = GLib.MAXINT64_BIGINT - 5n;
let obj = new PropInt64({int64});
expect(obj.int64).toEqual(Number(int64));
- int64 = BigIntLimits.int64.min + 555n;
+ int64 = GLib.MININT64_BIGINT + 555n;
obj = new PropInt64({int64});
expect(obj.int64).toEqual(Number(int64));
});
it('can have a default int64 property', function () {
- const defaultValue = BigIntLimits.int64.max - 1000n;
+ const defaultValue = GLib.MAXINT64_BIGINT - 1000n;
const PropInt64Init = GObject.registerClass({
Properties: {
'int64': GObject.ParamSpec.int64('int64', 'int64', 'int64',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
- BigIntLimits.int64.min, BigIntLimits.int64.max,
+ GLib.MININT64_BIGINT, GLib.MAXINT64_BIGINT,
defaultValue),
},
}, class PropDefaultInt64Init extends GObject.Object {});
@@ -414,22 +403,22 @@ describe('GObject class with decorator', function () {
Properties: {
'uint64': GObject.ParamSpec.uint64('uint64', 'uint64', 'uint64',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
- 0, BigIntLimits.uint64.max, 0),
+ 0, GLib.MAXUINT64_BIGINT, 0),
},
}, class PropUint64 extends GObject.Object {});
- const uint64 = BigIntLimits.uint64.max - 5n;
+ const uint64 = GLib.MAXUINT64_BIGINT - 5n;
const obj = new PropUint64({uint64});
expect(obj.uint64).toEqual(Number(uint64));
});
it('can have a default uint64 property', function () {
- const defaultValue = BigIntLimits.uint64.max;
+ const defaultValue = GLib.MAXUINT64_BIGINT;
const PropUint64Init = GObject.registerClass({
Properties: {
'uint64': GObject.ParamSpec.uint64('uint64', 'uint64', 'uint64',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
- 0n, BigIntLimits.uint64.max, defaultValue),
+ 0n, GLib.MAXUINT64_BIGINT, defaultValue),
},
}, class PropDefaultUint64Init extends GObject.Object {});
diff --git a/modules/core/overrides/GLib.js b/modules/core/overrides/GLib.js
index 74db4596..cb8f177e 100644
--- a/modules/core/overrides/GLib.js
+++ b/modules/core/overrides/GLib.js
@@ -261,6 +261,12 @@ function _init() {
GLib = this;
+ // For convenience in property min or max values, since GLib.MAXINT64 and
+ // friends will log a warning when used
+ this.MAXINT64_BIGINT = 0x7fff_ffff_ffff_ffffn;
+ this.MININT64_BIGINT = -this.MAXINT64_BIGINT - 1n;
+ this.MAXUINT64_BIGINT = 0xffff_ffff_ffff_ffffn;
+
// small HACK: we add a matches() method to standard Errors so that
// you can do "if (e.matches(Ns.FooError, Ns.FooError.SOME_CODE))"
// without checking instanceof