object-input-stream 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/ast.d.ts +276 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +3 -0
- package/dist/ast.js.map +1 -0
- package/dist/classes.d.ts +86 -0
- package/dist/classes.d.ts.map +1 -0
- package/dist/classes.js +193 -0
- package/dist/classes.js.map +1 -0
- package/dist/exceptions.d.ts +66 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +154 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +13 -0
- package/dist/internal.js.map +1 -0
- package/dist/object-input-stream.d.ts +236 -0
- package/dist/object-input-stream.d.ts.map +1 -0
- package/dist/object-input-stream.js +1082 -0
- package/dist/object-input-stream.js.map +1 -0
- package/dist/ois-ast.d.ts +69 -0
- package/dist/ois-ast.d.ts.map +1 -0
- package/dist/ois-ast.js +1019 -0
- package/dist/ois-ast.js.map +1 -0
- package/package.json +1 -1
- package/src/object-input-stream.ts +17 -8
package/dist/ois-ast.js
ADDED
|
@@ -0,0 +1,1019 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Forgive me father, for I have sinned.
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
22
|
+
var useValue = arguments.length > 2;
|
|
23
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
24
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
25
|
+
}
|
|
26
|
+
return useValue ? value : void 0;
|
|
27
|
+
};
|
|
28
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
29
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
30
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
31
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
32
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
33
|
+
var _, done = false;
|
|
34
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
35
|
+
var context = {};
|
|
36
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
37
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
38
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
39
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
40
|
+
if (kind === "accessor") {
|
|
41
|
+
if (result === void 0) continue;
|
|
42
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
43
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
44
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
45
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
46
|
+
}
|
|
47
|
+
else if (_ = accept(result)) {
|
|
48
|
+
if (kind === "field") initializers.unshift(_);
|
|
49
|
+
else descriptor[key] = _;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
53
|
+
done = true;
|
|
54
|
+
};
|
|
55
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
56
|
+
var ownKeys = function(o) {
|
|
57
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
58
|
+
var ar = [];
|
|
59
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
60
|
+
return ar;
|
|
61
|
+
};
|
|
62
|
+
return ownKeys(o);
|
|
63
|
+
};
|
|
64
|
+
return function (mod) {
|
|
65
|
+
if (mod && mod.__esModule) return mod;
|
|
66
|
+
var result = {};
|
|
67
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
68
|
+
__setModuleDefault(result, mod);
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
})();
|
|
72
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
73
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
|
+
};
|
|
75
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
|
+
exports.ObjectInputStreamAST = void 0;
|
|
77
|
+
const _1 = __importDefault(require("."));
|
|
78
|
+
const exc = __importStar(require("./exceptions"));
|
|
79
|
+
let ObjectInputStreamAST = (() => {
|
|
80
|
+
var _a;
|
|
81
|
+
let _classSuper = _1.default;
|
|
82
|
+
let _instanceExtraInitializers = [];
|
|
83
|
+
let _readBoolean_decorators;
|
|
84
|
+
let _readByte_decorators;
|
|
85
|
+
let _readUnsignedByte_decorators;
|
|
86
|
+
let _readChar_decorators;
|
|
87
|
+
let _readShort_decorators;
|
|
88
|
+
let _readUnsignedShort_decorators;
|
|
89
|
+
let _readInt_decorators;
|
|
90
|
+
let _readLong_decorators;
|
|
91
|
+
let _readFloat_decorators;
|
|
92
|
+
let _readDouble_decorators;
|
|
93
|
+
let _readTC_decorators;
|
|
94
|
+
let _read1_decorators;
|
|
95
|
+
let _read_decorators;
|
|
96
|
+
let _readBlockHeader_decorators;
|
|
97
|
+
let _readUTF_decorators;
|
|
98
|
+
let _readLongUTF_decorators;
|
|
99
|
+
let _readUTFBody_decorators;
|
|
100
|
+
let _readReset_decorators;
|
|
101
|
+
let _readNull_decorators;
|
|
102
|
+
let _readHandle_decorators;
|
|
103
|
+
let _readClass_decorators;
|
|
104
|
+
let _readClassDesc_decorators;
|
|
105
|
+
let _readProxyDesc_decorators;
|
|
106
|
+
let _readNonProxyDesc_decorators;
|
|
107
|
+
let _readString_decorators;
|
|
108
|
+
let _readArray_decorators;
|
|
109
|
+
let _readEnum_decorators;
|
|
110
|
+
let _readOrdinaryObject_decorators;
|
|
111
|
+
let _readExternalData_decorators;
|
|
112
|
+
let _readSerialData_decorators;
|
|
113
|
+
let _readClassDataWr_decorators;
|
|
114
|
+
let _readClassDataNoWr_decorators;
|
|
115
|
+
let _readFatalException_decorators;
|
|
116
|
+
let _readAnnotation_decorators;
|
|
117
|
+
let _readFields_decorators;
|
|
118
|
+
let _readFieldDescs_decorators;
|
|
119
|
+
let _readFieldDesc_decorators;
|
|
120
|
+
return _a = class ObjectInputStreamAST extends _classSuper {
|
|
121
|
+
constructor(data, options) {
|
|
122
|
+
super(data, options);
|
|
123
|
+
this.cst = __runInitializers(this, _instanceExtraInitializers);
|
|
124
|
+
this.finalized = false;
|
|
125
|
+
this.ast = null;
|
|
126
|
+
// How many resets happened so far
|
|
127
|
+
this.epoch = 0;
|
|
128
|
+
const rootNode = {
|
|
129
|
+
type: "root",
|
|
130
|
+
span: { start: 0, end: data.length },
|
|
131
|
+
value: null,
|
|
132
|
+
parent: null,
|
|
133
|
+
children: [],
|
|
134
|
+
};
|
|
135
|
+
rootNode.children = [{
|
|
136
|
+
type: "magic",
|
|
137
|
+
span: { start: 0, end: 2 },
|
|
138
|
+
value: this.STREAM_MAGIC,
|
|
139
|
+
parent: rootNode,
|
|
140
|
+
children: [],
|
|
141
|
+
}, {
|
|
142
|
+
type: "version",
|
|
143
|
+
span: { start: 2, end: 4 },
|
|
144
|
+
value: this.STREAM_VERSION,
|
|
145
|
+
parent: rootNode,
|
|
146
|
+
children: [],
|
|
147
|
+
}, {
|
|
148
|
+
type: "contents",
|
|
149
|
+
span: { start: 4, end: data.length },
|
|
150
|
+
value: null,
|
|
151
|
+
parent: rootNode,
|
|
152
|
+
children: [],
|
|
153
|
+
}];
|
|
154
|
+
this.cst = rootNode;
|
|
155
|
+
this.cstStack = [this.cst, this.cst.children[2]];
|
|
156
|
+
}
|
|
157
|
+
getAST() {
|
|
158
|
+
if (this.offset < this.data.length) {
|
|
159
|
+
throw new Error("Not done reading");
|
|
160
|
+
}
|
|
161
|
+
if (this.finalized) {
|
|
162
|
+
assert(this.ast !== null);
|
|
163
|
+
return this.ast;
|
|
164
|
+
}
|
|
165
|
+
this.finalized = true;
|
|
166
|
+
return cstToAst(this.cst, this.data);
|
|
167
|
+
}
|
|
168
|
+
readBoolean() { return super.readBoolean(); }
|
|
169
|
+
readByte() { return super.readByte(); }
|
|
170
|
+
readUnsignedByte() { return super.readUnsignedByte(); }
|
|
171
|
+
readChar() { return super.readChar(); }
|
|
172
|
+
readShort() { return super.readShort(); }
|
|
173
|
+
readUnsignedShort() { return super.readUnsignedShort(); }
|
|
174
|
+
readInt() { return super.readInt(); }
|
|
175
|
+
readLong() { return super.readLong(); }
|
|
176
|
+
readFloat() { return super.readFloat(); }
|
|
177
|
+
readDouble() { return super.readDouble(); }
|
|
178
|
+
readTC() { return super.readTC(); }
|
|
179
|
+
read1() { return super.read1(); }
|
|
180
|
+
read(len) { return super.read(len); }
|
|
181
|
+
readBlockHeader() { return super.readBlockHeader(); }
|
|
182
|
+
readUTF() { return super.readUTF(); }
|
|
183
|
+
readLongUTF() { return super.readLongUTF(); }
|
|
184
|
+
readUTFBody(byteLength) { return super.readUTFBody(byteLength); }
|
|
185
|
+
reset() {
|
|
186
|
+
assert(this.cstStack.length > 0);
|
|
187
|
+
const currNode = this.cstStack[this.cstStack.length - 1];
|
|
188
|
+
assert(currNode.type === "object/reset" || currNode.type === "object/exception");
|
|
189
|
+
currNode.value = ++this.epoch;
|
|
190
|
+
return super.reset();
|
|
191
|
+
}
|
|
192
|
+
newHandle(obj) {
|
|
193
|
+
assert(this.cstStack.length > 0);
|
|
194
|
+
const currNode = this.cstStack[this.cstStack.length - 1];
|
|
195
|
+
assert(currNode.type === "object/class"
|
|
196
|
+
|| currNode.type === "proxy-desc"
|
|
197
|
+
|| currNode.type === "non-proxy-desc"
|
|
198
|
+
|| currNode.type === "object/string"
|
|
199
|
+
|| currNode.type === "object/array"
|
|
200
|
+
|| currNode.type === "object/enum"
|
|
201
|
+
|| currNode.type === "object/instance");
|
|
202
|
+
const handle = super.newHandle(obj);
|
|
203
|
+
currNode.handle = { epoch: this.epoch, handle: handle };
|
|
204
|
+
return handle;
|
|
205
|
+
}
|
|
206
|
+
readReset() { return super.readReset(); }
|
|
207
|
+
readNull() { return super.readNull(); }
|
|
208
|
+
readHandle() {
|
|
209
|
+
assert(this.cstStack.length > 0);
|
|
210
|
+
const currNode = this.cstStack[this.cstStack.length - 1];
|
|
211
|
+
assert(currNode.type === "object/handle");
|
|
212
|
+
currNode.value = this.epoch;
|
|
213
|
+
return super.readHandle();
|
|
214
|
+
}
|
|
215
|
+
readClass() { return super.readClass(); }
|
|
216
|
+
readClassDesc() { return super.readClassDesc(); }
|
|
217
|
+
readProxyDesc() { return super.readProxyDesc(); }
|
|
218
|
+
readNonProxyDesc() { return super.readNonProxyDesc(); }
|
|
219
|
+
readString() { return super.readString(); }
|
|
220
|
+
readArray() { return super.readArray(); }
|
|
221
|
+
readEnum() { return super.readEnum(); }
|
|
222
|
+
readOrdinaryObject() { return super.readOrdinaryObject(); }
|
|
223
|
+
readExternalData(obj, desc) { return super.readExternalData(obj, desc); }
|
|
224
|
+
readSerialData(obj, desc) { return super.readSerialData(obj, desc); }
|
|
225
|
+
readClassDataWr(obj, desc, readMethod) {
|
|
226
|
+
return super.readClassDataWr(obj, desc, readMethod);
|
|
227
|
+
}
|
|
228
|
+
readClassDataNoWr(obj, desc, readMethod) { return super.readClassDataNoWr(obj, desc, readMethod); }
|
|
229
|
+
readFatalException() { return super.readFatalException(); }
|
|
230
|
+
readAnnotation() { return super.readAnnotation(); }
|
|
231
|
+
readFields() { return super.readFields(); }
|
|
232
|
+
readFieldDescs(className) { return super.readFieldDescs(className); }
|
|
233
|
+
readFieldDesc(className) { return super.readFieldDesc(className); }
|
|
234
|
+
},
|
|
235
|
+
(() => {
|
|
236
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
237
|
+
_readBoolean_decorators = [traceMethod("primitive/boolean", { keep: true })];
|
|
238
|
+
_readByte_decorators = [traceMethod("primitive/byte", { keep: true })];
|
|
239
|
+
_readUnsignedByte_decorators = [traceMethod("primitive/unsigned-byte", { keep: true })];
|
|
240
|
+
_readChar_decorators = [traceMethod("primitive/char", { keep: true })];
|
|
241
|
+
_readShort_decorators = [traceMethod("primitive/short", { keep: true })];
|
|
242
|
+
_readUnsignedShort_decorators = [traceMethod("primitive/unsigned-short", { keep: true })];
|
|
243
|
+
_readInt_decorators = [traceMethod("primitive/int", { keep: true })];
|
|
244
|
+
_readLong_decorators = [traceMethod("primitive/long", { keep: true })];
|
|
245
|
+
_readFloat_decorators = [traceMethod("primitive/float", { keep: true })];
|
|
246
|
+
_readDouble_decorators = [traceMethod("primitive/double", { keep: true })];
|
|
247
|
+
_readTC_decorators = [traceMethod("tc", { keep: true })];
|
|
248
|
+
_read1_decorators = [traceMethod("read1", { keep: true })];
|
|
249
|
+
_read_decorators = [traceMethod("read")];
|
|
250
|
+
_readBlockHeader_decorators = [traceMethod("block-header", { keep: true })];
|
|
251
|
+
_readUTF_decorators = [traceMethod("utf", { keep: true })];
|
|
252
|
+
_readLongUTF_decorators = [traceMethod("long-utf", { keep: true })];
|
|
253
|
+
_readUTFBody_decorators = [traceMethod("utf-body", { keep: true })];
|
|
254
|
+
_readReset_decorators = [traceMethod("object/reset")];
|
|
255
|
+
_readNull_decorators = [traceMethod("object/null")];
|
|
256
|
+
_readHandle_decorators = [traceMethod("object/handle")];
|
|
257
|
+
_readClass_decorators = [traceMethod("object/class")];
|
|
258
|
+
_readClassDesc_decorators = [traceMethod("object/class-desc")];
|
|
259
|
+
_readProxyDesc_decorators = [traceMethod("proxy-desc")];
|
|
260
|
+
_readNonProxyDesc_decorators = [traceMethod("non-proxy-desc")];
|
|
261
|
+
_readString_decorators = [traceMethod("object/string", { keep: true })];
|
|
262
|
+
_readArray_decorators = [traceMethod("object/array")];
|
|
263
|
+
_readEnum_decorators = [traceMethod("object/enum")];
|
|
264
|
+
_readOrdinaryObject_decorators = [traceMethod("object/instance")];
|
|
265
|
+
_readExternalData_decorators = [traceMethod("external-data")];
|
|
266
|
+
_readSerialData_decorators = [traceMethod("serial-data")];
|
|
267
|
+
_readClassDataWr_decorators = [traceMethod("class-data-wr")];
|
|
268
|
+
_readClassDataNoWr_decorators = [traceMethod("class-data-no-wr")];
|
|
269
|
+
_readFatalException_decorators = [traceMethod("object/exception")];
|
|
270
|
+
_readAnnotation_decorators = [traceMethod("annotation")];
|
|
271
|
+
_readFields_decorators = [traceMethod("values")];
|
|
272
|
+
_readFieldDescs_decorators = [traceMethod("fields")];
|
|
273
|
+
_readFieldDesc_decorators = [traceMethod("field")];
|
|
274
|
+
__esDecorate(_a, null, _readBoolean_decorators, { kind: "method", name: "readBoolean", static: false, private: false, access: { has: obj => "readBoolean" in obj, get: obj => obj.readBoolean }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
275
|
+
__esDecorate(_a, null, _readByte_decorators, { kind: "method", name: "readByte", static: false, private: false, access: { has: obj => "readByte" in obj, get: obj => obj.readByte }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
276
|
+
__esDecorate(_a, null, _readUnsignedByte_decorators, { kind: "method", name: "readUnsignedByte", static: false, private: false, access: { has: obj => "readUnsignedByte" in obj, get: obj => obj.readUnsignedByte }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
277
|
+
__esDecorate(_a, null, _readChar_decorators, { kind: "method", name: "readChar", static: false, private: false, access: { has: obj => "readChar" in obj, get: obj => obj.readChar }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
278
|
+
__esDecorate(_a, null, _readShort_decorators, { kind: "method", name: "readShort", static: false, private: false, access: { has: obj => "readShort" in obj, get: obj => obj.readShort }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
279
|
+
__esDecorate(_a, null, _readUnsignedShort_decorators, { kind: "method", name: "readUnsignedShort", static: false, private: false, access: { has: obj => "readUnsignedShort" in obj, get: obj => obj.readUnsignedShort }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
280
|
+
__esDecorate(_a, null, _readInt_decorators, { kind: "method", name: "readInt", static: false, private: false, access: { has: obj => "readInt" in obj, get: obj => obj.readInt }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
281
|
+
__esDecorate(_a, null, _readLong_decorators, { kind: "method", name: "readLong", static: false, private: false, access: { has: obj => "readLong" in obj, get: obj => obj.readLong }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
282
|
+
__esDecorate(_a, null, _readFloat_decorators, { kind: "method", name: "readFloat", static: false, private: false, access: { has: obj => "readFloat" in obj, get: obj => obj.readFloat }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
283
|
+
__esDecorate(_a, null, _readDouble_decorators, { kind: "method", name: "readDouble", static: false, private: false, access: { has: obj => "readDouble" in obj, get: obj => obj.readDouble }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
284
|
+
__esDecorate(_a, null, _readTC_decorators, { kind: "method", name: "readTC", static: false, private: false, access: { has: obj => "readTC" in obj, get: obj => obj.readTC }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
285
|
+
__esDecorate(_a, null, _read1_decorators, { kind: "method", name: "read1", static: false, private: false, access: { has: obj => "read1" in obj, get: obj => obj.read1 }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
286
|
+
__esDecorate(_a, null, _read_decorators, { kind: "method", name: "read", static: false, private: false, access: { has: obj => "read" in obj, get: obj => obj.read }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
287
|
+
__esDecorate(_a, null, _readBlockHeader_decorators, { kind: "method", name: "readBlockHeader", static: false, private: false, access: { has: obj => "readBlockHeader" in obj, get: obj => obj.readBlockHeader }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
288
|
+
__esDecorate(_a, null, _readUTF_decorators, { kind: "method", name: "readUTF", static: false, private: false, access: { has: obj => "readUTF" in obj, get: obj => obj.readUTF }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
289
|
+
__esDecorate(_a, null, _readLongUTF_decorators, { kind: "method", name: "readLongUTF", static: false, private: false, access: { has: obj => "readLongUTF" in obj, get: obj => obj.readLongUTF }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
290
|
+
__esDecorate(_a, null, _readUTFBody_decorators, { kind: "method", name: "readUTFBody", static: false, private: false, access: { has: obj => "readUTFBody" in obj, get: obj => obj.readUTFBody }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
291
|
+
__esDecorate(_a, null, _readReset_decorators, { kind: "method", name: "readReset", static: false, private: false, access: { has: obj => "readReset" in obj, get: obj => obj.readReset }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
292
|
+
__esDecorate(_a, null, _readNull_decorators, { kind: "method", name: "readNull", static: false, private: false, access: { has: obj => "readNull" in obj, get: obj => obj.readNull }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
293
|
+
__esDecorate(_a, null, _readHandle_decorators, { kind: "method", name: "readHandle", static: false, private: false, access: { has: obj => "readHandle" in obj, get: obj => obj.readHandle }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
294
|
+
__esDecorate(_a, null, _readClass_decorators, { kind: "method", name: "readClass", static: false, private: false, access: { has: obj => "readClass" in obj, get: obj => obj.readClass }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
295
|
+
__esDecorate(_a, null, _readClassDesc_decorators, { kind: "method", name: "readClassDesc", static: false, private: false, access: { has: obj => "readClassDesc" in obj, get: obj => obj.readClassDesc }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
296
|
+
__esDecorate(_a, null, _readProxyDesc_decorators, { kind: "method", name: "readProxyDesc", static: false, private: false, access: { has: obj => "readProxyDesc" in obj, get: obj => obj.readProxyDesc }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
297
|
+
__esDecorate(_a, null, _readNonProxyDesc_decorators, { kind: "method", name: "readNonProxyDesc", static: false, private: false, access: { has: obj => "readNonProxyDesc" in obj, get: obj => obj.readNonProxyDesc }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
298
|
+
__esDecorate(_a, null, _readString_decorators, { kind: "method", name: "readString", static: false, private: false, access: { has: obj => "readString" in obj, get: obj => obj.readString }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
299
|
+
__esDecorate(_a, null, _readArray_decorators, { kind: "method", name: "readArray", static: false, private: false, access: { has: obj => "readArray" in obj, get: obj => obj.readArray }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
300
|
+
__esDecorate(_a, null, _readEnum_decorators, { kind: "method", name: "readEnum", static: false, private: false, access: { has: obj => "readEnum" in obj, get: obj => obj.readEnum }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
301
|
+
__esDecorate(_a, null, _readOrdinaryObject_decorators, { kind: "method", name: "readOrdinaryObject", static: false, private: false, access: { has: obj => "readOrdinaryObject" in obj, get: obj => obj.readOrdinaryObject }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
302
|
+
__esDecorate(_a, null, _readExternalData_decorators, { kind: "method", name: "readExternalData", static: false, private: false, access: { has: obj => "readExternalData" in obj, get: obj => obj.readExternalData }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
303
|
+
__esDecorate(_a, null, _readSerialData_decorators, { kind: "method", name: "readSerialData", static: false, private: false, access: { has: obj => "readSerialData" in obj, get: obj => obj.readSerialData }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
304
|
+
__esDecorate(_a, null, _readClassDataWr_decorators, { kind: "method", name: "readClassDataWr", static: false, private: false, access: { has: obj => "readClassDataWr" in obj, get: obj => obj.readClassDataWr }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
305
|
+
__esDecorate(_a, null, _readClassDataNoWr_decorators, { kind: "method", name: "readClassDataNoWr", static: false, private: false, access: { has: obj => "readClassDataNoWr" in obj, get: obj => obj.readClassDataNoWr }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
306
|
+
__esDecorate(_a, null, _readFatalException_decorators, { kind: "method", name: "readFatalException", static: false, private: false, access: { has: obj => "readFatalException" in obj, get: obj => obj.readFatalException }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
307
|
+
__esDecorate(_a, null, _readAnnotation_decorators, { kind: "method", name: "readAnnotation", static: false, private: false, access: { has: obj => "readAnnotation" in obj, get: obj => obj.readAnnotation }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
308
|
+
__esDecorate(_a, null, _readFields_decorators, { kind: "method", name: "readFields", static: false, private: false, access: { has: obj => "readFields" in obj, get: obj => obj.readFields }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
309
|
+
__esDecorate(_a, null, _readFieldDescs_decorators, { kind: "method", name: "readFieldDescs", static: false, private: false, access: { has: obj => "readFieldDescs" in obj, get: obj => obj.readFieldDescs }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
310
|
+
__esDecorate(_a, null, _readFieldDesc_decorators, { kind: "method", name: "readFieldDesc", static: false, private: false, access: { has: obj => "readFieldDesc" in obj, get: obj => obj.readFieldDesc }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
311
|
+
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
312
|
+
})(),
|
|
313
|
+
_a;
|
|
314
|
+
})();
|
|
315
|
+
exports.ObjectInputStreamAST = ObjectInputStreamAST;
|
|
316
|
+
function traceMethod(type, options) {
|
|
317
|
+
return (method) => {
|
|
318
|
+
return function decorated(...args) {
|
|
319
|
+
if (!(this instanceof ObjectInputStreamAST))
|
|
320
|
+
throw new exc.InternalError();
|
|
321
|
+
if (this.finalized)
|
|
322
|
+
throw new exc.NotActiveException();
|
|
323
|
+
const parent = (this.cstStack?.length > 0) ? this.cstStack[this.cstStack.length - 1] : null;
|
|
324
|
+
const node = {
|
|
325
|
+
type: type,
|
|
326
|
+
span: { start: this.offset, end: this.offset },
|
|
327
|
+
value: null,
|
|
328
|
+
parent: parent,
|
|
329
|
+
children: [],
|
|
330
|
+
};
|
|
331
|
+
if (parent !== null) {
|
|
332
|
+
parent.children.push(node);
|
|
333
|
+
this.cstStack.push(node);
|
|
334
|
+
}
|
|
335
|
+
let result;
|
|
336
|
+
try {
|
|
337
|
+
result = method.apply(this, args);
|
|
338
|
+
if (options?.keep)
|
|
339
|
+
node.value = result;
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
catch (e) {
|
|
343
|
+
node.error = e;
|
|
344
|
+
throw e;
|
|
345
|
+
}
|
|
346
|
+
finally {
|
|
347
|
+
node.span.end = this.offset;
|
|
348
|
+
if (parent !== null) {
|
|
349
|
+
const popped = this.cstStack.pop();
|
|
350
|
+
assert(popped === node);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function assert(predicate, message = "assertion error") {
|
|
357
|
+
if (!predicate)
|
|
358
|
+
throw new exc.InternalError(message);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Convert a concrete-syntax-tree to an abstract-syntax-tree.
|
|
362
|
+
* This function is destructive to the CST.
|
|
363
|
+
*/
|
|
364
|
+
function cstToAst(cst, data) {
|
|
365
|
+
hoistBlockHeaders(cst);
|
|
366
|
+
hoistResets(cst);
|
|
367
|
+
// Remove calls to "read" from primitives and strings
|
|
368
|
+
removeNodesWhere(cst, node => node.type === "read" && node.parent !== null && (node.parent.type.startsWith("primitive/") || node.parent.type === "utf-body"));
|
|
369
|
+
// Remove calls to "readByte" from tc
|
|
370
|
+
removeNodesWhere(cst, node => node.type === "primitive/byte" && node.parent?.type === "tc");
|
|
371
|
+
// Remove empty nodes that shouldn't be empty
|
|
372
|
+
removeNodesWhere(cst, node => {
|
|
373
|
+
if (node.span.start < node.span.end)
|
|
374
|
+
return false;
|
|
375
|
+
return (node.type !== "contents"
|
|
376
|
+
&& node.type !== "serial-data"
|
|
377
|
+
&& node.type !== "external-data"
|
|
378
|
+
&& node.type !== "class-data-no-wr");
|
|
379
|
+
}, { recursive: true });
|
|
380
|
+
handleBlocks(cst);
|
|
381
|
+
const root = trasformCSTBottomUp(cst, cstToAstNode);
|
|
382
|
+
assert(root.type === "root");
|
|
383
|
+
return { root, data };
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Instead of headers being children of primitives, make them their siblings.
|
|
387
|
+
* They will later become their parents.
|
|
388
|
+
*/
|
|
389
|
+
function hoistBlockHeaders(cst) {
|
|
390
|
+
const headers = [...traverseCST(cst)].filter(node => node.type === "block-header");
|
|
391
|
+
for (const header of headers) {
|
|
392
|
+
while (header.parent !== null && !canContainContent(header.parent)) {
|
|
393
|
+
assert(header.parent.children[0] === header);
|
|
394
|
+
hoistFirstChild(header);
|
|
395
|
+
}
|
|
396
|
+
assert(header.parent !== null);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function pp(node, indent = 0) {
|
|
400
|
+
let res = " ".repeat(indent) + node.type;
|
|
401
|
+
if (node.type === "object")
|
|
402
|
+
res += "/" + node.objectType;
|
|
403
|
+
if (node.type === "primitive")
|
|
404
|
+
res += "/" + node.dataType;
|
|
405
|
+
if (node.value !== null)
|
|
406
|
+
res += ": " + node.value;
|
|
407
|
+
if (node.children !== null && node.children.length > 0)
|
|
408
|
+
res += "\n" + node.children.map(c => pp(c, indent + 1)).join("\n");
|
|
409
|
+
return res;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Instead of resets being children of objects / block headers, make them their siblings/
|
|
413
|
+
*/
|
|
414
|
+
function hoistResets(cst) {
|
|
415
|
+
const resets = [...traverseCST(cst)].filter(node => node.type === "object/reset");
|
|
416
|
+
for (const reset of resets) {
|
|
417
|
+
while (reset.parent !== null && !canContainContent(reset.parent)) {
|
|
418
|
+
assert(reset.parent.children[0] === reset);
|
|
419
|
+
hoistFirstChild(reset);
|
|
420
|
+
}
|
|
421
|
+
assert(reset.parent !== null);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function canContainContent(node) {
|
|
425
|
+
if (node === null)
|
|
426
|
+
return false;
|
|
427
|
+
const type = node.type;
|
|
428
|
+
return type === "class-data-no-wr" || type === "class-data-wr" || type === "contents" || type === "external-data";
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Manipulate the CST s.t `child` becomes its parent's sibling.
|
|
432
|
+
* `child` must be its parent's first child.
|
|
433
|
+
*/
|
|
434
|
+
function hoistFirstChild(child) {
|
|
435
|
+
const parent = child.parent;
|
|
436
|
+
assert(parent !== null);
|
|
437
|
+
assert(parent.children.indexOf(child) === 0);
|
|
438
|
+
const grandParent = parent.parent;
|
|
439
|
+
assert(grandParent !== null);
|
|
440
|
+
const parentIndex = grandParent.children.indexOf(parent);
|
|
441
|
+
assert(parentIndex !== -1);
|
|
442
|
+
parent.children.shift();
|
|
443
|
+
parent.span.start = child.span.end;
|
|
444
|
+
grandParent.children.splice(parentIndex, 0, child);
|
|
445
|
+
child.parent = grandParent;
|
|
446
|
+
}
|
|
447
|
+
function handleBlocks(cst) {
|
|
448
|
+
// resets that are in between block headers
|
|
449
|
+
const blockResets = removeNodesWhere(cst, node => {
|
|
450
|
+
if (node.type !== "object/reset")
|
|
451
|
+
return false;
|
|
452
|
+
assert(node.parent !== null);
|
|
453
|
+
const siblings = node.parent.children;
|
|
454
|
+
const index = siblings.indexOf(node);
|
|
455
|
+
assert(0 <= index);
|
|
456
|
+
const nextRight = siblings.slice(index + 1).find(node => node.type !== "object/reset");
|
|
457
|
+
const nextLeft = siblings.slice(0, index).reverse().find(node => node.type !== "object/reset");
|
|
458
|
+
return (nextRight !== undefined && nextRight.type === "block-header"
|
|
459
|
+
&& nextLeft !== undefined && nextLeft.type === "block-header");
|
|
460
|
+
}, { recursive: true });
|
|
461
|
+
const blocks = removeNodesWhere(cst, node => node.type === "block-header", { recursive: true })
|
|
462
|
+
.filter(header => header.span.start < header.span.end)
|
|
463
|
+
.map(header => {
|
|
464
|
+
assert(header.value !== -1);
|
|
465
|
+
let parent = header.parent;
|
|
466
|
+
assert(parent !== null);
|
|
467
|
+
assert(typeof header.value === "number");
|
|
468
|
+
const span = { start: header.span.start, end: header.span.end + header.value };
|
|
469
|
+
return { header, parent, span };
|
|
470
|
+
});
|
|
471
|
+
if (blocks.length === 0)
|
|
472
|
+
return;
|
|
473
|
+
// Group blocks into contiguous sequences
|
|
474
|
+
let currSequence = [blocks[0]];
|
|
475
|
+
const blockSequences = [currSequence];
|
|
476
|
+
for (let i = 1; i < blocks.length; i++) {
|
|
477
|
+
let prev = currSequence[currSequence.length - 1];
|
|
478
|
+
while (blockResets.length > 0 && blockResets[0].span.start === prev.span.end) {
|
|
479
|
+
const reset = blockResets.shift();
|
|
480
|
+
assert(reset !== undefined);
|
|
481
|
+
currSequence.push(reset);
|
|
482
|
+
prev = reset;
|
|
483
|
+
}
|
|
484
|
+
const curr = blocks[i];
|
|
485
|
+
if (prev.span.end === curr.span.start) {
|
|
486
|
+
currSequence.push(curr);
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
currSequence = [curr];
|
|
490
|
+
blockSequences.push(currSequence);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
assert(blockResets.length === 0);
|
|
494
|
+
for (const sequence of blockSequences) {
|
|
495
|
+
assert(sequence.length > 0);
|
|
496
|
+
assert(sequence.every(block => block.parent === sequence[0].parent));
|
|
497
|
+
const parent = sequence[0].parent;
|
|
498
|
+
assert(parent !== null);
|
|
499
|
+
const start = sequence[0].span.start;
|
|
500
|
+
const end = sequence[sequence.length - 1].span.end;
|
|
501
|
+
// Get the values stored in each sequence
|
|
502
|
+
const values = removeNodesWhere(cst, node => (node.parent === parent && start <= node.span.start && node.span.end <= end), { recursive: true });
|
|
503
|
+
assert(values.every(v => v.type.startsWith("primitive/") || v.type === "utf" || v.type === "read"));
|
|
504
|
+
values.forEach(v => removeNodesWhere(v, node => node.type === "block-header", { recursive: true }));
|
|
505
|
+
const sequenceNode = {
|
|
506
|
+
type: "blockdata-sequence",
|
|
507
|
+
span: { start, end },
|
|
508
|
+
parent: null,
|
|
509
|
+
value: values,
|
|
510
|
+
children: [],
|
|
511
|
+
};
|
|
512
|
+
sequenceNode.children = sequence.map((seqItem) => {
|
|
513
|
+
if ("type" in seqItem && seqItem.type === "object/reset") {
|
|
514
|
+
return seqItem;
|
|
515
|
+
}
|
|
516
|
+
const { parent, header, span } = seqItem;
|
|
517
|
+
const result = {
|
|
518
|
+
type: "blockdata",
|
|
519
|
+
span: span,
|
|
520
|
+
parent: sequenceNode,
|
|
521
|
+
value: null,
|
|
522
|
+
children: [...header.children],
|
|
523
|
+
};
|
|
524
|
+
result.children.push({
|
|
525
|
+
type: "read",
|
|
526
|
+
span: { start: header.span.end, end: span.end },
|
|
527
|
+
value: null,
|
|
528
|
+
parent: result,
|
|
529
|
+
children: [],
|
|
530
|
+
});
|
|
531
|
+
return result;
|
|
532
|
+
});
|
|
533
|
+
insertNode(parent, sequenceNode);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function removeNodesWhere(cst, condition, options) {
|
|
537
|
+
const toRemove = [];
|
|
538
|
+
for (const node of traverseCST(cst)) {
|
|
539
|
+
if (condition(node)) {
|
|
540
|
+
toRemove.push(node);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
for (const node of toRemove)
|
|
544
|
+
removeNode(node, options);
|
|
545
|
+
return toRemove;
|
|
546
|
+
}
|
|
547
|
+
function removeNode(node, options) {
|
|
548
|
+
assert(node.parent !== null);
|
|
549
|
+
const nodeIndex = node.parent.children.indexOf(node);
|
|
550
|
+
assert(nodeIndex !== -1);
|
|
551
|
+
if (options?.recursive) {
|
|
552
|
+
node.parent.children.splice(nodeIndex, 1);
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
for (const child of node.children) {
|
|
556
|
+
child.parent = node.parent;
|
|
557
|
+
}
|
|
558
|
+
node.parent.children.splice(nodeIndex, 1, ...node.children);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function insertNode(parent, child) {
|
|
562
|
+
assert(parent.span.start <= child.span.start && child.span.end <= parent.span.end);
|
|
563
|
+
child.parent = parent;
|
|
564
|
+
if (parent.children.length === 0) {
|
|
565
|
+
parent.children.push(child);
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
let inserted = false;
|
|
569
|
+
for (let i = 0; i <= parent.children.length; i++) {
|
|
570
|
+
const left = parent.children[i - 1];
|
|
571
|
+
const right = parent.children[i];
|
|
572
|
+
// Not overlapping
|
|
573
|
+
if (left !== undefined)
|
|
574
|
+
assert(child.span.end <= left.span.start || left.span.end <= child.span.start);
|
|
575
|
+
if (right !== undefined)
|
|
576
|
+
assert(child.span.end <= right.span.start || right.span.end <= child.span.start);
|
|
577
|
+
const leftGood = (left === undefined) || (left.span.end <= child.span.start);
|
|
578
|
+
const rightGood = (right === undefined) || (child.span.end <= right.span.start);
|
|
579
|
+
if (leftGood && rightGood) {
|
|
580
|
+
parent.children.splice(i, 0, child);
|
|
581
|
+
inserted = true;
|
|
582
|
+
break;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
assert(inserted);
|
|
586
|
+
}
|
|
587
|
+
function* traverseCST(cst) {
|
|
588
|
+
yield cst;
|
|
589
|
+
for (const child of cst.children)
|
|
590
|
+
yield* traverseCST(child);
|
|
591
|
+
}
|
|
592
|
+
function trasformCSTBottomUp(cst, transform) {
|
|
593
|
+
const children = cst.children.map(c => trasformCSTBottomUp(c, transform));
|
|
594
|
+
return transform(cst, children);
|
|
595
|
+
}
|
|
596
|
+
function cstToAstNode(node, children) {
|
|
597
|
+
if (node.type.startsWith("primitive/")) {
|
|
598
|
+
assert(children.length === 0);
|
|
599
|
+
const dataType = node.type.split("/", 2)[1];
|
|
600
|
+
const value = node.value;
|
|
601
|
+
const span = node.span;
|
|
602
|
+
switch (dataType) {
|
|
603
|
+
case "boolean":
|
|
604
|
+
assert(typeof value === "boolean");
|
|
605
|
+
return { type: "primitive", dataType, value, span, children: null };
|
|
606
|
+
case "char":
|
|
607
|
+
assert(typeof value === "string");
|
|
608
|
+
return { type: "primitive", dataType, value, span, children: null };
|
|
609
|
+
case "long":
|
|
610
|
+
assert(typeof value === "bigint");
|
|
611
|
+
return { type: "primitive", dataType, value, span, children: null };
|
|
612
|
+
case "byte":
|
|
613
|
+
case "unsigned-byte":
|
|
614
|
+
case "short":
|
|
615
|
+
case "unsigned-short":
|
|
616
|
+
case "int":
|
|
617
|
+
case "float":
|
|
618
|
+
case "double":
|
|
619
|
+
assert(typeof value === "number");
|
|
620
|
+
return { type: "primitive", dataType, value, span, children: null };
|
|
621
|
+
default:
|
|
622
|
+
throw new exc.InternalError(dataType);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
switch (node.type) {
|
|
626
|
+
case "root": {
|
|
627
|
+
assert(children.length === 3);
|
|
628
|
+
const magic = children[0];
|
|
629
|
+
const version = children[1];
|
|
630
|
+
const contents = children[2];
|
|
631
|
+
assert(magic.type === "magic");
|
|
632
|
+
assert(version.type === "version");
|
|
633
|
+
assert(contents.type === "contents");
|
|
634
|
+
return { type: "root", span: node.span, children: [magic, version, contents] };
|
|
635
|
+
}
|
|
636
|
+
case "magic": {
|
|
637
|
+
assert(children.length === 0);
|
|
638
|
+
return { type: "magic", span: node.span, value: _1.default.STREAM_MAGIC, children: null };
|
|
639
|
+
}
|
|
640
|
+
case "version": {
|
|
641
|
+
assert(children.length === 0);
|
|
642
|
+
return { type: "version", span: node.span, value: _1.default.STREAM_VERSION, children: null };
|
|
643
|
+
}
|
|
644
|
+
case "contents": {
|
|
645
|
+
assert(children.every(c => c.type === "blockdata-sequence" || c.type === "object"));
|
|
646
|
+
return { type: "contents", span: node.span, children: children };
|
|
647
|
+
}
|
|
648
|
+
case "blockdata-sequence": {
|
|
649
|
+
assert(children.every(c => c.type === "blockdata" || (c.type === "object" && c.objectType === "reset")));
|
|
650
|
+
const rawValues = node.value;
|
|
651
|
+
const values = rawValues.map(v => trasformCSTBottomUp(v, cstToAstNode));
|
|
652
|
+
assert(values.every(v => v.type === "primitive" || v.type === "utf"));
|
|
653
|
+
return { type: "blockdata-sequence", span: node.span, values, children };
|
|
654
|
+
}
|
|
655
|
+
case "blockdata": {
|
|
656
|
+
assert(children.length === 3);
|
|
657
|
+
const tc = children[0];
|
|
658
|
+
const length = children[1];
|
|
659
|
+
const bytes = children[2];
|
|
660
|
+
assert(tc.type === "tc");
|
|
661
|
+
assert(length.type === "primitive");
|
|
662
|
+
assert(bytes.type === "primitive" && bytes.dataType === "bytes");
|
|
663
|
+
if (tc.value === _1.default.TC_BLOCKDATA && length.dataType === "unsigned-byte") {
|
|
664
|
+
return { type: "blockdata", span: node.span, children: [tc, length, bytes] };
|
|
665
|
+
}
|
|
666
|
+
else if (tc.value === _1.default.TC_BLOCKDATALONG && length.dataType === "long") {
|
|
667
|
+
return { type: "blockdata", span: node.span, children: [tc, length, bytes] };
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
throw new exc.InternalError();
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
case "tc": {
|
|
674
|
+
assert(children.length === 0);
|
|
675
|
+
assert(typeof node.value === "number" && _1.default.TC_BASE <= node.value && node.value <= _1.default.TC_MAX);
|
|
676
|
+
return { type: "tc", span: node.span, value: node.value, children: null };
|
|
677
|
+
}
|
|
678
|
+
case "read1": {
|
|
679
|
+
assert(children.length === 0);
|
|
680
|
+
assert(typeof node.value === "number");
|
|
681
|
+
return { type: "primitive", span: node.span, dataType: "unsigned-byte", value: node.value, children: null };
|
|
682
|
+
}
|
|
683
|
+
case "read": {
|
|
684
|
+
assert(children.length === 0);
|
|
685
|
+
return { type: "primitive", dataType: "bytes", span: node.span, value: null, children: null };
|
|
686
|
+
}
|
|
687
|
+
case "utf": {
|
|
688
|
+
assert(children.length === 2);
|
|
689
|
+
const length = children[0];
|
|
690
|
+
const body = children[1];
|
|
691
|
+
assert(length.type === "primitive" && length.dataType === "unsigned-short");
|
|
692
|
+
assert(body.type === "utf-body");
|
|
693
|
+
return { type: "utf", value: body.value, span: node.span, children: [length, body] };
|
|
694
|
+
}
|
|
695
|
+
case "long-utf": {
|
|
696
|
+
assert(children.length === 2);
|
|
697
|
+
const length = children[0];
|
|
698
|
+
const body = children[1];
|
|
699
|
+
assert(length.type === "primitive" && length.dataType === "long");
|
|
700
|
+
assert(body.type === "utf-body");
|
|
701
|
+
return { type: "long-utf", value: body.value, span: node.span, children: [length, body] };
|
|
702
|
+
}
|
|
703
|
+
case "utf-body": {
|
|
704
|
+
assert(children.length === 0);
|
|
705
|
+
assert(typeof node.value === "string");
|
|
706
|
+
return { type: "utf-body", value: node.value, span: node.span, children: null };
|
|
707
|
+
}
|
|
708
|
+
case "object/reset": {
|
|
709
|
+
assert(children.length === 1);
|
|
710
|
+
const tc = children[0];
|
|
711
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_RESET);
|
|
712
|
+
assert(typeof node.value === "number");
|
|
713
|
+
return { type: "object", objectType: "reset", newEpoch: node.value, span: node.span, children: [tc] };
|
|
714
|
+
}
|
|
715
|
+
case "object/null": {
|
|
716
|
+
assert(children.length === 1);
|
|
717
|
+
const tc = children[0];
|
|
718
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_NULL);
|
|
719
|
+
return { type: "object", objectType: "null", span: node.span, children: [tc] };
|
|
720
|
+
}
|
|
721
|
+
case "object/handle": {
|
|
722
|
+
assert(children.length === 2);
|
|
723
|
+
const tc = children[0];
|
|
724
|
+
const ref = children[1];
|
|
725
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_REFERENCE);
|
|
726
|
+
assert(ref.type === "primitive" && ref.dataType === "int");
|
|
727
|
+
assert(typeof node.value === "number");
|
|
728
|
+
return { type: "object", objectType: "prev-object", span: node.span, value: { epoch: node.value, handle: ref.value }, children: [tc, ref] };
|
|
729
|
+
}
|
|
730
|
+
case "object/class": {
|
|
731
|
+
assert(children.length === 1);
|
|
732
|
+
const tc = children[0];
|
|
733
|
+
const desc = children[0];
|
|
734
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_CLASS);
|
|
735
|
+
assertDescNode(desc);
|
|
736
|
+
assert(node.handle !== undefined);
|
|
737
|
+
return { type: "object", objectType: "new-class", span: node.span, handle: node.handle, children: [tc, desc] };
|
|
738
|
+
}
|
|
739
|
+
case "object/class-desc": {
|
|
740
|
+
assert(children.length === 1);
|
|
741
|
+
const first = children[0];
|
|
742
|
+
assertDescNode(first);
|
|
743
|
+
return first;
|
|
744
|
+
}
|
|
745
|
+
case "proxy-desc": {
|
|
746
|
+
assert(children.length >= 2);
|
|
747
|
+
const tc = children[0];
|
|
748
|
+
const numIfaces = children[1];
|
|
749
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_PROXYCLASSDESC);
|
|
750
|
+
assert(numIfaces.type === "primitive" && numIfaces.dataType === "int");
|
|
751
|
+
assert(children.length >= 2 + numIfaces.value);
|
|
752
|
+
const ifaces = children.slice(2, 2 + numIfaces.value);
|
|
753
|
+
assert(ifaces.every(x => x.type === "utf"));
|
|
754
|
+
assert(children.length === 2 + numIfaces.value + 2);
|
|
755
|
+
const annotation = children[2 + numIfaces.value];
|
|
756
|
+
const superDesc = children[2 + numIfaces.value + 1];
|
|
757
|
+
assert(annotation.type === "annotation");
|
|
758
|
+
assertDescNode(superDesc);
|
|
759
|
+
assert(node.handle !== undefined);
|
|
760
|
+
return { type: "object", objectType: "new-class-desc", handle: node.handle, span: node.span, children: [tc, {
|
|
761
|
+
type: "proxy-class-desc-info",
|
|
762
|
+
span: { start: node.span.start + 1, end: node.span.end },
|
|
763
|
+
children: [numIfaces, ...ifaces, annotation, superDesc],
|
|
764
|
+
}] };
|
|
765
|
+
}
|
|
766
|
+
case "non-proxy-desc": {
|
|
767
|
+
assert(children.length === 7);
|
|
768
|
+
const tc = children[0];
|
|
769
|
+
const name = children[1];
|
|
770
|
+
const suid = children[2];
|
|
771
|
+
const flags = children[3];
|
|
772
|
+
const fields = children[4];
|
|
773
|
+
const annotation = children[5];
|
|
774
|
+
const superDesc = children[6];
|
|
775
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_CLASSDESC);
|
|
776
|
+
assert(name.type === "utf");
|
|
777
|
+
assert(suid.type === "primitive" && suid.dataType === "long");
|
|
778
|
+
assert(flags.type === "primitive" && flags.dataType === "unsigned-byte");
|
|
779
|
+
assert(fields.type === "fields");
|
|
780
|
+
assert(annotation.type === "annotation");
|
|
781
|
+
assertDescNode(superDesc);
|
|
782
|
+
assert(node.handle !== undefined);
|
|
783
|
+
return { type: "object", objectType: "new-class-desc", handle: node.handle, span: node.span, children: [
|
|
784
|
+
tc, name, suid, {
|
|
785
|
+
type: "class-desc-info",
|
|
786
|
+
span: { start: suid.span.end, end: node.span.end },
|
|
787
|
+
children: [flags, fields, annotation, superDesc],
|
|
788
|
+
}
|
|
789
|
+
] };
|
|
790
|
+
}
|
|
791
|
+
case "object/string": {
|
|
792
|
+
assert(children.length > 0);
|
|
793
|
+
const first = children[0];
|
|
794
|
+
if (first.type === "object" && first.objectType === "prev-object")
|
|
795
|
+
return first;
|
|
796
|
+
assert(children.length === 2);
|
|
797
|
+
const tc = children[0];
|
|
798
|
+
const utf = children[1];
|
|
799
|
+
assert(tc.type === "tc");
|
|
800
|
+
if (tc.value === _1.default.TC_STRING) {
|
|
801
|
+
assert(utf.type === "utf");
|
|
802
|
+
assert(node.handle !== undefined);
|
|
803
|
+
return { type: "object", objectType: "new-string", value: utf.value, handle: node.handle, span: node.span, children: [tc, utf] };
|
|
804
|
+
}
|
|
805
|
+
else if (tc.value === _1.default.TC_LONGSTRING) {
|
|
806
|
+
assert(utf.type === "long-utf");
|
|
807
|
+
assert(node.handle !== undefined);
|
|
808
|
+
return { type: "object", objectType: "new-string", value: utf.value, handle: node.handle, span: node.span, children: [tc, utf] };
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
throw new exc.InternalError();
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
case "object/array": {
|
|
815
|
+
assert(children.length >= 3);
|
|
816
|
+
const tc = children[0];
|
|
817
|
+
const desc = children[1];
|
|
818
|
+
const len = children[2];
|
|
819
|
+
const values = children.slice(3);
|
|
820
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_ARRAY);
|
|
821
|
+
assertDescNode(desc);
|
|
822
|
+
assert(len.type === "primitive" && len.dataType === "int");
|
|
823
|
+
assert(len.value === values.length);
|
|
824
|
+
assert(values.every(v => v.type === "primitive" || v.type === "object"));
|
|
825
|
+
const firstItem = values.length > 0 ? values[0] : null;
|
|
826
|
+
if (firstItem?.type === "primitive") {
|
|
827
|
+
assert(values.every(v => v.type === "primitive" && v.dataType === firstItem.dataType));
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
assert(values.every(v => v.type === "object"));
|
|
831
|
+
}
|
|
832
|
+
assert(node.handle !== undefined);
|
|
833
|
+
return { type: "object", objectType: "new-array", handle: node.handle, span: node.span, children: [tc, desc, len, {
|
|
834
|
+
type: "values", span: { start: len.span.end, end: node.span.end }, children: values
|
|
835
|
+
}] };
|
|
836
|
+
}
|
|
837
|
+
case "object/enum": {
|
|
838
|
+
assert(children.length === 2);
|
|
839
|
+
const tc = children[0];
|
|
840
|
+
const desc = children[1];
|
|
841
|
+
const name = children[2];
|
|
842
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_ENUM);
|
|
843
|
+
assertDescNode(desc);
|
|
844
|
+
assertStringNode(name);
|
|
845
|
+
assert(node.handle !== undefined);
|
|
846
|
+
return { type: "object", objectType: "new-enum", span: node.span, handle: node.handle, children: [tc, desc, name] };
|
|
847
|
+
}
|
|
848
|
+
case "object/instance": {
|
|
849
|
+
assert(children.length === 3);
|
|
850
|
+
const tc = children[0];
|
|
851
|
+
const desc = children[1];
|
|
852
|
+
const data = children[2];
|
|
853
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_OBJECT);
|
|
854
|
+
assertDescNode(desc);
|
|
855
|
+
assert(data.type === "external-data" || data.type === "serial-data");
|
|
856
|
+
assert(node.handle !== undefined);
|
|
857
|
+
return { type: "object", objectType: "new-object", handle: node.handle, span: node.span, children: [tc, desc, data] };
|
|
858
|
+
}
|
|
859
|
+
case "external-data": {
|
|
860
|
+
// PROTOCOL_VERSION_1
|
|
861
|
+
if (children.every(c => c.type === "primitive" || c.type === "object" || c.type === "utf")) {
|
|
862
|
+
return { type: "external-data", protocolVersion: 1, span: node.span, children: children };
|
|
863
|
+
}
|
|
864
|
+
// PROTOCOL_VERSION_2
|
|
865
|
+
else {
|
|
866
|
+
assert(children.length > 0);
|
|
867
|
+
const annotation = children[children.length - 1];
|
|
868
|
+
assert(annotation.type === "annotation");
|
|
869
|
+
const before = children.slice(0, children.length - 1);
|
|
870
|
+
assert(before.every(c => c.type === "object" || c.type === "blockdata-sequence"));
|
|
871
|
+
const contents = annotation.children[0];
|
|
872
|
+
const endBlock = annotation.children[1];
|
|
873
|
+
const newContents = {
|
|
874
|
+
type: "contents",
|
|
875
|
+
span: { start: node.span.start, end: contents.span.end },
|
|
876
|
+
children: [...before, ...contents.children],
|
|
877
|
+
};
|
|
878
|
+
return { type: "external-data", protocolVersion: 2, span: node.span, children: [{
|
|
879
|
+
type: "annotation",
|
|
880
|
+
span: node.span,
|
|
881
|
+
children: [newContents, endBlock],
|
|
882
|
+
}] };
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
case "serial-data": {
|
|
886
|
+
assert(children.every(c => c.type === "class-data"));
|
|
887
|
+
return { type: "serial-data", span: node.span, children: children };
|
|
888
|
+
}
|
|
889
|
+
case "class-data-wr": {
|
|
890
|
+
assert(children.length > 0);
|
|
891
|
+
const annotation = children[children.length - 1];
|
|
892
|
+
assert(annotation.type === "annotation");
|
|
893
|
+
let beforeValues;
|
|
894
|
+
let values;
|
|
895
|
+
let afterValues;
|
|
896
|
+
const valuesIdx = children.findIndex(c => c.type === "values");
|
|
897
|
+
if (valuesIdx === -1) {
|
|
898
|
+
beforeValues = [];
|
|
899
|
+
values = null;
|
|
900
|
+
const tempAfter = children.slice(0, -1);
|
|
901
|
+
assert(tempAfter.every(c => c.type === "blockdata-sequence" || c.type === "object"));
|
|
902
|
+
afterValues = tempAfter;
|
|
903
|
+
}
|
|
904
|
+
else {
|
|
905
|
+
const tempBefore = children.slice(0, valuesIdx);
|
|
906
|
+
const tempValues = children[valuesIdx];
|
|
907
|
+
const tempAfter = children.slice(valuesIdx + 1, -1);
|
|
908
|
+
assert(tempBefore.every(c => c.type === "blockdata-sequence" || c.type === "object"));
|
|
909
|
+
assert(tempValues.type === "values");
|
|
910
|
+
assert(tempAfter.every(c => c.type === "blockdata-sequence" || c.type === "object"));
|
|
911
|
+
beforeValues = tempBefore;
|
|
912
|
+
values = tempValues;
|
|
913
|
+
afterValues = tempAfter;
|
|
914
|
+
}
|
|
915
|
+
const annotationSpan = {
|
|
916
|
+
start: afterValues.length > 0 ? afterValues[0].span.start : annotation.span.start,
|
|
917
|
+
end: annotation.span.end,
|
|
918
|
+
};
|
|
919
|
+
const annotationContentsSpan = { start: annotationSpan.start, end: annotationSpan.end - 1 };
|
|
920
|
+
const newAnnotation = {
|
|
921
|
+
type: "annotation",
|
|
922
|
+
span: annotationSpan,
|
|
923
|
+
children: [{
|
|
924
|
+
type: "contents",
|
|
925
|
+
span: annotationContentsSpan,
|
|
926
|
+
children: [...afterValues, ...annotation.children[0].children],
|
|
927
|
+
}, annotation.children[1]],
|
|
928
|
+
};
|
|
929
|
+
const constentsSpan = { start: node.span.start, end: values !== null ? values.span.start : -1 };
|
|
930
|
+
const contents = {
|
|
931
|
+
type: "contents",
|
|
932
|
+
span: constentsSpan,
|
|
933
|
+
children: [...beforeValues],
|
|
934
|
+
};
|
|
935
|
+
const beforeAnnotation = values !== null ? [contents, values] : [];
|
|
936
|
+
return { type: "class-data", writeMethod: true, span: node.span, children: [...beforeAnnotation, newAnnotation] };
|
|
937
|
+
}
|
|
938
|
+
case "class-data-no-wr": {
|
|
939
|
+
const hasValues = children.length > 0 && children[children.length - 1].type === "values";
|
|
940
|
+
const values = hasValues ? children[children.length - 1] : null;
|
|
941
|
+
assert(values === null || values.type === "values");
|
|
942
|
+
const before = children.slice(0, hasValues ? -1 : undefined);
|
|
943
|
+
assert(before.every(c => c.type === "blockdata-sequence" || c.type === "object"));
|
|
944
|
+
const contentsStart = node.span.start;
|
|
945
|
+
const contentsEnd = before.length > 0 ? before[before.length - 1].span.end : values !== null ? values.span.start : node.span.end;
|
|
946
|
+
const contents = {
|
|
947
|
+
type: "contents",
|
|
948
|
+
span: { start: contentsStart, end: contentsEnd },
|
|
949
|
+
children: before,
|
|
950
|
+
};
|
|
951
|
+
const valuesNodes = values !== null ? [values] : [];
|
|
952
|
+
return { type: "class-data", writeMethod: false, span: node.span, children: [
|
|
953
|
+
contents, ...valuesNodes,
|
|
954
|
+
] };
|
|
955
|
+
}
|
|
956
|
+
case "object/exception": {
|
|
957
|
+
assert(node.error !== undefined);
|
|
958
|
+
assert(children.length === 2);
|
|
959
|
+
const tc = children[0];
|
|
960
|
+
const throwable = children[1];
|
|
961
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_EXCEPTION);
|
|
962
|
+
assert(throwable.type === "object" && (throwable.objectType === "new-object" || throwable.objectType === "prev-object"));
|
|
963
|
+
assert(typeof node.value === "number");
|
|
964
|
+
const newEpoch = node.value;
|
|
965
|
+
return { type: "object", objectType: "exception", exceptionEpoch: newEpoch - 1, newEpoch: newEpoch, span: node.span, children: [tc, throwable] };
|
|
966
|
+
}
|
|
967
|
+
case "annotation": {
|
|
968
|
+
assert(children.length > 0);
|
|
969
|
+
const contents = children.slice(0, -1);
|
|
970
|
+
const tc = children[children.length - 1];
|
|
971
|
+
assert(contents.every(c => c.type === "blockdata-sequence" || c.type === "object"));
|
|
972
|
+
assert(tc.type === "tc" && tc.value === _1.default.TC_ENDBLOCKDATA);
|
|
973
|
+
return { type: "annotation", span: node.span, children: [{
|
|
974
|
+
type: "contents", span: { start: node.span.start, end: tc.span.start }, children: contents,
|
|
975
|
+
}, tc] };
|
|
976
|
+
}
|
|
977
|
+
case "fields": {
|
|
978
|
+
assert(children.length > 0);
|
|
979
|
+
const length = children[0];
|
|
980
|
+
const fields = children.slice(1);
|
|
981
|
+
assert(length.type === "primitive" && length.dataType === "short");
|
|
982
|
+
assert(fields.every(f => f.type === "field-desc"));
|
|
983
|
+
return { type: "fields", span: node.span, children: [length, ...fields] };
|
|
984
|
+
}
|
|
985
|
+
case "field": {
|
|
986
|
+
assert(children.length >= 2);
|
|
987
|
+
const typecode = children[0];
|
|
988
|
+
const name = children[1];
|
|
989
|
+
assert(typecode.type === "primitive" && typecode.dataType === "unsigned-byte");
|
|
990
|
+
assert(name.type === "utf");
|
|
991
|
+
const tcStr = String.fromCharCode(typecode.value);
|
|
992
|
+
if (tcStr === "[" || tcStr === "L") {
|
|
993
|
+
assert(children.length === 3);
|
|
994
|
+
const className = children[2];
|
|
995
|
+
assertStringNode(className);
|
|
996
|
+
return { type: "field-desc", fieldType: "object", span: node.span, children: [typecode, name, className] };
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
assert(children.length === 2);
|
|
1000
|
+
return { type: "field-desc", fieldType: "primitive", span: node.span, children: [typecode, name] };
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
case "values": {
|
|
1004
|
+
assert(children.every(c => c.type === "primitive" || c.type === "object"));
|
|
1005
|
+
return { type: "values", span: node.span, children: children };
|
|
1006
|
+
}
|
|
1007
|
+
default:
|
|
1008
|
+
throw new exc.InternalError();
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function assertDescNode(node) {
|
|
1012
|
+
assert(node.type === "object" &&
|
|
1013
|
+
(node.objectType === "new-class-desc" || node.objectType === "null" || node.objectType === "prev-object"));
|
|
1014
|
+
}
|
|
1015
|
+
function assertStringNode(node) {
|
|
1016
|
+
assert(node.type === "object" &&
|
|
1017
|
+
(node.objectType === "new-string" || node.objectType === "prev-object"));
|
|
1018
|
+
}
|
|
1019
|
+
//# sourceMappingURL=ois-ast.js.map
|