Commit b3ab88a7 authored by Philip Chimento's avatar Philip Chimento 🚮

Merge branch 'wip/fmuellner/legacy-gtype-names' into 'master'

legacy: Ensure generated GType names are valid

See merge request GNOME/gjs!229
parents d32e4a94 e1ea03a0
Pipeline #30181 passed with stages
in 18 minutes and 14 seconds
......@@ -139,6 +139,8 @@ const Derived = GObject.registerClass(class Derived extends MyObject {
}
});
const Cla$$ = GObject.registerClass(class Cla$$ extends MyObject {});
const MyCustomInit = GObject.registerClass(class MyCustomInit extends GObject.Object {
_instance_init() {
this.foo = true;
......@@ -292,6 +294,13 @@ describe('GObject class with decorator', function () {
expect(derived.readwrite).toEqual('yes');
});
it('can have any valid class name', function () {
let obj = new Cla$$();
expect(obj instanceof Cla$$).toBeTruthy();
expect(obj instanceof MyObject).toBeTruthy();
});
it('calls its _instance_init() function while chaining up in constructor', function () {
let instance = new MyCustomInit();
expect(instance.foo).toBeTruthy();
......
......@@ -164,6 +164,11 @@ const Derived = new Lang.Class({
}
});
const OddlyNamed = new Lang.Class({
Name: 'Legacy.OddlyNamed',
Extends: MyObject
});
const MyCustomInit = new Lang.Class({
Name: 'MyCustomInit',
Extends: GObject.Object,
......@@ -316,6 +321,13 @@ describe('GObject class', function () {
expect(derived.readwrite).toEqual('yes');
});
it('can have any valid Lang.Class name', function () {
let obj = new OddlyNamed();
expect(obj instanceof OddlyNamed).toBeTruthy();
expect(obj instanceof MyObject).toBeTruthy();
});
it('calls its _instance_init() function while chaining up in constructor', function () {
let instance = new MyCustomInit();
expect(instance.foo).toBeTruthy();
......
......@@ -434,7 +434,7 @@ function defineGObjectLegacyObjects(GObject) {
if (params.GTypeName)
return params.GTypeName;
else
return 'Gjs_' + params.Name;
return 'Gjs_' + params.Name.replace(/[^a-z0-9_+-]/gi, '_');
}
function _getGObjectInterfaces(interfaces) {
......
......@@ -110,7 +110,7 @@ function _createSignals(gtype, signals) {
function _createGTypeName(klass) {
if (klass.hasOwnProperty(GTypeName))
return klass[GTypeName];
return `Gjs_${klass.name}`;
return `Gjs_${klass.name.replace(/[^a-z0-9+_-]/gi, '_')}`;
}
function _propertiesAsArray(klass) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment