-
Notifications
You must be signed in to change notification settings - Fork 25
/
commonjs_wrapper.js.erb
73 lines (59 loc) · 2.27 KB
/
commonjs_wrapper.js.erb
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
<%# A CommonJS module as an ERB template, wrapping the GWT compiled output %>
(function(exports) {
if(typeof document === 'undefined')
var document = {};
if(typeof window === 'undefined')
var window = {};
if(!window.document)
window.document = document;
if(typeof navigator === 'undefined')
var navigator = {};
if(!navigator.userAgent)
navigator.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22';
function gwtapp() {};
<%= gwt_source %>
exports.RoundingMode = window.bigdecimal.RoundingMode;
exports.MathContext = window.bigdecimal.MathContext;
fix_and_export('BigDecimal');
fix_and_export('BigInteger');
// This is an unfortunate kludge because Java methods and constructors cannot accept vararg parameters.
function fix_and_export(class_name) {
var Src = window.bigdecimal[class_name];
var Fixed = Src;
if(Src.__init__) {
Fixed = function wrap_constructor() {
var args = Array.prototype.slice.call(arguments);
return Src.__init__(args);
};
Fixed.prototype = Src.prototype;
for (var a in Src)
if(Src.hasOwnProperty(a)) {
if((typeof Src[a] != 'function') || !a.match(/_va$/))
Fixed[a] = Src[a];
else {
var pub_name = a.replace(/_va$/, '');
Fixed[pub_name] = function wrap_classmeth () {
var args = Array.prototype.slice.call(arguments);
var m = wrap_classmeth.inner_method ? wrap_classmeth.inner_method : arguments.callee.inner_method;
return m.apply(this, [args]);
};
Fixed[pub_name].inner_method = Src[a];
}
}
}
var proto = Fixed.prototype;
for (var a in proto) {
if(proto.hasOwnProperty(a) && (typeof proto[a] == 'function') && a.match(/_va$/)) {
var pub_name = a.replace(/_va$/, '');
proto[pub_name] = function wrap_meth() {
var args = Array.prototype.slice.call(arguments);
var m = wrap_meth.inner_method ? wrap_meth.inner_method : arguments.callee.inner_method;
return m.apply(this, [args]);
};
proto[pub_name].inner_method = proto[a];
delete proto[a];
}
}
exports[class_name] = Fixed;
}
})(typeof exports !== 'undefined' ? exports : (typeof window !== 'undefined' ? window : {}));