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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
// **********************************************************************
//
// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
//
// Ice.Object
//
// Using IceObject in this file to avoid collisions with the native Object.
//
var Ice = require("../Ice/ModuleRegistry").Ice;
Ice.__M.require(module,
[
"../Ice/Class",
"../Ice/DispatchStatus",
"../Ice/Exception",
"../Ice/FormatType",
"../Ice/StreamHelpers",
"../Ice/OptionalFormat"
]);
var Class = Ice.Class;
var nextAddress = 0;
var IceObject = Class({
__init__: function()
{
// Fake Address used as the hashCode for this object instance.
this.__address = nextAddress++;
},
hashCode: function()
{
return this.__address;
},
ice_isA: function(s, current)
{
return this.__mostDerivedType().__ids.indexOf(s) >= 0;
},
ice_ping: function(current)
{
},
ice_ids: function(current)
{
return this.__mostDerivedType().__ids;
},
ice_id: function(current)
{
return this.__mostDerivedType().__id;
},
toString: function()
{
return "[object " + this.ice_id() + "]";
},
ice_preMarshal: function()
{
},
ice_postUnmarshal: function()
{
},
__write: function(os)
{
os.startWriteObject(null);
__writeImpl(this, os, this.__mostDerivedType());
os.endWriteObject();
},
__read: function(is)
{
is.startReadObject();
__readImpl(this, is, this.__mostDerivedType());
is.endReadObject(false);
},
ice_instanceof: function(T)
{
if(T)
{
if(this instanceof T)
{
return true;
}
return this.__mostDerivedType().__instanceof(T);
}
return false;
},
//
// __mostDerivedType returns the the most derived Ice generated class. This is
// necessary because the user might extend Slice generated classes. The user
// class extensions don't have __id, __ids, __instanceof etc static members so
// the implementation of ice_id, ice_ids and ice_instanceof would fail trying
// to access those members of the user defined class. Instead, ice_id, ice_ids
// and ice_instanceof call __mostDerivedType to get the most derived Ice class.
//
// The __mostDerivedType is overriden by each Slice generated class, see the
// Slice.defineObject method implementation for details.
//
__mostDerivedType: function()
{
return IceObject;
},
//
// The default implementation of equals compare references.
//
equals: function(other)
{
return this === other;
}
});
//
// These methods are used for object parameters.
//
IceObject.write = function(os, v)
{
os.writeObject(v);
};
IceObject.writeOpt = function(os, tag, v)
{
os.writeOptObject(tag, v);
};
IceObject.read = function(is)
{
var v = { value: null };
is.readObject(function(o) { v.value = o; }, IceObject);
return v;
};
IceObject.readOpt = function(is, tag)
{
var v = { value: undefined };
is.readOptObject(tag, function(o) { v.value = o; }, IceObject);
return v;
};
IceObject.ice_staticId = function()
{
return IceObject.__id;
};
IceObject.__instanceof = function(T)
{
if(T === this)
{
return true;
}
for(var i in this.__implements)
{
if(this.__implements[i].__instanceof(T))
{
return true;
}
}
if(this.__parent)
{
return this.__parent.__instanceof(T);
}
return false;
};
IceObject.__ids = ["::Ice::Object"];
IceObject.__id = IceObject.__ids[0];
IceObject.__compactId = -1;
IceObject.__preserved = false;
//
// Private methods
//
var __writeImpl = function(obj, os, type)
{
//
// The __writeImpl method is a recursive method that goes down the
// class hierarchy to marshal each slice of the class using the
// generated __writeMemberImpl method.
//
if(type === undefined || type === IceObject)
{
return; // Don't marshal anything for IceObject
}
os.startWriteSlice(type.__id, type.__compactId, type.__parent === IceObject);
if(type.prototype.__writeMemberImpl)
{
type.prototype.__writeMemberImpl.call(obj, os);
}
os.endWriteSlice();
__writeImpl(obj, os, type.__parent);
};
var __readImpl = function(obj, is, type)
{
//
// The __readImpl method is a recursive method that goes down the
// class hierarchy to marshal each slice of the class using the
// generated __readMemberImpl method.
//
if(type === undefined || type === IceObject)
{
return; // Don't marshal anything for IceObject
}
is.startReadSlice();
if(type.prototype.__readMemberImpl)
{
type.prototype.__readMemberImpl.call(obj, is);
}
is.endReadSlice();
__readImpl(obj, is, type.__parent);
};
var __writePreserved = function(os)
{
//
// For Slice classes which are marked "preserved", the implementation of this method
// replaces the Ice.Object.prototype.__write method.
//
os.startWriteObject(this.__slicedData);
__writeImpl(this, os, this.__mostDerivedType());
os.endWriteObject();
};
var __readPreserved = function(is)
{
//
// For Slice classes which are marked "preserved", the implementation of this method
// replaces the Ice.Object.prototype.__read method.
//
is.startReadObject();
__readImpl(this, is, this.__mostDerivedType());
this.__slicedData = is.endReadObject(true);
};
Ice.Object = IceObject;
var Slice = Ice.Slice;
Slice.defineLocalObject = function(constructor, base)
{
var obj = constructor || function(){};
if(base !== undefined)
{
obj.prototype = new base();
obj.__parent = base;
obj.prototype.constructor = constructor;
}
return obj;
};
Slice.defineObject = function(constructor, base, intfs, scope, ids, compactId, writeImpl, readImpl, preserved)
{
var obj = constructor || function(){};
obj.prototype = new base();
obj.__parent = base;
obj.__ids = ids;
obj.__id = ids[scope];
obj.__compactId = compactId;
obj.__instanceof = IceObject.__instanceof;
obj.__implements = intfs;
//
// These methods are used for object parameters.
//
obj.write = function(os, v)
{
os.writeObject(v);
};
obj.writeOpt = function(os, tag, v)
{
os.writeOptObject(tag, v);
};
obj.read = function(is)
{
var v = { value: null };
is.readObject(function(o) { v.value = o; }, obj);
return v;
};
obj.readOpt = function(is, tag)
{
var v = { value: undefined };
is.readOptObject(tag, function(o) { v.value = o; }, obj);
return v;
};
obj.ice_staticId = function()
{
return ids[scope];
};
obj.prototype.constructor = obj;
obj.prototype.__mostDerivedType = function() { return obj; };
if(preserved)
{
obj.prototype.__write = __writePreserved;
obj.prototype.__read = __readPreserved;
}
obj.prototype.__writeMemberImpl = writeImpl;
obj.prototype.__readMemberImpl = readImpl;
return obj;
};
module.exports.Ice = Ice;
|