-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsltws-back.js
103 lines (92 loc) · 3 KB
/
sltws-back.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
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
/*
* Copyright © 2007 Chris K. Jester-Young.
*
* This file is part of Scriptlet Workshop.
*
* Scriptlet Workshop is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scriptlet Workshop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with Scriptlet Workshop. If not, see <http://www.gnu.org/licenses/>.
*/
function Backend() {
this.init = this.bootstrap_init;
}
Backend.prototype.method_sigs = {
init: ['applet'],
start: ['applet'],
paint: ['applet', 'g'],
stop: ['applet'],
destroy: ['applet'],
getAppletInfo: ['applet'],
getParameterInfo: ['applet']
};
Backend.prototype.invoke_method = function (method, func, args) {
try {
func.apply(this, args);
return true;
} catch (ex) {
delete this[method];
window.alert("Error running method " + method + ":" + ex.lineNumber
+ ": " + ex.message);
return false;
}
};
Backend.prototype.install_method = function (method, script) {
var func;
try {
func = Function.apply(null, this.method_sigs[method].concat(script));
this[method] = function () {return this.invoke_method(method, func,
arguments)};
return true;
} catch (ex) {
window.alert("Error compiling method " + method + ":" + ex.lineNumber
+ ": " + ex.message);
return false;
}
};
Backend.prototype.install_applet_method = function (method, applet) {
var id = applet.getParameter(method);
if (!id)
return true;
var element = window.document.getElementById(id);
if (!element) {
window.alert("Error installing method " + method
+ ": document element " + id + " does not exist");
return false;
}
var script = element.value;
if (!script)
return true;
return this.install_method(method, script);
};
Backend.prototype.uninstall_methods = function () {
for (var method in this.method_sigs)
delete this[method];
};
Backend.prototype.install_applet_methods = function (applet) {
var status = true;
for (var method in this.method_sigs)
status &= this.install_applet_method(method, applet);
if (!status)
this.uninstall_methods();
return status;
};
Backend.prototype.bootstrap_init = function (applet) {
delete this.init;
if (this.install_applet_methods(applet) && this.init) {
if (!this.init(applet)) {
this.uninstall_methods();
return false;
}
}
return true;
};
var backend = new Backend();