forked from iskiselev/JSIL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSIL.References.js
More file actions
169 lines (132 loc) · 4.7 KB
/
Copy pathJSIL.References.js
File metadata and controls
169 lines (132 loc) · 4.7 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"use strict";
if (typeof (JSIL) === "undefined")
throw new Error("JSIL.Core is required");
if (!$jsilcore)
throw new Error("JSIL.Core is required");
JSIL.MakeClass("System.Object", "JSIL.Reference", true, [], function ($) {
var types = {};
var checkType = function Reference_CheckType (value) {
var type = this;
var isReference = JSIL.Reference.$Is(value, true);
if (!isReference)
return false;
var typeProto = Object.getPrototypeOf(type);
if (
(typeProto === JSIL.GenericParameter.prototype) ||
(typeProto === JSIL.PositionalGenericParameter.prototype)
) {
return true;
}
var refValue = value.get();
if ((type.__IsReferenceType__) && (refValue === null))
return true;
return type.$Is(refValue, false);
};
var of = function Reference_Of (type) {
if (typeof (type) === "undefined")
JSIL.RuntimeError("Undefined reference type");
var typeObject = JSIL.ResolveTypeReference(type)[1];
var elementName = JSIL.GetTypeName(typeObject);
var compositePublicInterface = types[elementName];
if (typeof (compositePublicInterface) === "undefined") {
var typeName = "ref " + elementName;
var compositeTypeObject = JSIL.CreateDictionaryObject($.Type);
compositePublicInterface = JSIL.CreateDictionaryObject(JSIL.Reference);
JSIL.SetValueProperty(compositePublicInterface, "__Type__", compositeTypeObject);
JSIL.SetValueProperty(compositeTypeObject, "__PublicInterface__", compositePublicInterface);
compositeTypeObject.__IsByRef__ = true;
var toStringImpl = function (context) {
return "ref " + typeObject.toString(context);
};
compositePublicInterface.prototype = JSIL.MakeProto(JSIL.Reference, compositeTypeObject, typeName, true, typeObject.__Context__);
JSIL.SetValueProperty(compositePublicInterface, "CheckType", checkType.bind(type));
JSIL.SetValueProperty(compositePublicInterface, "toString", function ReferencePublicInterface_ToString () {
return "<JSIL.Reference.Of(" + typeObject.toString() + ") Public Interface>";
});
JSIL.SetValueProperty(compositePublicInterface.prototype, "toString", toStringImpl);
JSIL.SetValueProperty(compositeTypeObject, "toString", toStringImpl);
JSIL.SetValueProperty(compositePublicInterface, "__FullName__", typeName);
JSIL.SetValueProperty(compositeTypeObject, "__FullName__", typeName);
JSIL.SetTypeId(
compositePublicInterface, compositeTypeObject, (
$.Type.__TypeId__ + "[" + JSIL.HashTypeArgumentArray([typeObject], typeObject.__Context__) + "]"
)
);
types[elementName] = compositePublicInterface;
}
return compositePublicInterface;
};
$.RawMethod(true, "Of$NoInitialize", of);
$.RawMethod(true, "Of", of);
$.RawMethod(false, "get_value",
function Reference_GetValue () {
JSIL.RuntimeError("Use of old-style reference.value");
}
);
$.RawMethod(false, "set_value",
function Reference_SetValue (value) {
JSIL.RuntimeError("Use of old-style reference.value = x");
}
);
$.Property({Static: false, Public: true }, "value");
});
JSIL.MakeClass("JSIL.Reference", "JSIL.BoxedVariable", true, [], function ($) {
$.RawMethod(false, ".ctor",
function BoxedVariable_ctor (value) {
this.$value = value;
}
);
$.RawMethod(false, "get",
function BoxedVariable_Get () {
return this.$value;
}
);
$.RawMethod(false, "set",
function BoxedVariable_Set (value) {
return this.$value = value;
}
);
});
JSIL.MakeClass("JSIL.Reference", "JSIL.MemberReference", true, [], function ($) {
$.RawMethod(false, ".ctor",
function MemberReference_ctor (object, memberName) {
this.object = object;
this.memberName = memberName;
}
);
$.RawMethod(false, "get",
function MemberReference_Get () {
return this.object[this.memberName];
}
);
$.RawMethod(false, "set",
function MemberReference_Set (value) {
return this.object[this.memberName] = value;
}
);
});
JSIL.MakeClass("JSIL.Reference", "JSIL.ArrayElementReference", true, [], function ($) {
$.RawMethod(false, ".ctor",
function ArrayElementReference_ctor (array, index) {
this.array = array;
this.index = index | 0;
}
);
$.RawMethod(false, "get",
function ArrayElementReference_Get () {
return this.array[this.index];
}
);
$.RawMethod(false, "set",
function ArrayElementReference_Set (value) {
return this.array[this.index] = value;
}
);
$.RawMethod(false, "retarget",
function ArrayElementReference_Retarget (array, index) {
this.array = array;
this.index = index | 0;
return this;
}
);
});