mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 00:59:08 +02:00
pastojs: createCallback: store events in $events to create unique method pointers, issue #38845
git-svn-id: trunk@49331 -
This commit is contained in:
parent
dd9179043e
commit
f5d138eb08
39
utils/pas2js/dist/rtl.js
vendored
39
utils/pas2js/dist/rtl.js
vendored
@ -229,7 +229,10 @@ var rtl = {
|
|||||||
createCallback: function(scope, fn){
|
createCallback: function(scope, fn){
|
||||||
var cb;
|
var cb;
|
||||||
if (typeof(fn)==='string'){
|
if (typeof(fn)==='string'){
|
||||||
cb = function(){
|
if (!scope.$events) scope.$events = {};
|
||||||
|
cb = scope.$events[fn];
|
||||||
|
if (cb) return cb;
|
||||||
|
scope.$events[fn] = cb = function(){
|
||||||
return scope[fn].apply(scope,arguments);
|
return scope[fn].apply(scope,arguments);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@ -243,32 +246,38 @@ var rtl = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
createSafeCallback: function(scope, fn){
|
createSafeCallback: function(scope, fn){
|
||||||
var cb = function(){
|
var cb;
|
||||||
try{
|
if (typeof(fn)==='string'){
|
||||||
if (typeof(fn)==='string'){
|
if (!scope.$events) scope.$events = {};
|
||||||
|
cb = scope.$events[fn];
|
||||||
|
if (cb) return cb;
|
||||||
|
scope.$events[fn] = cb = function(){
|
||||||
|
try{
|
||||||
return scope[fn].apply(scope,arguments);
|
return scope[fn].apply(scope,arguments);
|
||||||
} else {
|
} catch (err) {
|
||||||
|
if (!rtl.handleUncaughtException(err)) throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
cb = function(){
|
||||||
|
try{
|
||||||
return fn.apply(scope,arguments);
|
return fn.apply(scope,arguments);
|
||||||
};
|
} catch (err) {
|
||||||
} catch (err) {
|
if (!rtl.handleUncaughtException(err)) throw err;
|
||||||
if (!rtl.handleUncaughtException(err)) throw err;
|
}
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
cb.scope = scope;
|
cb.scope = scope;
|
||||||
cb.fn = fn;
|
cb.fn = fn;
|
||||||
return cb;
|
return cb;
|
||||||
},
|
},
|
||||||
|
|
||||||
cloneCallback: function(cb){
|
|
||||||
return rtl.createCallback(cb.scope,cb.fn);
|
|
||||||
},
|
|
||||||
|
|
||||||
eqCallback: function(a,b){
|
eqCallback: function(a,b){
|
||||||
// can be a function or a function wrapper
|
// can be a function or a function wrapper
|
||||||
if (a==b){
|
if (a===b){
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return (a!=null) && (b!=null) && (a.fn) && (a.scope===b.scope) && (a.fn==b.fn);
|
return (a!=null) && (b!=null) && (a.fn) && (a.scope===b.scope) && (a.fn===b.fn);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user