nv-buf-serde 0.0.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.
Files changed (52) hide show
  1. package/DIST/dist.js +25 -0
  2. package/README.md +382 -0
  3. package/TEST/common.js +435 -0
  4. package/TEST/hole-tst.js +31 -0
  5. package/TEST/nd-benchmark.js +17 -0
  6. package/TEST/r-1bstr.js +33 -0
  7. package/TEST/r-2bstr.js +33 -0
  8. package/TEST/r-ab-and-abvw.js +48 -0
  9. package/TEST/r-bi.js +33 -0
  10. package/TEST/r-date.js +28 -0
  11. package/TEST/r-double.js +33 -0
  12. package/TEST/r-int-not-smi.js +28 -0
  13. package/TEST/r-mp-st-circular.js +105 -0
  14. package/TEST/r-odd-ball.js +33 -0
  15. package/TEST/r-packed-double.js +38 -0
  16. package/TEST/r-packed-smi.js +35 -0
  17. package/TEST/r-packed-with-attr.js +40 -0
  18. package/TEST/r-prim-wrap.js +35 -0
  19. package/TEST/r-rgx.js +28 -0
  20. package/TEST/r-smi.js +28 -0
  21. package/TEST/read-bi-contents.js +20 -0
  22. package/TEST/run.js +43 -0
  23. package/TEST/run.sh +29 -0
  24. package/TEST/serde-benchmark.js +17 -0
  25. package/TEST/tst.json +114 -0
  26. package/TEST/tst.v8ser +0 -0
  27. package/TEST/w-1bstr.js +34 -0
  28. package/TEST/w-2bstr.js +34 -0
  29. package/TEST/w-ab-and-abvw.js +60 -0
  30. package/TEST/w-bi.js +33 -0
  31. package/TEST/w-date.js +33 -0
  32. package/TEST/w-double.js +35 -0
  33. package/TEST/w-int-not-smi.js +37 -0
  34. package/TEST/w-mp-st-circular.js +60 -0
  35. package/TEST/w-odd-ball.js +43 -0
  36. package/TEST/w-packed-double.js +40 -0
  37. package/TEST/w-packed-smi.js +38 -0
  38. package/TEST/w-packed-with-attr.js +41 -0
  39. package/TEST/w-prim-wrap.js +41 -0
  40. package/TEST/w-rgx.js +33 -0
  41. package/TEST/w-smi.js +36 -0
  42. package/build.sh +1 -0
  43. package/const.js +181 -0
  44. package/ctx.js +89 -0
  45. package/fixed-cfg.js +6 -0
  46. package/index.js +27 -0
  47. package/misc.js +112 -0
  48. package/package.json +22 -0
  49. package/r.js +646 -0
  50. package/restrict.js +48 -0
  51. package/w.js +510 -0
  52. package/zero-nid.js +21 -0
package/r.js ADDED
@@ -0,0 +1,646 @@
1
+ const {_u,_n,_t,_f} = require("nv-facutil-untf");
2
+ const {thrw_str} = require("nv-facutil-thrw");
3
+ const _ab = require("nv-facutil-ab");
4
+ const _zigzag = require("nv-number-zigzag");
5
+ const _utf16 = require("nv-buf-jstr");
6
+ const _rgx_flag = require("nv-regexp-flags");
7
+ const _misc = require("./misc");
8
+ const {SerializationTag,ErrorTag,ArrayBufferViewIndexToCtor,CreatUnknown} = require("./const");
9
+ const { creat_rctx } = require("./ctx");
10
+
11
+ const ERRD = {
12
+ must_be_str:"must_be_str"
13
+ }
14
+
15
+
16
+ const ReadVarintLoopIfLshiftWork = (u8a,si,ctx) => {
17
+ let old_si = si;
18
+ let v = 0;
19
+ let shift = 0;
20
+ let has_another_byte = _f;
21
+ do {
22
+ let byte = u8a[si];
23
+ has_another_byte = byte & 0x80;
24
+ if(shift < 32) {
25
+ v |= (byte & 0x7F) << shift;
26
+ shift = shift +7;
27
+ } else {
28
+ break;
29
+ }
30
+ ++si;
31
+ } while(has_another_byte);
32
+ return([v,si-old_si,si])
33
+ }
34
+
35
+ const ReadVarintLoop = (u8a,si,ctx) => {
36
+ let old_si = si;
37
+ let v = 0n;
38
+ let shift = 0n;
39
+ let has_another_byte = _f;
40
+ do {
41
+ let byte = BigInt(u8a[si]);
42
+ has_another_byte = byte & 0x80n;
43
+ if(shift < 32n) {
44
+ v |= (byte & 0x7Fn) << shift;
45
+ shift = shift +7n;
46
+ } else {
47
+ break;
48
+ }
49
+ ++si;
50
+ } while(has_another_byte);
51
+ return([Number(v),si-old_si,si])
52
+ }
53
+
54
+ const ReadVarint = ReadVarintLoop; // in js-layer no need unroll
55
+
56
+ const ReadHeader = (u8a,si,ctx) => {
57
+ let old_si = si;
58
+ ++si; // tag
59
+ let kLatestVersion = u8a[si];
60
+ ++si;
61
+ return([kLatestVersion,si-old_si,si])
62
+ }
63
+
64
+ const ReadTag = (u8a,si,ctx) => {
65
+ let old_si = si;
66
+ let tag;
67
+ do {
68
+ tag = u8a[si];
69
+ ++si;
70
+ } while(tag === SerializationTag.kPadding);
71
+ return([tag,si-old_si,si])
72
+ }
73
+
74
+ const ReadZigZag = (u8a,si,ctx,decode=_zigzag.decd) => {
75
+ let old_si = si;
76
+ let a3 = ReadVarint(u8a,si,ctx);
77
+ let unsigned = a3[0];
78
+ si = a3[2];
79
+ let v = decode(unsigned);
80
+ return([v,si-old_si,si])
81
+ }
82
+
83
+
84
+ const ReadDouble = (u8a,si,ctx) => {
85
+ let dv = new DataView(u8a.buffer);
86
+ let v = dv.getFloat64(si,_t);
87
+ si = si+8;
88
+ return([v,8,si])
89
+ }
90
+
91
+ const ReadRawBytes = (u8a,si,sz,ctx) => {
92
+ let old_si = si;
93
+ let nu8a = new Uint8Array(u8a.buffer,si,sz);
94
+ si = si + sz;
95
+ return([nu8a,sz,si])
96
+ }
97
+
98
+ const ReadByte = (u8a,si,ctx) => {
99
+ ++si;
100
+ return([u8a[i],1,si])
101
+ }
102
+
103
+ const ReadUint32 = (u8a,si,ctx) => ReadVarint(u8a,si,ctx);
104
+
105
+ const BI_MUL = 2n**64n;
106
+
107
+ const ReadBigInt = (u8a,si,ctx) => {
108
+ let old_si = si;
109
+ let a3 = ReadVarint(u8a,si,ctx);
110
+ let bitfield = a3[0];
111
+ let sign = bitfield & 0x1;
112
+ let byte_len = bitfield >> 1;
113
+ si = a3[2];
114
+ ////
115
+ let data_si = si;
116
+ a3 = ReadRawBytes(u8a,si,byte_len,ctx);
117
+ let nu8a = a3[0];
118
+ let dv = new DataView(nu8a.buffer);
119
+ let bi = 0n;
120
+ let mul = 1n;
121
+ let bi_len = byte_len /8;
122
+ for(let i =0;i<bi_len;++i) {
123
+ let nbi = dv.getBigUint64(data_si,_t);
124
+ bi = bi + (nbi * mul);
125
+ mul = mul * BI_MUL;
126
+ data_si = data_si + 8;
127
+ }
128
+ if(sign === 1) { bi = -bi;} else {}
129
+ si = a3[2];
130
+ return([bi,si-old_si,si])
131
+ }
132
+
133
+ const ReadOneByteString = (u8a,si,ctx) => {
134
+ let old_si = si;
135
+ let a3 = ReadVarint(u8a,si,ctx);
136
+ let blen = a3[0];
137
+ si = a3[2];
138
+ let s = _misc.Latin1U8aToStr(u8a,si,blen);
139
+ si += blen;
140
+ return([s,si-old_si,si])
141
+ }
142
+
143
+ const ReadTwoByteString = (u8a,si,ctx) => {
144
+ let old_si = si;
145
+ let a3 = ReadVarint(u8a,si,ctx);
146
+ let blen = a3[0];
147
+ si = a3[2];
148
+ let s = _misc.JstrU8aToStr(u8a,si,blen);
149
+ si += blen;
150
+ return([s,si-old_si,si])
151
+ }
152
+
153
+ const ReadUtf8String = (u8a,si,ctx) => {
154
+ let old_si = si;
155
+ let a3 = ReadVarint(u8a,si,ctx);
156
+ let blen = a3[0];
157
+ si = a3[2];
158
+ let s = _misc.Utf8U8aToStr(u8a,si,blen);
159
+ si += blen;
160
+ return([s,si-old_si,si])
161
+ }
162
+
163
+
164
+
165
+ const ReadJSDate = (u8a,si,ctx) => {
166
+ let old_si = si;
167
+ let a3 = ReadDouble(u8a,si,ctx);
168
+ let v = a3[0];
169
+ let dt = new Date(v);
170
+ si = a3[2];
171
+ ctx.AddObjectWithID(dt);
172
+ return([dt,si-old_si,si])
173
+ }
174
+
175
+
176
+ const ReadJSPrimitiveWrapper = (u8a,si,tag,ctx) => {
177
+ let old_si = si;
178
+ let v;
179
+ switch (tag) {
180
+ case SerializationTag.kTrueObject: {v = new Boolean(_t);break;}
181
+ case SerializationTag.kFalseObject: {v = new Boolean(_f);break;}
182
+ case SerializationTag.kNumberObject: {
183
+ let a3 = ReadDouble(u8a,si,ctx);
184
+ let num = a3[0];
185
+ si = a3[2];
186
+ v = new Number(num);
187
+ break;
188
+ }
189
+ case SerializationTag.kStringObject: {
190
+ let a3 = ReadString(u8a,si,ctx);
191
+ let s = a3[0];
192
+ si = a3[2];
193
+ v = new String(s);
194
+ break;
195
+ }
196
+ case SerializationTag.kBigIntObject: {
197
+ let a3 = ReadBigInt(u8a,si,ctx);
198
+ let bi = a3[0];
199
+ si = a3[2];
200
+ // this is impossible in js-layer
201
+ //v = new BigInt(bi);
202
+ v = CreatFakeCantBeSered("BigInt",bi);
203
+ break;
204
+ }
205
+ default: {}
206
+ }
207
+ ctx.AddObjectWithID(v);
208
+ return([v,si-old_si,si])
209
+ }
210
+
211
+
212
+ const ReadJSError = (u8a,si,ctx) => {
213
+ let old_si = si;
214
+ let message = _u;
215
+ let stack = _u;
216
+ let done = _f;
217
+ let ctor = Error;
218
+ ////
219
+ while (!done) {
220
+ let a3 = ReadVarint(u8a,si,ctx);
221
+ let tag = a3[0];
222
+ si = a3[2];
223
+ switch (tag) {
224
+ case ErrorTag.kEvalErrorPrototype: {ctor=EvalError; break;}
225
+ case ErrorTag.kRangeErrorPrototype: {ctor=RangeError; break;}
226
+ case ErrorTag.kReferenceErrorPrototype: {ctor=ReferenceError; break;}
227
+ case ErrorTag.kSyntaxErrorPrototype: {ctor=SyntaxError; break;}
228
+ case ErrorTag.kTypeErrorPrototype: {ctor=TypeError; break;}
229
+ case ErrorTag.kUriErrorPrototype: {ctor=UriError; break;}
230
+ case ErrorTag.kMessage: {
231
+ let a3 = ReadString(u8a,si,ctx);
232
+ message = a3[0];
233
+ si = a3[2];
234
+ break;
235
+ }
236
+ case ErrorTag.kCause: {
237
+ let a3 = ReadObject(u8a,si,ctx);
238
+ let cause = a3[0];
239
+ si = a3[2];
240
+ break;
241
+ }
242
+ case ErrorTag.kStack: {
243
+ let a3 = ReadString(u8a,si,ctx);
244
+ stack = a3[0];
245
+ si = a3[2];
246
+ break;
247
+ }
248
+ case ErrorTag.kEnd: {
249
+ done = _t;
250
+ break;
251
+ }
252
+ default:{}
253
+ }
254
+ }
255
+
256
+ let err;
257
+ if(cause) {
258
+ err = new ctor(message,{cause})
259
+ } else {
260
+ err = new ctor(message)
261
+ }
262
+ err.stack = stack;
263
+ ctx.AddObjectWithID(err);
264
+ return([err,si-old_si,si])
265
+ }
266
+
267
+ const ReadString = (u8a,si,ctx) => {
268
+ let old_si = si;
269
+ let a3 = ReadTag(u8a,si,ctx);
270
+ let tag = a3[0];
271
+ si = a3[2];
272
+ switch(tag) {
273
+ case SerializationTag.kOneByteString: {
274
+ a3 = ReadOneByteString(u8a,si,ctx);
275
+ si = a3[2];
276
+ return([a3[0],si-old_si,si]);
277
+ }
278
+ case SerializationTag.kTwoByteString: {
279
+ a3 = ReadTwoByteString(u8a,si,ctx);
280
+ si = a3[2];
281
+ return([a3[0],si-old_si,si]);
282
+ }
283
+ case SerializationTag.kUtf8String: {
284
+ a3 = ReadUtf8String(u8a,si,ctx);
285
+ si = a3[2];
286
+ return([a3[0],si-old_si,si]);
287
+ }
288
+ default: {
289
+ thrw_str(ERRD.must_be_str)
290
+ }
291
+ }
292
+ }
293
+
294
+
295
+ const ReadJSRegExp = (u8a,si,ctx) => {
296
+ let old_si = si;
297
+ let a3 = ReadString(u8a,si,ctx);
298
+ let ptrn = a3[0];
299
+ si = a3[2];
300
+ a3 = ReadVarint(u8a,si,ctx);
301
+ let flags = a3[0];
302
+ flags = _rgx_flag.n2s(flags);
303
+ si = a3[2];
304
+ let rgx = new RegExp(ptrn,flags);
305
+ ctx.AddObjectWithID(rgx);
306
+ return([rgx,si-old_si,si])
307
+ }
308
+
309
+ const ReadJSSet = (u8a,si,ctx)=> {
310
+ let old_si = si;
311
+ let st = new Set();
312
+ ctx.AddObjectWithID(st);
313
+ let sz = 0;
314
+ while (_t) {
315
+ let rtrn_si = si;
316
+ let a3 = ReadTag(u8a,si,ctx);
317
+ let tag = a3[0];
318
+ si = a3[2];
319
+ if (tag === SerializationTag.kEndJSSet) {
320
+ break;
321
+ } else {
322
+ si = rtrn_si;
323
+ a3 = ReadObject(u8a,si,ctx);
324
+ st.add(a3[0]);
325
+ si = a3[2];
326
+ }
327
+ sz++;
328
+ }
329
+ let a3 = ReadVarint(u8a,si,ctx); // in js-layer no-need to check
330
+ si = a3[2];
331
+ return([st,si-old_si,si,a3[0]/*just for check*/])
332
+ }
333
+
334
+ const ReadJSMap = (u8a,si,ctx) => {
335
+ let old_si = si;
336
+ let mp = new Map();
337
+ ctx.AddObjectWithID(mp);
338
+ let sz = 0;
339
+ while (_t) {
340
+ let rtrn_si = si;
341
+ let a3 = ReadTag(u8a,si,ctx);
342
+ si = a3[2];
343
+ let tag = a3[0];
344
+ if (tag === SerializationTag.kEndJSMap) {
345
+ break;
346
+ } else {
347
+ si = rtrn_si;
348
+ a3 = ReadObject(u8a,si,ctx);
349
+ let mpk = a3[0];
350
+ si = a3[2];
351
+ a3 = ReadObject(u8a,si,ctx);
352
+ let mpv = a3[0];
353
+ si = a3[2];
354
+ mp.set(mpk,mpv);
355
+ sz = sz+2;
356
+ }
357
+ }
358
+ let a3 = ReadVarint(u8a,si,ctx);
359
+ si = a3[2];
360
+ return([mp,si-old_si,si,a3[0]/*just for check*/])
361
+ }
362
+
363
+ const ReadHostObject = (u8a,si,ctx) => {
364
+ let old_si = si;
365
+ let a3 = ReadUint32(u8a,si,ctx);
366
+ let typeIndex = a3[0];
367
+ let ctor = ArrayBufferViewIndexToCtor[typeIndex];
368
+ let BYTES_PER_ELEMENT = ctor.BYTES_PER_ELEMENT ;
369
+ si = a3[2];
370
+ a3 = ReadUint32(u8a,si,ctx);
371
+ let byteLength = a3[0];
372
+ si = a3[2];
373
+ let offset = si;
374
+ a3 = ReadRawBytes(u8a,si,byteLength,ctx);
375
+ let buf;
376
+ if(si%BYTES_PER_ELEMENT === 0) {
377
+ buf = new ctor(a3[0].buffer,si,byteLength);
378
+ } else {
379
+ //need copy
380
+ buf = new ctor(a3[0].buffer.slice(si,si+byteLength));
381
+ }
382
+ si = a3[2];
383
+ ctx.AddObjectWithID(buf);
384
+ return([buf,si-old_si,si])
385
+ }
386
+
387
+ const ReadJSArrayBufferView = ReadHostObject; //compatible to nodejs
388
+
389
+
390
+ const ReadJSArrayBuffer = (u8a,si,is_resizable,ctx) => {
391
+ let old_si = si;
392
+ let a3 = ReadVarint(u8a,si,ctx);
393
+ let byte_length = a3[0];
394
+ si = a3[2];
395
+ let max_byte_length = byte_length;
396
+ let ab;
397
+ if(is_resizable) {
398
+ let a3 = ReadVarint(u8a,si,ctx);
399
+ max_byte_length = a3[0];
400
+ ab = new ArrayBuffer(byte_length,{maxByteLength:max_byte_length});
401
+ si = a3[2];
402
+ _ab._cp(u8a.buffer,si,byte_length,ab,0);
403
+ si = si + byte_length;
404
+ } else {
405
+ let total_ab = u8a.buffer;
406
+ ab = total_ab.slice(si,si+byte_length);
407
+ si = si + byte_length;
408
+ }
409
+ ctx.AddObjectWithID(ab);
410
+ return([ab,si-old_si,si])
411
+ }
412
+
413
+ const ReadJSObjectProperties = (u8a,si,o,end_tag,is_ary,ctx) => {
414
+ let old_si = si;
415
+ let num_properties = 0;
416
+ while(_t) {
417
+ let rtrn_si = si;
418
+ let a3 = ReadTag(u8a,si,ctx);
419
+ let tag = a3[0];
420
+ si = a3[2];
421
+ if(tag !== end_tag) {
422
+ si = rtrn_si;
423
+ a3 = ReadObject(u8a,si,ctx);
424
+ let key = a3[0];
425
+ si = a3[2];
426
+ a3 = ReadObject(u8a,si,ctx);
427
+ let val = a3[0];
428
+ si = a3[2];
429
+ o[key] = val;
430
+ ++num_properties;
431
+ } else {
432
+ return([num_properties,si-old_si,si])
433
+ }
434
+ }
435
+ }
436
+
437
+ const ReadJSObject = (u8a,si,ctx) => {
438
+ let old_si = si;
439
+ let o = {};
440
+ ctx.AddObjectWithID(o);
441
+ let a3 = ReadJSObjectProperties(u8a,si,o,SerializationTag.kEndJSObject,_f,ctx);
442
+ let num_properties = a3[0];
443
+ si = a3[2];
444
+ a3 = ReadVarint(u8a,si,ctx); // expected_num_properties
445
+ si = a3[2];
446
+ return([o,si-old_si,si]) // we dont verify expected_num_properties
447
+ }
448
+
449
+ const ReadJSArray = (u8a,si,begin_tag,ctx) => {
450
+ let old_si = si;
451
+ let a3 = ReadVarint(u8a,si,ctx);
452
+ let length = a3[0];
453
+ si = a3[2];
454
+ let a = [];
455
+ ctx.AddObjectWithID(a);
456
+ for(let i=0;i<length;++i) {
457
+ a3 = ReadObject(u8a,si,ctx);
458
+ a.push(a3[0]);
459
+ si = a3[2];
460
+ }
461
+ /////
462
+ let end_tag = (begin_tag === SerializationTag.kBeginDenseJSArray)?SerializationTag.kEndDenseJSArray:SerializationTag.kEndSparseJSArray;
463
+ a3 = ReadJSObjectProperties(u8a,si,a, end_tag, _t,ctx);
464
+ si = a3[2];
465
+ a3 = ReadVarint(u8a,si,ctx); // we dont check expected_num_properties
466
+ si = a3[2];
467
+ a3 = ReadVarint(u8a,si,ctx); // we dont check expected_length
468
+ si = a3[2];
469
+ return([a,si-old_si,si])
470
+ }
471
+
472
+
473
+ const ReadObjectInternal = (u8a,si,ctx) => {
474
+ let old_si = si;
475
+ let a3 = ReadTag(u8a,si,ctx);
476
+ let tag = a3[0];
477
+ si = a3[2];
478
+ switch (tag) {
479
+ case SerializationTag.kTheHole: {return([_u,si-old_si,si]);}
480
+ case SerializationTag.kUndefined: {return([_u,si-old_si,si]);}
481
+ case SerializationTag.kNull: {return([_n,si-old_si,si]);}
482
+ case SerializationTag.kTrue: {return([_t,si-old_si,si]);}
483
+ case SerializationTag.kFalse: {return([_f,si-old_si,si]);}
484
+ case SerializationTag.kInt32: {
485
+ a3 = ReadZigZag(u8a,si,ctx);
486
+ si = a3[2];
487
+ return([a3[0],si-old_si,si]);
488
+ }
489
+ case SerializationTag.kUint32: {
490
+ a3 = ReadVarint(u8a,si,ctx);
491
+ si = a3[2];
492
+ return([a3[0],si-old_si,si]);
493
+ }
494
+ case SerializationTag.kDouble: {
495
+ a3 = ReadDouble(u8a,si,ctx);
496
+ si = a3[2];
497
+ return([a3[0],si-old_si,si]);
498
+ }
499
+ case SerializationTag.kBigInt: {
500
+ a3 = ReadBigInt(u8a,si,ctx);
501
+ si = a3[2];
502
+ return([a3[0],si-old_si,si]);
503
+ }
504
+ case SerializationTag.kOneByteString: {
505
+ a3 = ReadOneByteString(u8a,si,ctx);
506
+ si = a3[2];
507
+ return([a3[0],si-old_si,si]);
508
+ }
509
+ case SerializationTag.kTwoByteString: {
510
+ a3 = ReadTwoByteString(u8a,si,ctx);
511
+ si = a3[2];
512
+ return([a3[0],si-old_si,si]);
513
+ }
514
+ case SerializationTag.kUtf8String: {
515
+ a3 = ReadUtf8String(u8a,si,ctx);
516
+ si = a3[2];
517
+ return([a3[0],si-old_si,si]);
518
+ }
519
+ case SerializationTag.kBeginJSObject: {
520
+ a3 = ReadJSObject(u8a,si,ctx);
521
+ si = a3[2];
522
+ return([a3[0],si-old_si,si]);
523
+ }
524
+ case SerializationTag.kBeginDenseJSArray :
525
+ case SerializationTag.kBeginSparseJSArray: { // treat sparse same as dense
526
+ a3 = ReadJSArray(u8a,si,tag,ctx);
527
+ si = a3[2];
528
+ return([a3[0],si-old_si,si]);
529
+ }
530
+ case SerializationTag.kDate: {
531
+ a3 = ReadJSDate(u8a,si,ctx);
532
+ si = a3[2];
533
+ return([a3[0],si-old_si,si]);
534
+ }
535
+ case SerializationTag.kBeginJSMap: {
536
+ a3 = ReadJSMap(u8a,si,ctx);
537
+ si = a3[2];
538
+ return([a3[0],si-old_si,si]);
539
+ }
540
+ case SerializationTag.kBeginJSSet: {
541
+ a3 = ReadJSSet(u8a,si,ctx);
542
+ si = a3[2];
543
+ return([a3[0],si-old_si,si]);
544
+ }
545
+ case SerializationTag.kObjectReference: {
546
+ a3 = ReadVarint(u8a,si,ctx);
547
+ let id = a3[0];
548
+ si = a3[2];
549
+ let v = ctx.GetObjectWithID(id);
550
+ return([v,si-old_si,si]);
551
+ }
552
+ case SerializationTag.kRegExp: {
553
+ a3 = ReadJSRegExp(u8a,si,ctx);
554
+ si = a3[2];
555
+ return([a3[0],si-old_si,si]);
556
+ }
557
+ case SerializationTag.kSharedArrayBuffer: //treat sab as normal ab
558
+ case SerializationTag.kArrayBuffer: {
559
+ let is_resizable = _f;
560
+ a3 = ReadJSArrayBuffer(u8a,si,is_resizable,ctx);
561
+ si = a3[2];
562
+ return([a3[0],si-old_si,si]);
563
+ }
564
+ case SerializationTag.kResizableArrayBuffer: {
565
+ let is_resizable = _t;
566
+ a3 = ReadJSArrayBuffer(u8a,si,is_resizable,ctx);
567
+ si = a3[2];
568
+ return([a3[0],si-old_si,si]);
569
+ }
570
+ case SerializationTag.kError: {
571
+ a3 = ReadJSError(u8a,si,ctx);
572
+ si = a3[2];
573
+ return([a3[0],si-old_si,si]);
574
+ }
575
+ case SerializationTag.kArrayBufferView: //corresponding to nodejs
576
+ case SerializationTag.kHostObject: {
577
+ a3 = ReadHostObject(u8a,si,ctx);
578
+ si = a3[2];
579
+ return([a3[0],si-old_si,si]);
580
+ }
581
+ case SerializationTag.kTrueObject:
582
+ case SerializationTag.kFalseObject:
583
+ case SerializationTag.kNumberObject:
584
+ case SerializationTag.kBigIntObject:
585
+ case SerializationTag.kStringObject: {
586
+ a3 = ReadJSPrimitiveWrapper(u8a,si,tag,ctx);
587
+ si = a3[2];
588
+ return([a3[0],si-old_si,si]);
589
+ }
590
+ default: {
591
+ console.log("why unknown",tag,si,u8a);
592
+ process.exit();
593
+ return([CreatUnknown(),si-old_si,si])
594
+ }
595
+ }
596
+ }
597
+
598
+
599
+
600
+ const ReadObject = (u8a,si,ctx) => ReadObjectInternal(u8a,si,ctx); //same as ReadObjectInternal , coz ArrayBufferView AS HostObject
601
+
602
+
603
+ const decd = (ab) => {
604
+ let u8a = new Uint8Array(ab);
605
+ let ctx = creat_rctx();
606
+ let si = 0;
607
+ let a3 = ReadHeader(u8a,si,ctx);
608
+ si = a3[2];
609
+ a3 = ReadObject(u8a,si,ctx);
610
+ return(a3[0])
611
+ }
612
+
613
+
614
+ module.exports = {
615
+ ERRD,
616
+ ////
617
+ ReadVarintLoopIfLshiftWork,
618
+ ReadVarint,
619
+ ReadHeader,
620
+ ReadTag,
621
+ ReadZigZag,
622
+ ReadDouble,
623
+ ReadRawBytes,
624
+ ReadByte,
625
+ ReadUint32,
626
+ ReadBigInt,BI_MUL,
627
+ ReadOneByteString,
628
+ ReadTwoByteString,
629
+ ReadUtf8String,
630
+ ReadJSDate,
631
+ ReadString,
632
+ ReadJSRegExp,
633
+ ReadJSError,
634
+ ReadJSSet,
635
+ ReadJSMap,
636
+ ReadHostObject,
637
+ ReadJSArrayBufferView,
638
+ ReadJSArrayBuffer,
639
+ ReadJSObjectProperties,
640
+ ReadObjectInternal,
641
+ ReadObject,
642
+ ReadJSObject,
643
+ ReadJSArray,
644
+ ////
645
+ decd
646
+ }
package/restrict.js ADDED
@@ -0,0 +1,48 @@
1
+ module.exports = {
2
+ kTheHole : 'the hole element will be replaced by undefined',
3
+ kSparseArray : `
4
+ NOT support. only dense/packed_smi/packed_double.
5
+ hard to explain this, refer to ./TEST/hole-tst.js
6
+ this script will make sparse-array
7
+ `,
8
+ kSharedArrayBuffer : 'treated as normal ArrayBuffer',
9
+ kArrayBufferView : `
10
+ 0. array-buffer-view will be treated as kHostObject,for compatible with nodjes delegate,
11
+ event if several array-buf-views refer to the same buffer, still be deepcopy:
12
+ var ab = new ArrayBuffer(4);
13
+ var u8a = new Uint8Array(ab);
14
+ var u16a = new Uint16Array(ab);
15
+ var ary = [ab,u8a,u16a];
16
+ var dupe_ary = der(ser(ary));
17
+ /*
18
+ 1. dupe_ary[0]
19
+ 2. dupe_ary[1].buffer
20
+ 3. dupe_ary[2].buffer
21
+
22
+ [1. 2. 3.] are different buffer, this means:
23
+ the abview NOT support keeping the ref-of-<.buffer>-relations
24
+ */
25
+ `,
26
+ JSMap : "extra attributes set On Map will be dropped, for compatible to current v8-impl",
27
+ JSSet : "extra attributes set On Set will be dropped, for compatible to current v8-impl",
28
+ RegExp : "extra attributes set On RegExp will be dropped, for compatible to current v8-impl",
29
+ Date : "extra attributes set On Date will be dropped, for compatible to current v8-impl",
30
+ PrimitiveWrapper : `
31
+ extra attributes set On PrimitiveWrapper will be dropped, for compatible to current v8-impl;
32
+ not support <new BigInt>, in c++ layer ,it can be done, in js-layer ,impossible
33
+ `,
34
+ ////
35
+ "Error'message" : "Error'message treated as string",
36
+ "Error'stack" : "Error'stack treated as string",
37
+ ////
38
+ kVerifyObjectCount : "no verify",
39
+ throwDetachedArrayBufferError : "dont know how to get this state in js-layer",
40
+ kArrayBufferTransfer : "hard to do this in js-layer",
41
+ kSharedObject : 'hard to do this in js-layer',
42
+ kWasmModuleTransfer : 'hard to do this in js-layer',
43
+ kWasmMemoryTransfer : 'hard to do this in js-layer',
44
+ ITERATOR : "dont know how to get the iter cursor in js-layer, treated as a {}",
45
+ ATOMICS : "dont know how to do this, treated as a {}",
46
+ FPG : "function | lambda | promise| generator| all treated as a {}",
47
+ Proxy : "hard to do this in browser, so treated as the-target-be-proxied",
48
+ }