/usr/share/cjs-1.0/overrides/GObject.js is in libcjs0 2.2.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | // application/javascript;version=1.8
// Copyright 2011 Jasper St. Pierre
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
const Lang = imports.lang;
const Gi = imports._gi;
let GObject;
const GObjectMeta = new Lang.Class({
Name: 'GObjectClass',
Extends: Lang.Class,
_init: function(params) {
this.parent(params);
// retrieve all parameters and remove them from params before chaining
let properties = params.Properties;
let signals = params.Signals;
let ifaces = params.Implements;
delete params.Properties;
delete params.Signals;
delete params.Implements;
if (properties) {
for (let prop in properties) {
Gi.register_property(this.prototype, properties[prop]);
}
}
if (signals) {
for (let signalName in signals) {
let obj = signals[signalName];
let flags = (obj.flags !== undefined) ? obj.flags : GObject.SignalFlags.RUN_FIRST;
let accumulator = (obj.accumulator !== undefined) ? obj.accumulator : GObject.AccumulatorType.NONE;
let rtype = (obj.return_type !== undefined) ? obj.return_type : GObject.TYPE_NONE;
let paramtypes = (obj.param_types !== undefined) ? obj.param_types : [];
try {
obj.signal_id = Gi.signal_new(this.prototype, signalName, flags, accumulator, rtype, paramtypes);
} catch(e) {
throw new TypeError('Invalid signal ' + signal_name + ': ' + e.message);
}
}
}
if (ifaces) {
for (let i = 0; i < ifaces.length; i++)
Gi.add_interface(this.prototype, ifaces[i]);
}
for (let prop in params) {
let value = this.prototype[prop];
if (typeof value === 'function') {
if (prop.slice(0, 6) == 'vfunc_') {
Gi.hook_up_vfunc(this.prototype, prop.slice(6), value);
} else if (prop.slice(0, 3) == 'on_') {
let id = GObject.signal_lookup(prop.slice(3).replace('_', '-'), this.$gtype);
if (id != 0) {
GObject.signal_override_class_closure(id, this.$gtype, function() {
let argArray = Array.prototype.slice.call(arguments);
let emitter = argArray.shift();
value.apply(emitter, argArray);
});
}
}
}
}
},
_isValidClass: function(klass) {
let proto = klass.prototype;
if (!proto)
return false;
// If proto == GObject.Object.prototype, then
// proto.__proto__ is Object, so "proto instanceof GObject.Object"
// will return false.
return proto == GObject.Object.prototype ||
proto instanceof GObject.Object;
},
// If we want an object with a custom JSClass, we can't just
// use a function. We have to use a custom constructor here.
_construct: function(params) {
if (!params.Name)
throw new TypeError("Classes require an explicit 'Name' parameter.");
let name = params.Name;
let gtypename;
if (params.GTypeName)
gtypename = params.GTypeName;
else
gtypename = 'Gjs_' + params.Name;
if (!params.Extends)
params.Extends = GObject.Object;
let parent = params.Extends;
if (!this._isValidClass(parent))
throw new TypeError('GObject.Class used with invalid base class (is ' + parent + ')');
let newClass = Gi.register_type(parent.prototype, gtypename);
// See Class.prototype._construct in lang.js for the reasoning
// behind this direct __proto__ set.
newClass.__proto__ = this.constructor.prototype;
newClass.__super__ = parent;
newClass._init.apply(newClass, arguments);
Object.defineProperty(newClass.prototype, '__metaclass__',
{ writable: false,
configurable: false,
enumerable: false,
value: this.constructor });
return newClass;
}
});
function _init() {
GObject = this;
this.TYPE_NONE = GObject.type_from_name('void');
this.TYPE_INTERFACE = GObject.type_from_name('GInterface');
this.TYPE_CHAR = GObject.type_from_name('gchar');
this.TYPE_UCHAR = GObject.type_from_name('guchar');
this.TYPE_BOOLEAN = GObject.type_from_name('gboolean');
this.TYPE_INT = GObject.type_from_name('gint');
this.TYPE_UINT = GObject.type_from_name('guint');
this.TYPE_LONG = GObject.type_from_name('glong');
this.TYPE_ULONG = GObject.type_from_name('gulong');
this.TYPE_INT64 = GObject.type_from_name('gint64');
this.TYPE_UINT64 = GObject.type_from_name('guint64');
this.TYPE_ENUM = GObject.type_from_name('GEnum');
this.TYPE_FLAGS = GObject.type_from_name('GFlags');
this.TYPE_FLOAT = GObject.type_from_name('gfloat');
this.TYPE_DOUBLE = GObject.type_from_name('gdouble');
this.TYPE_STRING = GObject.type_from_name('gchararray');
this.TYPE_POINTER = GObject.type_from_name('gpointer');
this.TYPE_BOXED = GObject.type_from_name('GBoxed');
this.TYPE_PARAM = GObject.type_from_name('GParam');
this.TYPE_OBJECT = GObject.type_from_name('GObject');
this.TYPE_GTYPE = GObject.type_from_name('GType');
this.TYPE_VARIANT = GObject.type_from_name('GVariant');
this.TYPE_UNICHAR = this.TYPE_UINT;
this.ParamSpec.char = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_CHAR,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.uchar = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_UCHAR,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.int = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_INT,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.uint = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_UINT,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.long = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_LONG,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.ulong = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_ULONG,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.int64 = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_INT64,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.uint64 = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_UINT64,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.float = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_FLOAT,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.boolean = function(name, nick, blurb, flags, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_BOOLEAN,
nick, blurb, flags, default_value);
};
this.ParamSpec.flags = function(name, nick, blurb, flags, flags_type, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_FLAGS,
nick, blurb, flags, flags_type, default_value);
};
this.ParamSpec.enum = function(name, nick, blurb, flags, enum_type, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_ENUM,
nick, blurb, flags, enum_type, default_value);
};
this.ParamSpec.double = function(name, nick, blurb, flags, minimum, maximum, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_DOUBLE,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.string = function(name, nick, blurb, flags, default_value) {
return GObject.ParamSpec._new_internal(name, GObject.TYPE_STRING,
nick, blurb, flags, default_value);
};
this.Class = GObjectMeta;
this.Object.prototype.__metaclass__ = this.Class;
// For compatibility with Lang.Class... we need a _construct
// or the Lang.Class constructor will fail.
this.Object.prototype._construct = function() {
this._init.apply(this, arguments);
return this;
};
// fake enum for signal accumulators, keep in sync with gi/object.c
this.AccumulatorType = {
NONE: 0,
FIRST_WINS: 1,
TRUE_HANDLED: 2
};
}
|