@agoric/xsnap 0.14.3-dev-b047af2.0 → 0.14.3-dev-3eb4230.0

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 (126) hide show
  1. package/api.js +1 -1
  2. package/package.json +16 -23
  3. package/src/build.js +4 -61
  4. package/moddable/modules/data/base64/base64.js +0 -28
  5. package/moddable/modules/data/base64/manifest.json +0 -11
  6. package/moddable/modules/data/base64/modBase64.c +0 -188
  7. package/moddable/modules/data/binaryMessage/BinaryMessage.js +0 -106
  8. package/moddable/modules/data/crc/crc.c +0 -205
  9. package/moddable/modules/data/crc/crc.js +0 -36
  10. package/moddable/modules/data/crc/manifest.json +0 -8
  11. package/moddable/modules/data/hex/hex.js +0 -28
  12. package/moddable/modules/data/hex/manifest.json +0 -11
  13. package/moddable/modules/data/hex/modHex.c +0 -139
  14. package/moddable/modules/data/logical/logical.js +0 -32
  15. package/moddable/modules/data/logical/modLogical.c +0 -98
  16. package/moddable/modules/data/qrcode/manifest.json +0 -9
  17. package/moddable/modules/data/qrcode/qrcode.c +0 -93
  18. package/moddable/modules/data/qrcode/qrcode.js +0 -23
  19. package/moddable/modules/data/qrcode/qrcodegen.c +0 -1025
  20. package/moddable/modules/data/qrcode/qrcodegen.h +0 -267
  21. package/moddable/modules/data/text/decoder/manifest.json +0 -8
  22. package/moddable/modules/data/text/decoder/textdecoder.c +0 -480
  23. package/moddable/modules/data/text/decoder/textdecoder.js +0 -27
  24. package/moddable/modules/data/text/encoder/manifest.json +0 -8
  25. package/moddable/modules/data/text/encoder/textencoder.c +0 -232
  26. package/moddable/modules/data/text/encoder/textencoder.js +0 -24
  27. package/moddable/modules/data/tinyint/tinyint.c +0 -150
  28. package/moddable/modules/data/tinyint/tinyint.js +0 -53
  29. package/moddable/modules/data/url/manifest.json +0 -17
  30. package/moddable/modules/data/url/url.c +0 -1959
  31. package/moddable/modules/data/url/url.js +0 -210
  32. package/moddable/modules/data/wavreader/manifest.json +0 -8
  33. package/moddable/modules/data/wavreader/wavreader.js +0 -128
  34. package/moddable/modules/data/zlib/deflate.c +0 -161
  35. package/moddable/modules/data/zlib/deflate.js +0 -63
  36. package/moddable/modules/data/zlib/inflate.c +0 -145
  37. package/moddable/modules/data/zlib/inflate.js +0 -66
  38. package/moddable/modules/data/zlib/manifest_deflate.json +0 -9
  39. package/moddable/modules/data/zlib/manifest_inflate.json +0 -9
  40. package/moddable/modules/data/zlib/miniz.c +0 -4924
  41. package/moddable/xs/includes/xs.d.ts +0 -73
  42. package/moddable/xs/includes/xs.h +0 -1533
  43. package/moddable/xs/includes/xsmc.h +0 -206
  44. package/moddable/xs/makefiles/lin/makefile +0 -33
  45. package/moddable/xs/makefiles/lin/xsc.mk +0 -118
  46. package/moddable/xs/makefiles/lin/xsid.mk +0 -90
  47. package/moddable/xs/makefiles/lin/xsl.mk +0 -168
  48. package/moddable/xs/makefiles/lin/xst.mk +0 -201
  49. package/moddable/xs/makefiles/mac/makefile +0 -33
  50. package/moddable/xs/makefiles/mac/xsc.mk +0 -130
  51. package/moddable/xs/makefiles/mac/xsid.mk +0 -102
  52. package/moddable/xs/makefiles/mac/xsl.mk +0 -177
  53. package/moddable/xs/makefiles/mac/xst.mk +0 -203
  54. package/moddable/xs/makefiles/mac/xst_no_asan.txt +0 -52
  55. package/moddable/xs/makefiles/win/build.bat +0 -26
  56. package/moddable/xs/makefiles/win/xsc.mak +0 -142
  57. package/moddable/xs/makefiles/win/xsid.mak +0 -113
  58. package/moddable/xs/makefiles/win/xsl.mak +0 -186
  59. package/moddable/xs/makefiles/win/xst.mak +0 -195
  60. package/moddable/xs/platforms/lin_xs.h +0 -99
  61. package/moddable/xs/platforms/mac_xs.h +0 -97
  62. package/moddable/xs/platforms/wasm_xs.h +0 -79
  63. package/moddable/xs/platforms/win_xs.h +0 -104
  64. package/moddable/xs/platforms/xsHost.h +0 -63
  65. package/moddable/xs/platforms/xsPlatform.h +0 -618
  66. package/moddable/xs/sources/xsAPI.c +0 -2555
  67. package/moddable/xs/sources/xsAll.c +0 -294
  68. package/moddable/xs/sources/xsAll.h +0 -2741
  69. package/moddable/xs/sources/xsArguments.c +0 -222
  70. package/moddable/xs/sources/xsArray.c +0 -2657
  71. package/moddable/xs/sources/xsAtomics.c +0 -844
  72. package/moddable/xs/sources/xsBigInt.c +0 -1859
  73. package/moddable/xs/sources/xsBoolean.c +0 -109
  74. package/moddable/xs/sources/xsCode.c +0 -4493
  75. package/moddable/xs/sources/xsCommon.c +0 -1710
  76. package/moddable/xs/sources/xsCommon.h +0 -1142
  77. package/moddable/xs/sources/xsDataView.c +0 -2890
  78. package/moddable/xs/sources/xsDate.c +0 -1541
  79. package/moddable/xs/sources/xsDebug.c +0 -2710
  80. package/moddable/xs/sources/xsDefaults.c +0 -134
  81. package/moddable/xs/sources/xsError.c +0 -353
  82. package/moddable/xs/sources/xsFunction.c +0 -776
  83. package/moddable/xs/sources/xsGenerator.c +0 -865
  84. package/moddable/xs/sources/xsGlobal.c +0 -839
  85. package/moddable/xs/sources/xsJSON.c +0 -1091
  86. package/moddable/xs/sources/xsLexical.c +0 -1969
  87. package/moddable/xs/sources/xsLockdown.c +0 -933
  88. package/moddable/xs/sources/xsMapSet.c +0 -1649
  89. package/moddable/xs/sources/xsMarshall.c +0 -1020
  90. package/moddable/xs/sources/xsMath.c +0 -624
  91. package/moddable/xs/sources/xsMemory.c +0 -1941
  92. package/moddable/xs/sources/xsModule.c +0 -3101
  93. package/moddable/xs/sources/xsNumber.c +0 -560
  94. package/moddable/xs/sources/xsObject.c +0 -1102
  95. package/moddable/xs/sources/xsPlatforms.c +0 -480
  96. package/moddable/xs/sources/xsProfile.c +0 -577
  97. package/moddable/xs/sources/xsPromise.c +0 -1199
  98. package/moddable/xs/sources/xsProperty.c +0 -636
  99. package/moddable/xs/sources/xsProxy.c +0 -1014
  100. package/moddable/xs/sources/xsRegExp.c +0 -1168
  101. package/moddable/xs/sources/xsRun.c +0 -4889
  102. package/moddable/xs/sources/xsScope.c +0 -1293
  103. package/moddable/xs/sources/xsScript.c +0 -288
  104. package/moddable/xs/sources/xsScript.h +0 -1186
  105. package/moddable/xs/sources/xsSnapshot.c +0 -2161
  106. package/moddable/xs/sources/xsSnapshot.h +0 -51
  107. package/moddable/xs/sources/xsSourceMap.c +0 -218
  108. package/moddable/xs/sources/xsString.c +0 -3332
  109. package/moddable/xs/sources/xsSymbol.c +0 -503
  110. package/moddable/xs/sources/xsSyntaxical.c +0 -4193
  111. package/moddable/xs/sources/xsTree.c +0 -1893
  112. package/moddable/xs/sources/xsType.c +0 -1488
  113. package/moddable/xs/sources/xsdtoa.c +0 -6672
  114. package/moddable/xs/sources/xsmc.c +0 -340
  115. package/moddable/xs/sources/xsre.c +0 -7578
  116. package/xsnap-native/xsnap/makefiles/lin/makefile +0 -10
  117. package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +0 -153
  118. package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +0 -144
  119. package/xsnap-native/xsnap/makefiles/mac/makefile +0 -10
  120. package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +0 -162
  121. package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +0 -153
  122. package/xsnap-native/xsnap/sources/xsnap-worker.c +0 -996
  123. package/xsnap-native/xsnap/sources/xsnap.c +0 -716
  124. package/xsnap-native/xsnap/sources/xsnap.h +0 -142
  125. package/xsnap-native/xsnap/sources/xsnapPlatform.c +0 -1496
  126. package/xsnap-native/xsnap/sources/xsnapPlatform.h +0 -105
@@ -1,1020 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-2018 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- * This file incorporates work covered by the following copyright and
20
- * permission notice:
21
- *
22
- * Copyright (C) 2010-2016 Marvell International Ltd.
23
- * Copyright (C) 2002-2010 Kinoma, Inc.
24
- *
25
- * Licensed under the Apache License, Version 2.0 (the "License");
26
- * you may not use this file except in compliance with the License.
27
- * You may obtain a copy of the License at
28
- *
29
- * http://www.apache.org/licenses/LICENSE-2.0
30
- *
31
- * Unless required by applicable law or agreed to in writing, software
32
- * distributed under the License is distributed on an "AS IS" BASIS,
33
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
- * See the License for the specific language governing permissions and
35
- * limitations under the License.
36
- */
37
-
38
- #include "xsAll.h"
39
-
40
- #if mx32bitID
41
- #define mxSymbolBit 0x80000000
42
- #define mxSymbolMask 0x7FFFFFFF
43
- #else
44
- #define mxSymbolBit 0x8000
45
- #define mxSymbolMask 0x7FFF
46
- #endif
47
-
48
- typedef struct sxMarshallBuffer txMarshallBuffer;
49
- struct sxMarshallBuffer {
50
- txByte* base;
51
- txByte* current;
52
- txSlot* link;
53
- txID* symbolMap;
54
- txSize size;
55
- txID symbolCount;
56
- txSize symbolSize;
57
- txSlot* stack;
58
- };
59
-
60
- static void fxDemarshallChunk(txMachine* the, void* theData, void** theDataAddress);
61
- static txID fxDemarshallKey(txMachine* the, txID id, txID* theSymbolMap, txBoolean alien);
62
- static void fxDemarshallReference(txMachine* the, txSlot* theSlot, txSlot** theSlotAddress, txID* theSymbolMap, txBoolean alien);
63
- static void fxDemarshallSlot(txMachine* the, txSlot* theSlot, txSlot* theResult, txID* theSymbolMap, txBoolean alien);
64
- static void fxMarshallChunk(txMachine* the, void* theData, void** theDataAddress, txMarshallBuffer* theBuffer);
65
- static txID fxMarshallKey(txMachine* the, txID id, txMarshallBuffer* theBuffer, txBoolean alien);
66
- static void fxMarshallReference(txMachine* the, txSlot* theSlot, txSlot** theSlotAddress, txMarshallBuffer* theBuffer, txBoolean alien);
67
- static txBoolean fxMarshallSlot(txMachine* the, txSlot* theSlot, txSlot** theSlotAddress, txMarshallBuffer* theBuffer, txBoolean alien);
68
- static void fxMeasureChunk(txMachine* the, void* theData, txMarshallBuffer* theBuffer);
69
- static void fxMeasureKey(txMachine* the, txID theID, txMarshallBuffer* theBuffer, txBoolean alien);
70
- static void fxMeasureReference(txMachine* the, txSlot* theSlot, txMarshallBuffer* theBuffer, txBoolean alien);
71
- static void fxMeasureSlot(txMachine* the, txSlot* theSlot, txMarshallBuffer* theBuffer, txBoolean alien);
72
- static void fxMeasureThrow(txMachine* the, txMarshallBuffer* theBuffer, txString message);
73
-
74
- #define mxMarshallAlign(POINTER,SIZE) \
75
- if (((SIZE) &= ((sizeof(txNumber) - 1)))) (POINTER) += sizeof(txNumber) - (SIZE)
76
-
77
- void fxDemarshall(txMachine* the, void* theData, txBoolean alien)
78
- {
79
- txFlag aFlag;
80
- txByte* p;
81
- txByte* q;
82
- txID aSymbolCount;
83
- txID aSymbolLength;
84
- txID* aSymbolMap;
85
- txID* aSymbolPointer;
86
- txSlot* aSlot;
87
- txChunk* aChunk;
88
- txInteger skipped;
89
- txIndex aLength;
90
-
91
- if (!theData) {
92
- the->stack->kind = XS_UNDEFINED_KIND;
93
- return;
94
- }
95
- p = (txByte*)theData;
96
- q = p + *((txSize*)(p));
97
- aFlag = (txFlag)the->collectFlag;
98
- the->collectFlag &= ~(XS_COLLECTING_FLAG | XS_SKIPPED_COLLECT_FLAG);
99
- {
100
- mxTry(the) {
101
- p += sizeof(txSize);
102
- aSymbolCount = *((txID*)p);
103
- p += sizeof(txID);
104
- aSymbolMap = aSymbolPointer = (txID*)p;
105
- p += aSymbolCount * sizeof(txID);
106
- while (aSymbolCount) {
107
- txID id;
108
- aSymbolLength = *aSymbolPointer;
109
- if ((aSymbolLength & mxSymbolBit) == 0)
110
- id = fxNewNameC(the, (char *)p);
111
- else {
112
- aSymbolLength = aSymbolLength & mxSymbolMask;
113
- id = the->keyIndex;
114
- if (id == the->keyCount)
115
- fxGrowKeys(the, 1);
116
- if (aSymbolLength > 1) {
117
- aSlot = fxNewSlot(the);
118
- aSlot->kind = XS_STRING_KIND;
119
- aSlot->value.string = (txString)fxNewChunk(the, mxStringLength((char *)p) + 1);
120
- c_strcpy(aSlot->value.key.string, (char *)p);
121
- }
122
- else
123
- aSlot = C_NULL;
124
- the->keyArray[id - the->keyOffset] = aSlot;
125
- the->keyIndex++;
126
- }
127
- *aSymbolPointer++ = id;
128
- aSymbolCount--;
129
- p += aSymbolLength;
130
- }
131
- aLength = mxPtrDiff(p - (txByte*)theData);
132
- mxMarshallAlign(p, aLength);
133
- mxPushUndefined();
134
- fxDemarshallSlot(the, (txSlot*)p, the->stack, aSymbolMap, alien);
135
- }
136
- mxCatch(the) {
137
- the->stack->kind = XS_UNDEFINED_KIND;
138
- break;
139
- }
140
- while (p < q) {
141
- aSlot = (txSlot*)p;
142
- p += sizeof(txSlot);
143
- switch (aSlot->kind) {
144
- case XS_STRING_KIND:
145
- case XS_BIGINT_KIND:
146
- case XS_ARRAY_BUFFER_KIND:
147
- aChunk = (txChunk*)p;
148
- p += aChunk->size;
149
- mxMarshallAlign(p, aChunk->size);
150
- break;
151
- case XS_REGEXP_KIND:
152
- if (aSlot->value.regexp.code) {
153
- aChunk = (txChunk*)p;
154
- p += aChunk->size;
155
- mxMarshallAlign(p, aChunk->size);
156
- }
157
- if (aSlot->value.regexp.data) {
158
- aChunk = (txChunk*)p;
159
- p += aChunk->size;
160
- mxMarshallAlign(p, aChunk->size);
161
- }
162
- break;
163
- case XS_INSTANCE_KIND:
164
- aSlot->value.instance.garbage = C_NULL;
165
- break;
166
- }
167
- }
168
- }
169
- skipped = the->collectFlag & XS_SKIPPED_COLLECT_FLAG;
170
- the->collectFlag = aFlag;
171
- if (skipped)
172
- fxCollectGarbage(the);
173
- }
174
-
175
- void fxDemarshallChunk(txMachine* the, void* theData, void** theDataAddress)
176
- {
177
- txSize aSize = ((txChunk*)(((txByte*)theData) - sizeof(txChunk)))->size - sizeof(txChunk);
178
- txByte* aResult = (txByte *)fxNewChunk(the, aSize);
179
- c_memcpy(aResult, theData, aSize);
180
- *theDataAddress = aResult;
181
- }
182
-
183
- txID fxDemarshallKey(txMachine* the, txID id, txID* theSymbolMap, txBoolean alien)
184
- {
185
- if (id != XS_NO_ID) {
186
- if (alien)
187
- id = theSymbolMap[id - 1];
188
- else if (id >= the->keyOffset)
189
- id = theSymbolMap[id - the->keyOffset];
190
- }
191
- return id;
192
- }
193
-
194
- void fxDemarshallReference(txMachine* the, txSlot* theSlot, txSlot** theSlotAddress, txID* theSymbolMap, txBoolean alien)
195
- {
196
- if (!alien && (theSlot->flag & XS_DONT_MARSHALL_FLAG))
197
- *theSlotAddress = theSlot;
198
- else if (theSlot->value.instance.garbage)
199
- *theSlotAddress = theSlot->value.instance.garbage;
200
- else {
201
- *theSlotAddress = fxNewSlot(the);
202
- fxDemarshallSlot(the, theSlot, *theSlotAddress, theSymbolMap, alien);
203
- }
204
- }
205
-
206
- void fxDemarshallSlot(txMachine* the, txSlot* theSlot, txSlot* theResult, txID* theSymbolMap, txBoolean alien)
207
- {
208
- txSlot* aSlot;
209
- txIndex aLength, index;
210
- txSlot* aResult;
211
- txSlot** aSlotAddress;
212
-
213
- if (!(theSlot->flag & XS_INTERNAL_FLAG))
214
- theResult->ID = fxDemarshallKey(the, theSlot->ID, theSymbolMap, alien);
215
- else
216
- theResult->ID = theSlot->ID;
217
- theResult->flag = theSlot->flag;
218
- switch (theSlot->kind) {
219
- case XS_UNDEFINED_KIND:
220
- case XS_NULL_KIND:
221
- case XS_BOOLEAN_KIND:
222
- case XS_INTEGER_KIND:
223
- case XS_NUMBER_KIND:
224
- case XS_DATE_KIND:
225
- case XS_STRING_X_KIND:
226
- case XS_BIGINT_X_KIND:
227
- case XS_DATA_VIEW_KIND:
228
- case XS_KEY_X_KIND:
229
- case XS_BUFFER_INFO_KIND:
230
- theResult->value = theSlot->value;
231
- theResult->kind = theSlot->kind;
232
- break;
233
-
234
- case XS_STRING_KIND:
235
- fxDemarshallChunk(the, theSlot->value.string, (void **)&theResult->value.string);
236
- theResult->kind = theSlot->kind;
237
- break;
238
- case XS_BIGINT_KIND:
239
- fxDemarshallChunk(the, theSlot->value.bigint.data, (void **)&theResult->value.bigint.data);
240
- theResult->value.bigint.size = theSlot->value.bigint.size;
241
- theResult->value.bigint.sign = theSlot->value.bigint.sign;
242
- theResult->kind = theSlot->kind;
243
- break;
244
- case XS_ARRAY_BUFFER_KIND:
245
- if (theSlot->value.arrayBuffer.address)
246
- fxDemarshallChunk(the, theSlot->value.arrayBuffer.address, (void **)&(theResult->value.arrayBuffer.address));
247
- else
248
- theResult->value.arrayBuffer.address = C_NULL;
249
- theResult->kind = theSlot->kind;
250
- break;
251
- case XS_REGEXP_KIND:
252
- if (theSlot->value.regexp.code)
253
- fxDemarshallChunk(the, theSlot->value.regexp.code, (void**)&(theResult->value.regexp.code));
254
- else
255
- theResult->value.regexp.code = C_NULL;
256
- if (theSlot->value.regexp.data)
257
- fxDemarshallChunk(the, theSlot->value.regexp.data, (void**)&(theResult->value.regexp.data));
258
- else
259
- theResult->value.regexp.data = C_NULL;
260
- theResult->kind = theSlot->kind;
261
- break;
262
- case XS_KEY_KIND:
263
- if (theSlot->value.key.string)
264
- fxDemarshallChunk(the, theSlot->value.key.string, (void **)&theResult->value.key.string);
265
- else
266
- theResult->value.key.string = C_NULL;
267
- theResult->value.key.sum = theSlot->value.key.sum;
268
- theResult->kind = theSlot->kind;
269
- break;
270
-
271
- case XS_SYMBOL_KIND:
272
- theResult->value.symbol = fxDemarshallKey(the, theSlot->value.symbol, theSymbolMap, alien);
273
- theResult->kind = theSlot->kind;
274
- break;
275
-
276
- case XS_HOST_KIND:
277
- theResult->value.host.data = fxRetainSharedChunk(theSlot->value.host.data);
278
- theResult->value.host.variant.destructor = fxReleaseSharedChunk;
279
- theResult->kind = theSlot->kind;
280
- break;
281
- case XS_MAP_KIND:
282
- case XS_SET_KIND:
283
- theResult->value.table.length = theSlot->value.table.length;
284
- aSlotAddress = (txSlot**)fxNewChunk(the, theResult->value.table.length * sizeof(txSlot*));
285
- c_memset(aSlotAddress, 0, theResult->value.table.length * sizeof(txSlot*));
286
- theResult->value.table.address = aSlotAddress;
287
- theResult->kind = theSlot->kind;
288
- break;
289
- case XS_TYPED_ARRAY_KIND:
290
- theResult->value.typedArray.dispatch = (txTypeDispatch*)&gxTypeDispatches[theSlot->value.integer];
291
- theResult->value.typedArray.atomics = (txTypeAtomics*)&gxTypeAtomics[theSlot->value.integer];
292
- theResult->kind = theSlot->kind;
293
- break;
294
-
295
- case XS_REFERENCE_KIND:
296
- theResult->kind = theSlot->kind;
297
- fxDemarshallReference(the, theSlot->value.reference, &theResult->value.reference, theSymbolMap, alien);
298
- break;
299
- case XS_INSTANCE_KIND:
300
- theSlot->value.instance.garbage = theResult;
301
- theResult->value.instance.garbage = C_NULL;
302
- theResult->kind = theSlot->kind;
303
- aSlot = theSlot->next;
304
- if (!alien && theSlot->value.instance.prototype) {
305
- theResult->value.instance.prototype = theSlot->value.instance.prototype;
306
- }
307
- else {
308
- theResult->value.instance.prototype = mxObjectPrototype.value.reference;
309
- if (aSlot) {
310
- if (aSlot->flag & XS_INTERNAL_FLAG) {
311
- if (aSlot->ID == XS_ARRAY_BEHAVIOR)
312
- theResult->value.instance.prototype = mxArrayPrototype.value.reference;
313
- else {
314
- switch (aSlot->kind) {
315
- case XS_ARRAY_BUFFER_KIND: theResult->value.instance.prototype = mxArrayBufferPrototype.value.reference; break;
316
- case XS_BOOLEAN_KIND: theResult->value.instance.prototype = mxBooleanPrototype.value.reference; break;
317
- case XS_DATA_VIEW_KIND: theResult->value.instance.prototype = mxDataViewPrototype.value.reference; break;
318
- case XS_DATE_KIND: theResult->value.instance.prototype = mxDatePrototype.value.reference; break;
319
- case XS_ERROR_KIND: theResult->value.instance.prototype = mxErrorPrototypes(aSlot->value.error.which).value.reference; break;
320
- case XS_HOST_KIND: theResult->value.instance.prototype = mxSharedArrayBufferPrototype.value.reference; break;
321
- case XS_MAP_KIND: theResult->value.instance.prototype = mxMapPrototype.value.reference; break;
322
- case XS_NUMBER_KIND: theResult->value.instance.prototype = mxNumberPrototype.value.reference; break;
323
- case XS_REGEXP_KIND: theResult->value.instance.prototype = mxRegExpPrototype.value.reference; break;
324
- case XS_SET_KIND: theResult->value.instance.prototype = mxSetPrototype.value.reference; break;
325
- case XS_STRING_KIND: theResult->value.instance.prototype = mxStringPrototype.value.reference; break;
326
- case XS_TYPED_ARRAY_KIND: {
327
- txTypeDispatch* dispatch = (txTypeDispatch*)&gxTypeDispatches[aSlot->value.integer];
328
- mxPush(the->stackPrototypes[-1 - (txInteger)dispatch->constructorID]);
329
- mxGetID(mxID(_prototype));
330
- theResult->value.instance.prototype = the->stack->value.reference;
331
- mxPop();
332
- } break;
333
- }
334
- }
335
- }
336
- }
337
- }
338
- aSlotAddress = &(theResult->next);
339
- while (aSlot) {
340
- *aSlotAddress = fxNewSlot(the);
341
- fxDemarshallSlot(the, aSlot, *aSlotAddress, theSymbolMap, alien);
342
- aSlot = aSlot->next;
343
- aSlotAddress = &((*aSlotAddress)->next);
344
- }
345
- aSlot = theResult->next;
346
- if (aSlot) {
347
- if (aSlot->kind == XS_MAP_KIND) {
348
- txSlot* key = aSlot->next->value.list.first;
349
- while (key) {
350
- txSlot* value = key->next;
351
- txU4 sum = fxSumEntry(the, key);
352
- txU4 modulo = sum % aSlot->value.table.length;
353
- txSlot** address = &(aSlot->value.table.address[modulo]);
354
- txSlot* entry = fxNewSlot(the);
355
- entry->next = *address;
356
- entry->kind = XS_ENTRY_KIND;
357
- entry->value.entry.slot = key;
358
- entry->value.entry.sum = sum;
359
- *address = entry;
360
- key = value->next;
361
- }
362
- }
363
- else if (aSlot->kind == XS_SET_KIND) {
364
- txSlot* key = aSlot->next->value.list.first;
365
- while (key) {
366
- txU4 sum = fxSumEntry(the, key);
367
- txU4 modulo = sum % aSlot->value.table.length;
368
- txSlot** address = &(aSlot->value.table.address[modulo]);
369
- txSlot* entry = fxNewSlot(the);
370
- entry->next = *address;
371
- entry->kind = XS_ENTRY_KIND;
372
- entry->value.entry.slot = key;
373
- entry->value.entry.sum = sum;
374
- *address = entry;
375
- key = key->next;
376
- }
377
- }
378
- }
379
- break;
380
- case XS_ARRAY_KIND:
381
- theResult->value.array.length = 0;
382
- theResult->value.array.address = C_NULL;
383
- theResult->kind = theSlot->kind;
384
- if ((aLength = theSlot->value.array.length)) {
385
- theResult->value.array.length = aLength;
386
- theResult->value.array.address = (txSlot *)fxNewChunk(the, aLength * sizeof(txSlot));
387
- c_memset(theResult->value.array.address, 0, aLength * sizeof(txSlot));
388
- aSlot = theSlot->value.array.address;
389
- aResult = theResult->value.array.address;
390
- index = 0;
391
- while (aLength) {
392
- fxDemarshallSlot(the, aSlot, aResult, theSymbolMap, alien);
393
- aLength--;
394
- aSlot = aSlot->next;
395
- *((txIndex*)aResult) = index;
396
- aResult++;
397
- index++;
398
- }
399
- }
400
- break;
401
- case XS_ERROR_KIND:
402
- theResult->kind = theSlot->kind;
403
- if (theSlot->value.error.info)
404
- fxDemarshallReference(the, theSlot->value.error.info, &theResult->value.error.info, theSymbolMap, alien);
405
- else
406
- theResult->value.error.info = C_NULL;
407
- theResult->value.error.which = theSlot->value.error.which;
408
- break;
409
- case XS_PROXY_KIND:
410
- theResult->kind = theSlot->kind;
411
- if (theSlot->value.proxy.handler)
412
- fxDemarshallReference(the, theSlot->value.proxy.handler, &theResult->value.proxy.handler, theSymbolMap, alien);
413
- else
414
- theResult->value.proxy.handler = C_NULL;
415
- if (theSlot->value.proxy.target)
416
- fxDemarshallReference(the, theSlot->value.proxy.target, &theResult->value.proxy.target, theSymbolMap, alien);
417
- else
418
- theResult->value.proxy.target = C_NULL;
419
- break;
420
-
421
- case XS_LIST_KIND:
422
- aSlot = theSlot->value.list.first;
423
- aSlotAddress = &(theResult->value.list.first);
424
- while (aSlot) {
425
- theResult->value.list.last = *aSlotAddress = fxNewSlot(the);
426
- fxDemarshallSlot(the, aSlot, *aSlotAddress, theSymbolMap, alien);
427
- aSlot = aSlot->next;
428
- aSlotAddress = &((*aSlotAddress)->next);
429
- }
430
- theResult->kind = theSlot->kind;
431
- break;
432
- case XS_PRIVATE_KIND:
433
- aSlot = theSlot->value.private.first;
434
- aSlotAddress = &(theResult->value.private.first);
435
- while (aSlot) {
436
- *aSlotAddress = fxNewSlot(the);
437
- fxDemarshallSlot(the, aSlot, *aSlotAddress, theSymbolMap, alien);
438
- aSlot = aSlot->next;
439
- aSlotAddress = &((*aSlotAddress)->next);
440
- }
441
- theResult->value.private.check = theSlot->value.private.check;
442
- theResult->kind = theSlot->kind;
443
- break;
444
- default:
445
- break;
446
- }
447
- }
448
-
449
- void* fxMarshall(txMachine* the, txBoolean alien)
450
- {
451
- txMarshallBuffer aBuffer = { C_NULL, C_NULL, C_NULL, C_NULL, 0, 0, 0 };
452
- txSlot* aSlot;
453
- txSlot* bSlot;
454
- txSlot* cSlot;
455
-
456
- mxTry(the) {
457
- size_t mapSize = alien ? the->keyIndex : (the->keyIndex - the->keyOffset);
458
- aBuffer.symbolSize = sizeof(txSize) + sizeof(txID);
459
- aBuffer.symbolMap = c_calloc(mapSize, sizeof(txID));
460
- if (mapSize && !aBuffer.symbolMap)
461
- mxUnknownError("out of memory");
462
- the->stack->ID = XS_NO_ID;
463
- aBuffer.stack = the->stack;
464
- fxMeasureSlot(the, the->stack, &aBuffer, alien);
465
-
466
- aBuffer.size += aBuffer.symbolSize;
467
- mxMarshallAlign(aBuffer.size, aBuffer.symbolSize);
468
- aBuffer.base = aBuffer.current = (txByte *)c_malloc(aBuffer.size);
469
- if (!aBuffer.base)
470
- mxUnknownError("out of memory");
471
- *((txSize*)(aBuffer.current)) = aBuffer.size;
472
- aBuffer.current += sizeof(txSize);
473
- *((txID*)(aBuffer.current)) = aBuffer.symbolCount;
474
- aBuffer.current += sizeof(txID);
475
- if (aBuffer.symbolCount) {
476
- txID* lengths = (txID*)aBuffer.current;
477
- txID* map = aBuffer.symbolMap;
478
- txID dstIndex = 1;
479
- txSlot** p;
480
- txSlot** q;
481
- aBuffer.current += aBuffer.symbolCount * sizeof(txID);
482
- if (alien) {
483
- p = the->keyArrayHost;
484
- q = p + the->keyOffset;
485
- while (p < q) {
486
- txID length = *map;
487
- if (length) {
488
- *map = dstIndex;
489
- if ((*p) && ((*p)->flag & XS_DONT_ENUM_FLAG)) {
490
- *lengths++ = length;
491
- c_memcpy(aBuffer.current, (*p)->value.key.string, length);
492
- }
493
- else {
494
- *lengths++ = mxSymbolBit | length;
495
- if (length > 1)
496
- c_memcpy(aBuffer.current, (*p)->value.string, length);
497
- else
498
- *aBuffer.current = 0;
499
- }
500
- aBuffer.current += length;
501
- dstIndex++;
502
- }
503
- map++;
504
- p++;
505
- }
506
- }
507
- else
508
- dstIndex = the->keyOffset;
509
- p = the->keyArray;
510
- q = p + the->keyIndex - the->keyOffset;
511
- while (p < q) {
512
- txID length = *map;
513
- if (length) {
514
- *map = dstIndex;
515
- if ((*p) && ((*p)->flag & XS_DONT_ENUM_FLAG)) {
516
- *lengths++ = length;
517
- c_memcpy(aBuffer.current, (*p)->value.key.string, length);
518
- }
519
- else {
520
- *lengths++ = mxSymbolBit | length;
521
- if (length > 1)
522
- c_memcpy(aBuffer.current, (*p)->value.string, length);
523
- else
524
- *aBuffer.current = 0;
525
- }
526
- aBuffer.current += length;
527
- dstIndex++;
528
- }
529
- map++;
530
- p++;
531
- }
532
- }
533
- mxMarshallAlign(aBuffer.current, aBuffer.symbolSize);
534
-
535
- fxMarshallSlot(the, the->stack, &aSlot, &aBuffer, alien);
536
- aSlot = aBuffer.link;
537
- while (aSlot) {
538
- bSlot = aSlot->value.instance.garbage;
539
- aSlot->flag &= ~XS_MARK_FLAG;
540
- aSlot->value.instance.garbage = C_NULL;
541
- aSlot = bSlot;
542
- }
543
-
544
- mxCheck(the, aBuffer.current == aBuffer.base + aBuffer.size);
545
- }
546
- mxCatch(the) {
547
- aSlot = the->firstHeap;
548
- while (aSlot) {
549
- bSlot = aSlot + 1;
550
- cSlot = aSlot->value.reference;
551
- while (bSlot < cSlot) {
552
- bSlot->flag &= ~XS_MARK_FLAG;
553
- bSlot++;
554
- }
555
- aSlot = aSlot->next;
556
- }
557
- if (aBuffer.base)
558
- c_free(aBuffer.base);
559
- if (aBuffer.symbolMap)
560
- c_free(aBuffer.symbolMap);
561
- fxJump(the);
562
- }
563
- mxPop();
564
- c_free(aBuffer.symbolMap);
565
- return aBuffer.base;
566
- }
567
-
568
- void fxMarshallChunk(txMachine* the, void* theData, void** theDataAddress, txMarshallBuffer* theBuffer)
569
- {
570
- txChunk* aChunk = ((txChunk*)(((txByte*)theData) - sizeof(txChunk)));
571
- txSize aSize = aChunk->size & 0x7FFFFFFF;
572
- txByte* aResult = theBuffer->current;
573
- theBuffer->current += aSize;
574
- c_memcpy(aResult, aChunk, aSize);
575
- aChunk = (txChunk*)aResult;
576
- aChunk->size &= 0x7FFFFFFF;
577
- *theDataAddress = aResult + sizeof(txChunk);
578
- mxMarshallAlign(theBuffer->current, aSize);
579
- }
580
-
581
- txID fxMarshallKey(txMachine* the, txID id, txMarshallBuffer* theBuffer, txBoolean alien)
582
- {
583
- if (id != XS_NO_ID) {
584
- if (alien) {
585
- id = theBuffer->symbolMap[id];
586
- }
587
- else if (id >= the->keyOffset) {
588
- id = theBuffer->symbolMap[id - the->keyOffset];
589
- }
590
- }
591
- return id;
592
- }
593
-
594
- void fxMarshallReference(txMachine* the, txSlot* theSlot, txSlot** theSlotAddress, txMarshallBuffer* theBuffer, txBoolean alien)
595
- {
596
- if (!alien && (theSlot->flag & XS_DONT_MARSHALL_FLAG))
597
- *theSlotAddress = theSlot;
598
- else if (theSlot->value.instance.garbage)
599
- *theSlotAddress = theSlot->value.instance.garbage;
600
- else
601
- fxMarshallSlot(the, theSlot, theSlotAddress, theBuffer, alien);
602
- }
603
-
604
- txBoolean fxMarshallSlot(txMachine* the, txSlot* theSlot, txSlot** theSlotAddress, txMarshallBuffer* theBuffer, txBoolean alien)
605
- {
606
- txSlot* aResult;
607
- txSlot* aSlot;
608
- txSlot** aSlotAddress;
609
-
610
- aResult = (txSlot*)(theBuffer->current);
611
- theBuffer->current += sizeof(txSlot);
612
- if (!(theSlot->flag & XS_INTERNAL_FLAG))
613
- aResult->ID = fxMarshallKey(the, theSlot->ID, theBuffer, alien);
614
- else
615
- aResult->ID = theSlot->ID;
616
- aResult->flag = theSlot->flag;
617
- aResult->kind = theSlot->kind;
618
- aResult->value = theSlot->value;
619
- *theSlotAddress = aResult;
620
- switch (theSlot->kind) {
621
- case XS_UNDEFINED_KIND:
622
- case XS_NULL_KIND:
623
- case XS_BOOLEAN_KIND:
624
- case XS_INTEGER_KIND:
625
- case XS_NUMBER_KIND:
626
- case XS_DATE_KIND:
627
- case XS_STRING_X_KIND:
628
- case XS_BIGINT_X_KIND:
629
- case XS_DATA_VIEW_KIND:
630
- case XS_KEY_X_KIND:
631
- case XS_BUFFER_INFO_KIND:
632
- break;
633
-
634
- case XS_STRING_KIND:
635
- fxMarshallChunk(the, theSlot->value.string, (void **)&(aResult->value.string), theBuffer);
636
- break;
637
- case XS_BIGINT_KIND:
638
- fxMarshallChunk(the, theSlot->value.bigint.data, (void **)&(aResult->value.bigint.data), theBuffer);
639
- break;
640
- case XS_ARRAY_BUFFER_KIND:
641
- if (theSlot->value.arrayBuffer.address)
642
- fxMarshallChunk(the, theSlot->value.arrayBuffer.address, (void **) &(aResult->value.arrayBuffer.address), theBuffer);
643
- break;
644
- case XS_REGEXP_KIND:
645
- if (theSlot->value.regexp.code)
646
- fxMarshallChunk(the, theSlot->value.regexp.code, (void**)&(aResult->value.regexp.code), theBuffer);
647
- if (theSlot->value.regexp.data)
648
- fxMarshallChunk(the, theSlot->value.regexp.data, (void**)&(aResult->value.regexp.data), theBuffer);
649
- break;
650
- case XS_KEY_KIND:
651
- if (theSlot->value.key.string)
652
- fxMarshallChunk(the, theSlot->value.key.string, (void **)&(aResult->value.key.string), theBuffer);
653
- break;
654
-
655
- case XS_SYMBOL_KIND:
656
- aResult->value.symbol = fxMarshallKey(the, theSlot->value.symbol, theBuffer, alien);
657
- break;
658
-
659
- case XS_HOST_KIND:
660
- break;
661
- case XS_MAP_KIND:
662
- case XS_SET_KIND:
663
- aResult->value.table.address = C_NULL;
664
- break;
665
- case XS_TYPED_ARRAY_KIND:
666
- aResult->value.integer = (txInteger)(theSlot->value.typedArray.dispatch - &gxTypeDispatches[0]);
667
- break;
668
-
669
- case XS_REFERENCE_KIND:
670
- fxMarshallReference(the, theSlot->value.reference, &aResult->value.reference, theBuffer, alien);
671
- break;
672
- case XS_INSTANCE_KIND:
673
- aResult->value.instance.garbage = theBuffer->link;
674
- aResult->value.instance.prototype = C_NULL;
675
- aSlot = theSlot->value.instance.prototype;
676
- if (!alien && aSlot && (aSlot->flag & XS_DONT_MARSHALL_FLAG))
677
- aResult->value.instance.prototype = aSlot;
678
- theSlot->value.instance.garbage = aResult;
679
- theBuffer->link = theSlot;
680
- aSlotAddress = &(aResult->next);
681
- aSlot = theSlot->next;
682
- while (aSlot) {
683
- if (fxMarshallSlot(the, aSlot, aSlotAddress, theBuffer, alien))
684
- aSlotAddress = &((*aSlotAddress)->next);
685
- aSlot = aSlot->next;
686
- }
687
- *aSlotAddress = C_NULL;
688
- break;
689
- case XS_ARRAY_KIND: {
690
- txIndex length = theSlot->value.array.length;
691
- txIndex size = fxGetIndexSize(the, theSlot);
692
- txSlot* slot = theSlot->value.array.address;
693
- txSlot* limit = slot + size;
694
- txIndex former = 0, current;
695
- aSlotAddress = &(aResult->value.array.address);
696
- while (slot < limit) {
697
- current = *((txIndex*)slot);
698
- while (former < current) {
699
- fxMarshallSlot(the, &mxUndefined, aSlotAddress, theBuffer, alien);
700
- aSlotAddress = &((*aSlotAddress)->next);
701
- former++;
702
- }
703
- fxMarshallSlot(the, slot, aSlotAddress, theBuffer, alien);
704
- aSlotAddress = &((*aSlotAddress)->next);
705
- slot++;
706
- former++;
707
- }
708
- while (former < length) {
709
- fxMarshallSlot(the, &mxUndefined, aSlotAddress, theBuffer, alien);
710
- aSlotAddress = &((*aSlotAddress)->next);
711
- former++;
712
- }
713
- } break;
714
- case XS_ERROR_KIND:
715
- if (theSlot->value.error.info)
716
- fxMarshallReference(the, theSlot->value.error.info, &aResult->value.error.info, theBuffer, alien);
717
- break;
718
- case XS_PROXY_KIND:
719
- if (theSlot->value.proxy.handler)
720
- fxMarshallReference(the, theSlot->value.proxy.handler, &aResult->value.proxy.handler, theBuffer, alien);
721
- if (theSlot->value.proxy.target)
722
- fxMarshallReference(the, theSlot->value.proxy.target, &aResult->value.proxy.target, theBuffer, alien);
723
- break;
724
-
725
- case XS_LIST_KIND:
726
- aSlot = theSlot->value.list.first;
727
- aSlotAddress = &(aResult->value.list.first);
728
- while (aSlot) {
729
- fxMarshallSlot(the, aSlot, aSlotAddress, theBuffer, alien);
730
- aResult->value.list.last = *aSlotAddress;
731
- aSlot = aSlot->next;
732
- aSlotAddress = &((*aSlotAddress)->next);
733
- }
734
- *aSlotAddress = C_NULL;
735
- break;
736
- case XS_PRIVATE_KIND:
737
- aSlot = theSlot->value.private.check;
738
- if (!alien && (aSlot->flag & XS_DONT_MARSHALL_FLAG)) {
739
- aSlot = theSlot->value.private.first;
740
- aSlotAddress = &(aResult->value.private.first);
741
- while (aSlot) {
742
- fxMarshallSlot(the, aSlot, aSlotAddress, theBuffer, alien);
743
- aSlot = aSlot->next;
744
- aSlotAddress = &((*aSlotAddress)->next);
745
- }
746
- *aSlotAddress = C_NULL;
747
- }
748
- else {
749
- theBuffer->current -= sizeof(txSlot);
750
- return 0;
751
- }
752
- break;
753
- default:
754
- break;
755
- }
756
- return 1;
757
- }
758
-
759
- void fxMeasureChunk(txMachine* the, void* theData, txMarshallBuffer* theBuffer)
760
- {
761
- txChunk* aChunk = ((txChunk*)(((txByte*)theData) - sizeof(txChunk)));
762
- txSize aSize = aChunk->size & 0x7FFFFFFF;
763
- theBuffer->size += aSize;
764
- mxMarshallAlign(theBuffer->size, aSize);
765
- }
766
-
767
- void fxMeasureKey(txMachine* the, txID theID, txMarshallBuffer* theBuffer, txBoolean alien)
768
- {
769
- txSlot* aSlot;
770
- txSize aLength;
771
- if (theID != XS_NO_ID) {
772
- if (alien) {
773
- if (theBuffer->symbolMap[theID])
774
- return;
775
- if (theID >= the->keyOffset)
776
- aSlot = the->keyArray[theID - the->keyOffset];
777
- else
778
- aSlot = the->keyArrayHost[theID];
779
- }
780
- else if (theID >= the->keyOffset) {
781
- theID -= the->keyOffset;
782
- if (theBuffer->symbolMap[theID])
783
- return;
784
- aSlot = the->keyArray[theID];
785
- }
786
- else
787
- return;
788
- if (aSlot) {
789
- if (aSlot->flag & XS_DONT_ENUM_FLAG) {
790
- aLength = mxStringLength(aSlot->value.key.string) + 1;
791
- }
792
- else if (aSlot->kind != XS_UNDEFINED_KIND) {
793
- aLength = mxStringLength(aSlot->value.string) + 1;
794
- }
795
- else
796
- aLength = 1;
797
- }
798
- else
799
- aLength = 1;
800
- // if (aLength > XS_ID_MASK)
801
- // mxRangeError("marshall: key overflow");
802
- theBuffer->symbolMap[theID] = (txID)aLength;
803
- theBuffer->symbolSize += sizeof(txID);
804
- theBuffer->symbolSize += aLength;
805
- theBuffer->symbolCount++;
806
- }
807
- }
808
-
809
- void fxMeasureReference(txMachine* the, txSlot* theSlot, txMarshallBuffer* theBuffer, txBoolean alien)
810
- {
811
- if (theSlot->flag & XS_DONT_MARSHALL_FLAG) {
812
- if (alien)
813
- if (theSlot->value.host.variant.destructor != fxReleaseSharedChunk)
814
- fxMeasureThrow(the, theBuffer, "read only object");
815
- }
816
- else if ((theSlot->flag & XS_MARK_FLAG) == 0)
817
- fxMeasureSlot(the, theSlot, theBuffer, alien);
818
- }
819
-
820
- void fxMeasureSlot(txMachine* the, txSlot* theSlot, txMarshallBuffer* theBuffer, txBoolean alien)
821
- {
822
- txSlot* aSlot;
823
-
824
- if (!(theSlot->flag & XS_INTERNAL_FLAG))
825
- fxMeasureKey(the, theSlot->ID, theBuffer, alien);
826
- theBuffer->size += sizeof(txSlot);
827
- switch (theSlot->kind) {
828
- case XS_UNDEFINED_KIND:
829
- case XS_NULL_KIND:
830
- case XS_BOOLEAN_KIND:
831
- case XS_INTEGER_KIND:
832
- case XS_NUMBER_KIND:
833
- case XS_DATE_KIND:
834
- case XS_STRING_X_KIND:
835
- case XS_BIGINT_X_KIND:
836
- case XS_DATA_VIEW_KIND:
837
- case XS_KEY_X_KIND:
838
- case XS_BUFFER_INFO_KIND:
839
- break;
840
-
841
- case XS_STRING_KIND:
842
- fxMeasureChunk(the, theSlot->value.string, theBuffer);
843
- break;
844
- case XS_BIGINT_KIND:
845
- fxMeasureChunk(the, theSlot->value.bigint.data, theBuffer);
846
- break;
847
- case XS_ARRAY_BUFFER_KIND:
848
- if (theSlot->value.arrayBuffer.address)
849
- fxMeasureChunk(the, theSlot->value.arrayBuffer.address, theBuffer);
850
- break;
851
- case XS_REGEXP_KIND:
852
- if (theSlot->value.regexp.code)
853
- fxMeasureChunk(the, theSlot->value.regexp.code, theBuffer);
854
- if (theSlot->value.regexp.data)
855
- fxMeasureChunk(the, theSlot->value.regexp.data, theBuffer);
856
- break;
857
- case XS_KEY_KIND:
858
- if (theSlot->value.key.string)
859
- fxMeasureChunk(the, theSlot->value.string, theBuffer);
860
- break;
861
-
862
- case XS_SYMBOL_KIND:
863
- fxMeasureKey(the, theSlot->value.symbol, theBuffer, alien);
864
- break;
865
-
866
- case XS_HOST_KIND:
867
- if (theSlot->value.host.variant.destructor != fxReleaseSharedChunk)
868
- fxMeasureThrow(the, theBuffer, "host object");
869
- break;
870
- case XS_MAP_KIND:
871
- case XS_SET_KIND:
872
- break;
873
- case XS_TYPED_ARRAY_KIND:
874
- break;
875
-
876
- case XS_REFERENCE_KIND:
877
- fxMeasureReference(the, theSlot->value.reference, theBuffer, alien);
878
- break;
879
- case XS_INSTANCE_KIND:
880
- theSlot->flag |= XS_MARK_FLAG;
881
- theSlot->value.instance.garbage = C_NULL;
882
- aSlot = theSlot->next;
883
- while (aSlot) {
884
- if (aSlot->flag & XS_INTERNAL_FLAG)
885
- mxPushUndefined();
886
- else
887
- mxPushAt(aSlot->ID, 0);
888
- fxMeasureSlot(the, aSlot, theBuffer, alien);
889
- mxPop();
890
- aSlot = aSlot->next;
891
- }
892
- break;
893
- case XS_ARRAY_KIND: {
894
- txIndex length = theSlot->value.array.length;
895
- txIndex size = fxGetIndexSize(the, theSlot);
896
- txSlot* slot = theSlot->value.array.address;
897
- txSlot* limit = slot + size;
898
- txIndex former = 0, current;
899
- while (slot < limit) {
900
- current = *((txIndex*)slot);
901
- while (former < current) {
902
- theBuffer->size += sizeof(txSlot);
903
- former++;
904
- }
905
- mxPushAt(XS_NO_ID, *((txIndex*)slot));
906
- fxMeasureSlot(the, slot, theBuffer, alien);
907
- mxPop();
908
- slot++;
909
- former++;
910
- }
911
- while (former < length) {
912
- theBuffer->size += sizeof(txSlot);
913
- former++;
914
- }
915
- } break;
916
- case XS_ERROR_KIND:
917
- if (theSlot->value.error.info)
918
- fxMeasureReference(the, theSlot->value.error.info, theBuffer, alien);
919
- break;
920
- case XS_PROXY_KIND:
921
- if (theSlot->value.proxy.handler)
922
- fxMeasureReference(the, theSlot->value.proxy.handler, theBuffer, alien);
923
- if (theSlot->value.proxy.target)
924
- fxMeasureReference(the, theSlot->value.proxy.target, theBuffer, alien);
925
- break;
926
-
927
- case XS_LIST_KIND:
928
- aSlot = theSlot->value.list.first;
929
- while (aSlot) {
930
- fxMeasureSlot(the, aSlot, theBuffer, alien);
931
- aSlot = aSlot->next;
932
- }
933
- break;
934
- case XS_PRIVATE_KIND:
935
- aSlot = theSlot->value.private.check;
936
- if (!alien && (aSlot->flag & XS_DONT_MARSHALL_FLAG)) {
937
- aSlot = theSlot->value.private.first;
938
- while (aSlot) {
939
- fxMeasureSlot(the, aSlot, theBuffer, alien);
940
- aSlot = aSlot->next;
941
- }
942
- }
943
- else
944
- theBuffer->size -= sizeof(txSlot);
945
- break;
946
-
947
- case XS_ARGUMENTS_SLOPPY_KIND:
948
- case XS_ARGUMENTS_STRICT_KIND:
949
- fxMeasureThrow(the, theBuffer, "arguments");
950
- break;
951
- case XS_CALLBACK_KIND:
952
- case XS_CALLBACK_X_KIND:
953
- case XS_CODE_KIND:
954
- case XS_CODE_X_KIND:
955
- #ifdef mxHostFunctionPrimitive
956
- case XS_HOST_FUNCTION_KIND:
957
- #endif
958
- fxMeasureThrow(the, theBuffer, "function");
959
- break;
960
- case XS_FINALIZATION_CELL_KIND:
961
- case XS_FINALIZATION_REGISTRY_KIND:
962
- fxMeasureThrow(the, theBuffer, "finalization");
963
- break;
964
- case XS_MODULE_KIND:
965
- case XS_PROGRAM_KIND:
966
- fxMeasureThrow(the, theBuffer, "module");
967
- break;
968
- case XS_PROMISE_KIND:
969
- fxMeasureThrow(the, theBuffer, "promise");
970
- break;
971
- case XS_WEAK_MAP_KIND:
972
- fxMeasureThrow(the, theBuffer, "weak map");
973
- break;
974
- case XS_WEAK_REF_KIND:
975
- fxMeasureThrow(the, theBuffer, "weak ref");
976
- break;
977
- case XS_WEAK_SET_KIND:
978
- fxMeasureThrow(the, theBuffer, "weak set");
979
- break;
980
- case XS_ACCESSOR_KIND:
981
- fxMeasureThrow(the, theBuffer, "accessor");
982
- break;
983
- case XS_STACK_KIND:
984
- fxMeasureThrow(the, theBuffer, "generator");
985
- break;
986
- default:
987
- fxMeasureThrow(the, theBuffer, "no way");
988
- break;
989
- }
990
- }
991
-
992
- void fxMeasureThrow(txMachine* the, txMarshallBuffer* theBuffer, txString message)
993
- {
994
- char buffer[128] = "";
995
- txSlot* slot = theBuffer->stack;
996
- txInteger i = 0;
997
- txInteger c = sizeof(buffer);
998
- i += c_snprintf(buffer, c, "marshall ");
999
- while (slot > the->stack) {
1000
- slot--;
1001
- if (slot->kind == XS_AT_KIND) {
1002
- if (slot->value.at.id != XS_NO_ID) {
1003
- txSlot* key = fxGetKey(the, slot->value.at.id);
1004
- if (key) {
1005
- txKind kind = mxGetKeySlotKind(key);
1006
- if ((kind == XS_KEY_KIND) || (kind == XS_KEY_X_KIND)) {
1007
- if (i < c) i += c_snprintf(buffer + i, c - i, ".%s", key->value.string);
1008
- }
1009
- }
1010
- }
1011
- else {
1012
- if (i < c) i += c_snprintf(buffer + i, c - i, "[%d]", (int)slot->value.at.index);
1013
- }
1014
- }
1015
- }
1016
- if (i < c)
1017
- i += c_snprintf(buffer + i, c - i, ": %s", message);
1018
- mxTypeError(buffer);
1019
- }
1020
-