[gjs] lang: Fix chaining up to interface methods w/args
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] lang: Fix chaining up to interface methods w/args
- Date: Fri, 31 Jul 2015 02:52:09 +0000 (UTC)
commit ea6decf10280c1db0cceb5f19827d02874b21c7c
Author: Philip Chimento <philip endlessm com>
Date: Tue Jul 28 16:04:01 2015 -0700
lang: Fix chaining up to interface methods w/args
Calling Interface.some_method(this, arg) from inside the implementation
of an interface did not work correctly.
https://bugzilla.gnome.org/show_bug.cgi?id=752984
installed-tests/js/testInterface.js | 14 ++++++++++++++
modules/lang.js | 2 +-
2 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/installed-tests/js/testInterface.js b/installed-tests/js/testInterface.js
index db370f7..d634e76 100644
--- a/installed-tests/js/testInterface.js
+++ b/installed-tests/js/testInterface.js
@@ -16,6 +16,10 @@ const AnInterface = new Lang.Interface({
return 'AnInterface.optionalGeneric()';
},
+ argumentGeneric: function (arg) {
+ return 'AnInterface.argumentGeneric(' + arg + ')';
+ },
+
usesThis: function () {
return this._interfacePrivateMethod();
},
@@ -64,6 +68,10 @@ const ObjectImplementingAnInterface = new Lang.Class({
optionalGeneric: function () {
return AnInterface.optionalGeneric(this);
+ },
+
+ argumentGeneric: function (arg) {
+ return AnInterface.argumentGeneric(this, arg + ' (hello from class)');
}
});
@@ -160,6 +168,12 @@ function testObjectCanChainUpToInterface() {
JSUnit.assertEquals('AnInterface.optional()', obj.optional());
}
+function testObjectCanChainUpToInterfaceWithArguments() {
+ let obj = new ObjectImplementingAnInterface();
+ JSUnit.assertEquals('AnInterface.argumentGeneric(arg (hello from class))',
+ obj.argumentGeneric('arg'));
+}
+
function testObjectCanDeferToInterfaceGetter() {
let obj = new ObjectImplementingAnInterface();
JSUnit.assertEquals('AnInterface.some_prop getter', obj.some_prop);
diff --git a/modules/lang.js b/modules/lang.js
index 5179fd9..b9d16f4 100644
--- a/modules/lang.js
+++ b/modules/lang.js
@@ -463,7 +463,7 @@ Interface.prototype._init = function (params) {
if (typeof descriptor.value === 'function') {
let interfaceProto = this.prototype; // capture in closure
this[name] = function () {
- return interfaceProto[name].apply.apply(interfaceProto[name],
+ return interfaceProto[name].call.apply(interfaceProto[name],
arguments);
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]