-
Notifications
You must be signed in to change notification settings - Fork 1
/
workaround-issue-4862.js
60 lines (51 loc) · 1.55 KB
/
workaround-issue-4862.js
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
// Workaround Meteor issue #4862 by registering handlers with
// Meteor.bindEnvironment effectively disabled.
"use strict";
/* globals Accounts */
// If meteor version >= 1.2, this issues is fixed, so do nothing.
if (Accounts._onLoginHook) {
return;
}
Accounts.validateLoginAttempt = wrapUnbound(Accounts.validateLoginAttempt);
Accounts.onLogin = wrapUnbound(Accounts.onLogin);
Accounts.onLoginFailure = wrapUnbound(Accounts.onLoginFailure);
// Return a function that will run the passed function with
// Meteor.bindEnvironment effectively disabled
function wrapUnbound(func) {
return function( /* arguments */ ) {
var self = this;
var saved = Meteor.bindEnvironment;
try {
Meteor.bindEnvironment = dontBindEnvironment;
return func.apply(self, arguments);
} finally {
Meteor.bindEnvironment = saved;
}
return;
};
}
// Copied from Meteor.bindEnvironment and removed all the env stuff.
function dontBindEnvironment(func, onException, _this) {
if (!onException || typeof(onException) === 'string') {
var description = onException || "callback of async function";
onException = function(error) {
Meteor._debug(
"Exception in " + description + ":",
error && error.stack || error
);
};
}
return function( /* arguments */ ) {
var args = _.toArray(arguments);
var runAndHandleExceptions = function() {
var ret;
try {
ret = func.apply(_this, args);
} catch (e) {
onException(e);
}
return ret;
};
return runAndHandleExceptions();
};
}