-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSIL.Box.js
More file actions
69 lines (58 loc) · 1.94 KB
/
Copy pathJSIL.Box.js
File metadata and controls
69 lines (58 loc) · 1.94 KB
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
JSIL.MakeClass("System.Object", "JSIL.Box", true, ["TValue"], function ($) {
function prepareInterfaceCaller(interfaceMethod) {
return function() { return interfaceMethod.apply(this.value, arguments); };
}
$.SetValue("__IsBox__", true);
$.Method({ Static: false, Public: true }, ".ctor",
(new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TValue", "JSIL.Box")], [])),
function _ctor(value) {
this.value = value;
}
);
$.RawMethod(true, "$addTypeMethods",
function $addTypeMethods(ctor, type) {
var ctor = ctor.prototype;
var type = type.prototype;
//var initType = new ctor(null);
for (var key in type) {
if (type.hasOwnProperty(key) && !(key in ctor)) {
var obj = type[key];
if (typeof (obj) == "function") {
ctor[key] = prepareInterfaceCaller(obj);
}
}
}
}
);
$.RawMethod(false, "valueOf",
function valueOf() {
return this.value.valueOf();
}
);
$.RawMethod(false, "toString",
function toString() {
return this.value.toString();
}
);
$.RawMethod(false, "GetHashCode",
function Box_GetHashCode() {
return JSIL.ObjectHashCode(this.value, true, this.TValue);
}
);
$.RawMethod(true, "IsBoxedOfType",
function isBoxedOfType(value, type) {
return value !== null && value !== undefined && (value.__IsBox__ || false) && value.TValue.__TypeId__ === type.__TypeId__;
}
);
$.Method({ Static: false, Public: true }, "Object.Equals",
new JSIL.MethodSignature($.Boolean, [$.Object], []),
function Box_Equals(other) {
// TODO: Implement Equals method for primitive types and call that method.
if (this.value !== null && other == null) {
return false;
}
return this.value.valueOf() === other.valueOf();
}
);
$.Field({ Public: false, Static: false, ReadOnly: true }, "value", new JSIL.GenericParameter("TValue", "JSIL.Box"));
});