@agoric/xsnap 0.14.3-u14.0 → 0.14.3-u16.1

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 (137) hide show
  1. package/README.md +3 -3
  2. package/api.js +4 -2
  3. package/build.env +1 -1
  4. package/moddable/modules/data/base64/base64.js +28 -0
  5. package/moddable/modules/data/base64/manifest.json +11 -0
  6. package/moddable/modules/data/base64/modBase64.c +188 -0
  7. package/moddable/modules/data/binaryMessage/BinaryMessage.js +106 -0
  8. package/moddable/modules/data/crc/crc.c +205 -0
  9. package/moddable/modules/data/crc/crc.js +36 -0
  10. package/moddable/modules/data/crc/manifest.json +8 -0
  11. package/moddable/modules/data/hex/hex.js +28 -0
  12. package/moddable/modules/data/hex/manifest.json +11 -0
  13. package/moddable/modules/data/hex/modHex.c +139 -0
  14. package/moddable/modules/data/logical/logical.js +32 -0
  15. package/moddable/modules/data/logical/modLogical.c +98 -0
  16. package/moddable/modules/data/qrcode/manifest.json +9 -0
  17. package/moddable/modules/data/qrcode/qrcode.c +93 -0
  18. package/moddable/modules/data/qrcode/qrcode.js +23 -0
  19. package/moddable/modules/data/qrcode/qrcodegen.c +1025 -0
  20. package/moddable/modules/data/qrcode/qrcodegen.h +267 -0
  21. package/moddable/modules/data/text/decoder/manifest.json +8 -0
  22. package/moddable/modules/data/text/decoder/textdecoder.c +480 -0
  23. package/moddable/modules/data/text/decoder/textdecoder.js +27 -0
  24. package/moddable/modules/data/text/encoder/manifest.json +8 -0
  25. package/moddable/modules/data/text/encoder/textencoder.c +232 -0
  26. package/moddable/modules/data/text/encoder/textencoder.js +24 -0
  27. package/moddable/modules/data/tinyint/tinyint.c +150 -0
  28. package/moddable/modules/data/tinyint/tinyint.js +53 -0
  29. package/moddable/modules/data/url/manifest.json +17 -0
  30. package/moddable/modules/data/url/url.c +1959 -0
  31. package/moddable/modules/data/url/url.js +210 -0
  32. package/moddable/modules/data/wavreader/manifest.json +8 -0
  33. package/moddable/modules/data/wavreader/wavreader.js +128 -0
  34. package/moddable/modules/data/zlib/deflate.c +161 -0
  35. package/moddable/modules/data/zlib/deflate.js +63 -0
  36. package/moddable/modules/data/zlib/inflate.c +145 -0
  37. package/moddable/modules/data/zlib/inflate.js +66 -0
  38. package/moddable/modules/data/zlib/manifest_deflate.json +9 -0
  39. package/moddable/modules/data/zlib/manifest_inflate.json +9 -0
  40. package/moddable/modules/data/zlib/miniz.c +4924 -0
  41. package/moddable/xs/includes/xs.d.ts +73 -0
  42. package/moddable/xs/includes/xs.h +1533 -0
  43. package/moddable/xs/includes/xsmc.h +206 -0
  44. package/moddable/xs/makefiles/lin/makefile +33 -0
  45. package/moddable/xs/makefiles/lin/xsc.mk +118 -0
  46. package/moddable/xs/makefiles/lin/xsid.mk +90 -0
  47. package/moddable/xs/makefiles/lin/xsl.mk +168 -0
  48. package/moddable/xs/makefiles/lin/xst.mk +201 -0
  49. package/moddable/xs/makefiles/mac/makefile +33 -0
  50. package/moddable/xs/makefiles/mac/xsc.mk +130 -0
  51. package/moddable/xs/makefiles/mac/xsid.mk +102 -0
  52. package/moddable/xs/makefiles/mac/xsl.mk +177 -0
  53. package/moddable/xs/makefiles/mac/xst.mk +203 -0
  54. package/moddable/xs/makefiles/mac/xst_no_asan.txt +52 -0
  55. package/moddable/xs/makefiles/win/build.bat +26 -0
  56. package/moddable/xs/makefiles/win/xsc.mak +142 -0
  57. package/moddable/xs/makefiles/win/xsid.mak +113 -0
  58. package/moddable/xs/makefiles/win/xsl.mak +186 -0
  59. package/moddable/xs/makefiles/win/xst.mak +195 -0
  60. package/moddable/xs/platforms/lin_xs.h +99 -0
  61. package/moddable/xs/platforms/mac_xs.h +97 -0
  62. package/moddable/xs/platforms/wasm_xs.h +79 -0
  63. package/moddable/xs/platforms/win_xs.h +104 -0
  64. package/moddable/xs/platforms/xsHost.h +63 -0
  65. package/moddable/xs/platforms/xsPlatform.h +618 -0
  66. package/moddable/xs/sources/xsAPI.c +2555 -0
  67. package/moddable/xs/sources/xsAll.c +294 -0
  68. package/moddable/xs/sources/xsAll.h +2741 -0
  69. package/moddable/xs/sources/xsArguments.c +222 -0
  70. package/moddable/xs/sources/xsArray.c +2657 -0
  71. package/moddable/xs/sources/xsAtomics.c +844 -0
  72. package/moddable/xs/sources/xsBigInt.c +1859 -0
  73. package/moddable/xs/sources/xsBoolean.c +109 -0
  74. package/moddable/xs/sources/xsCode.c +4493 -0
  75. package/moddable/xs/sources/xsCommon.c +1710 -0
  76. package/moddable/xs/sources/xsCommon.h +1142 -0
  77. package/moddable/xs/sources/xsDataView.c +2890 -0
  78. package/moddable/xs/sources/xsDate.c +1541 -0
  79. package/moddable/xs/sources/xsDebug.c +2710 -0
  80. package/moddable/xs/sources/xsDefaults.c +134 -0
  81. package/moddable/xs/sources/xsError.c +353 -0
  82. package/moddable/xs/sources/xsFunction.c +776 -0
  83. package/moddable/xs/sources/xsGenerator.c +865 -0
  84. package/moddable/xs/sources/xsGlobal.c +839 -0
  85. package/moddable/xs/sources/xsJSON.c +1091 -0
  86. package/moddable/xs/sources/xsLexical.c +1969 -0
  87. package/moddable/xs/sources/xsLockdown.c +933 -0
  88. package/moddable/xs/sources/xsMapSet.c +1649 -0
  89. package/moddable/xs/sources/xsMarshall.c +1020 -0
  90. package/moddable/xs/sources/xsMath.c +624 -0
  91. package/moddable/xs/sources/xsMemory.c +1941 -0
  92. package/moddable/xs/sources/xsModule.c +3101 -0
  93. package/moddable/xs/sources/xsNumber.c +560 -0
  94. package/moddable/xs/sources/xsObject.c +1102 -0
  95. package/moddable/xs/sources/xsPlatforms.c +480 -0
  96. package/moddable/xs/sources/xsProfile.c +577 -0
  97. package/moddable/xs/sources/xsPromise.c +1199 -0
  98. package/moddable/xs/sources/xsProperty.c +636 -0
  99. package/moddable/xs/sources/xsProxy.c +1014 -0
  100. package/moddable/xs/sources/xsRegExp.c +1168 -0
  101. package/moddable/xs/sources/xsRun.c +4889 -0
  102. package/moddable/xs/sources/xsScope.c +1293 -0
  103. package/moddable/xs/sources/xsScript.c +288 -0
  104. package/moddable/xs/sources/xsScript.h +1186 -0
  105. package/moddable/xs/sources/xsSnapshot.c +2161 -0
  106. package/moddable/xs/sources/xsSnapshot.h +51 -0
  107. package/moddable/xs/sources/xsSourceMap.c +218 -0
  108. package/moddable/xs/sources/xsString.c +3332 -0
  109. package/moddable/xs/sources/xsSymbol.c +503 -0
  110. package/moddable/xs/sources/xsSyntaxical.c +4193 -0
  111. package/moddable/xs/sources/xsTree.c +1893 -0
  112. package/moddable/xs/sources/xsType.c +1488 -0
  113. package/moddable/xs/sources/xsdtoa.c +6672 -0
  114. package/moddable/xs/sources/xsmc.c +340 -0
  115. package/moddable/xs/sources/xsre.c +7578 -0
  116. package/package.json +37 -20
  117. package/scripts/get_xsnap_version.sh +14 -0
  118. package/scripts/test-package.sh +21 -0
  119. package/src/avaAssertXS.js +6 -2
  120. package/src/avaHandler.cjs +2 -5
  121. package/src/avaXS.js +7 -8
  122. package/src/build.js +161 -28
  123. package/src/replay.js +0 -3
  124. package/src/xsnap.js +105 -91
  125. package/src/xsrepl.js +2 -3
  126. package/xsnap-native/xsnap/makefiles/lin/makefile +10 -0
  127. package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +156 -0
  128. package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +144 -0
  129. package/xsnap-native/xsnap/makefiles/mac/makefile +10 -0
  130. package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +165 -0
  131. package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +153 -0
  132. package/xsnap-native/xsnap/sources/xsnap-worker.c +1008 -0
  133. package/xsnap-native/xsnap/sources/xsnap.c +717 -0
  134. package/xsnap-native/xsnap/sources/xsnap.h +142 -0
  135. package/xsnap-native/xsnap/sources/xsnapPlatform.c +1501 -0
  136. package/xsnap-native/xsnap/sources/xsnapPlatform.h +105 -0
  137. package/CHANGELOG.md +0 -654
@@ -0,0 +1,232 @@
1
+ /*
2
+ * Copyright (c) 2021-2022 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
+ */
20
+
21
+ #include "xsmc.h"
22
+ #include "xsHost.h"
23
+ #ifdef kPocoRotation
24
+ // Moddable SDK
25
+ #include "mc.xs.h" // for xsID_ values
26
+
27
+ #define VALIDATE 1
28
+ #else
29
+ // xst, xsnap, etc
30
+ #include <stdbool.h>
31
+
32
+ #define xsID_read (xsID("read"))
33
+ #define xsID_String (xsID("String"))
34
+ #define xsID_Uint8Array (xsID("Uint8Array"))
35
+ #define xsID_written (xsID("written"))
36
+ #endif
37
+
38
+ #if !VALIDATE
39
+ void xs_textencoder(xsMachine *the)
40
+ {
41
+ xsmcGet(xsResult, xsTarget, xsID("prototype"));
42
+ xsResult = xsNewHostInstance(xsResult);
43
+ }
44
+ #endif
45
+
46
+ /*
47
+ null character maps to 0xC0, 0x80
48
+ surrogate pair pattern: ED Ax xx ED Bx xx
49
+ */
50
+
51
+ void xs_textencoder_encode(xsMachine *the)
52
+ {
53
+ uint8_t *src, *dst;
54
+ int length = 0;
55
+ uint8_t remap = false;
56
+
57
+ xsArg(0) = xsCall1(xsGlobal, xsID_String, xsArg(0));
58
+ src = (uint8_t *)xsmcToString(xsArg(0));
59
+
60
+ while (true) {
61
+ uint8_t c = c_read8(src++);
62
+ if (!c) break;
63
+
64
+ if ((0xED == c) &&
65
+ (0xA0 == (0xF0 & c_read8(src))) &&
66
+ (0xED == c_read8(src + 2)) &&
67
+ (0xB0 == (0xF0 & c_read8(src + 3)))) {
68
+ src += 5;
69
+ length += 4;
70
+ remap = true;
71
+ continue;
72
+ }
73
+
74
+ length += 1;
75
+ if ((0xC0 == c) && (0x80 == c_read8(src))) {
76
+ src += 1;
77
+ remap = true;
78
+ }
79
+ }
80
+
81
+ xsmcSetArrayBuffer(xsResult, NULL, length);
82
+ src = (uint8_t *)xsmcToString(xsArg(0));
83
+ dst = xsmcToArrayBuffer(xsResult);
84
+ if (remap) {
85
+ while (true) {
86
+ uint8_t c = c_read8(src++);
87
+ if (!c) break;
88
+
89
+ if ((0xED == c) &&
90
+ (0xA0 == (0xF0 & c_read8(src))) &&
91
+ (0xED == c_read8(src + 2)) &&
92
+ (0xB0 == (0xF0 & c_read8(src + 3)))) {
93
+ xsIntegerValue high, low;
94
+
95
+ fxUTF8Decode((xsStringValue)(src - 1), &high);
96
+ fxUTF8Decode((xsStringValue)(src + 2), &low);
97
+ fxUTF8Encode((xsStringValue)dst, 0x10000 + ((high & 0x3FF) << 10) + (low & 0x3FF));
98
+ src += 5;
99
+ dst += 4;
100
+ continue;
101
+ }
102
+
103
+ if ((0xC0 == c) && (0x80 == c_read8(src))) {
104
+ *dst++ = 0;
105
+ src += 1;
106
+ }
107
+ else
108
+ *dst++ = c;
109
+ }
110
+ }
111
+ else
112
+ c_memcpy(dst, src, length);
113
+
114
+ xsResult = xsNew1(xsGlobal, xsID_Uint8Array, xsResult);
115
+ }
116
+
117
+ void xs_textencoder_encodeInto(xsMachine *the)
118
+ {
119
+ uint8_t *src, *dst;
120
+ xsUnsignedValue dstTotal, dstRemaining;
121
+ int read = 0;
122
+
123
+ if (!xsmcIsInstanceOf(xsArg(1), xsTypedArrayPrototype)) //@@ limit to Uint8Array
124
+ xsUnknownError("Uint8Array only");
125
+
126
+ xsArg(0) = xsCall1(xsGlobal, xsID_String, xsArg(0));
127
+ xsmcGetBufferWritable(xsArg(1), (void **)&dst, &dstTotal);
128
+ dstRemaining = dstTotal;
129
+ src = (uint8_t *)xsmcToString(xsArg(0));
130
+
131
+ while (dstRemaining) {
132
+ uint8_t first = c_read8(src++);
133
+ if (!first) break;
134
+
135
+ if (first < 0x80) {
136
+ *dst++ = first;
137
+ dstRemaining -= 1;
138
+ }
139
+ else if (0xC0 == (first & 0xE0)) {
140
+ if ((0xC0 == first) && (0x80 == c_read8(src))) {
141
+ *dst++ = 0;
142
+ dstRemaining -= 1;
143
+ src += 1;
144
+ read += 1;
145
+ continue;
146
+ }
147
+
148
+ if (dstRemaining < 2)
149
+ break;
150
+
151
+ *dst++ = first;
152
+ *dst++ = c_read8(src++);
153
+
154
+ dstRemaining -= 2;
155
+ }
156
+ else if (0xE0 == (first & 0xF0)) {
157
+ if ((0xED == first) &&
158
+ (0xA0 == (0xF0 & c_read8(src))) &&
159
+ (0xED == c_read8(src + 2)) &&
160
+ (0xB0 == (0xF0 & c_read8(src + 3)))) {
161
+ xsIntegerValue high, low;
162
+
163
+ if (dstRemaining < 4)
164
+ break;
165
+
166
+ fxUTF8Decode((xsStringValue)(src - 1), &high);
167
+ fxUTF8Decode((xsStringValue)(src + 2), &low);
168
+ fxUTF8Encode((xsStringValue)dst, 0x10000 + ((high & 0x3FF) << 10) + (low & 0x3FF));
169
+ src += 5;
170
+ dst += 4;
171
+ dstRemaining -= 4;
172
+ read += 2;
173
+ continue;
174
+ }
175
+
176
+ if (dstRemaining < 3)
177
+ break;
178
+
179
+ *dst++ = first;
180
+ *dst++ = c_read8(src++);
181
+ *dst++ = c_read8(src++);
182
+
183
+ dstRemaining -= 3;
184
+ }
185
+ else if (0xF0 == (first & 0xF0)) {
186
+ if (dstRemaining < 4)
187
+ break;
188
+
189
+ *dst++ = first;
190
+ *dst++ = c_read8(src++);
191
+ *dst++ = c_read8(src++);
192
+ *dst++ = c_read8(src++);
193
+
194
+ dstRemaining -= 4;
195
+ }
196
+ else
197
+ fxAbort(the, xsFatalCheckExit);
198
+
199
+ read += 1;
200
+ }
201
+
202
+ xsmcSetNewObject(xsResult);
203
+
204
+ xsmcVars(1);
205
+ xsmcSetInteger(xsVar(0), read);
206
+ xsmcSet(xsResult, xsID_read, xsVar(0));
207
+
208
+ xsmcSetInteger(xsVar(0), dstTotal - dstRemaining);
209
+ xsmcSet(xsResult, xsID_written, xsVar(0));
210
+ }
211
+
212
+ #if !VALIDATE
213
+ void modInstallTextEncoder(xsMachine *the)
214
+ {
215
+ #define kPrototype (0)
216
+ #define kConstructor (1)
217
+ #define kScratch (2)
218
+
219
+ xsBeginHost(the);
220
+ xsmcVars(3);
221
+
222
+ xsmcSetNewObject(xsVar(kPrototype));
223
+ xsVar(kConstructor) = xsNewHostConstructor(xs_textencoder, 1, xsVar(kPrototype));
224
+ xsmcSet(xsGlobal, xsID("TextEncoder"), xsVar(kConstructor));
225
+ xsVar(kScratch) = xsNewHostFunction(xs_textencoder_encode, 1);
226
+ xsmcSet(xsVar(kPrototype), xsID("encode"), xsVar(kScratch));
227
+ xsVar(kScratch) = xsNewHostFunction(xs_textencoder_encodeInto, 2);
228
+ xsmcSet(xsVar(kPrototype), xsID("encodeInto"), xsVar(kScratch));
229
+
230
+ xsEndHost(the);
231
+ }
232
+ #endif
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright (c) 2021 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
+ */
20
+
21
+ export default class {
22
+ encode(value) @ "xs_textencoder_encode";
23
+ encodeInto(value, buffer) @ "xs_textencoder_encodeInto";
24
+ }
@@ -0,0 +1,150 @@
1
+ /*
2
+ * Copyright (c) 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
+ */
20
+
21
+ #include "xsmc.h"
22
+ #include "mc.xs.h" // for xsID_ values
23
+
24
+ void BitsView_prototype_getIntBits(xsMachine *the)
25
+ {
26
+ xsUnknownError("unimplemented");
27
+ }
28
+
29
+ void BitsView_prototype_getUintBits(xsMachine *the)
30
+ {
31
+ int bitsOffset = xsmcToInteger(xsArg(0));
32
+ int bitsSize = xsmcToInteger(xsArg(1));
33
+ uint32_t bitsValue = 0;
34
+ int byteLength;
35
+ uint8_t *bytes;
36
+ uint8_t littleEndian = true;
37
+ uint8_t shift = 0;
38
+ static const uint8_t masks[] = {0, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF};
39
+
40
+ if ((bitsSize < 1) || (bitsSize > 32))
41
+ xsRangeError("invalid number of bits");
42
+
43
+ if (xsmcArgc > 3) {
44
+ if (xsmcTest(xsArg(3)))
45
+ littleEndian = false;
46
+ }
47
+
48
+ xsmcVars(1);
49
+
50
+ xsmcGet(xsVar(0), xsThis, xsID_byteLength);
51
+ byteLength = xsmcToInteger(xsVar(0));
52
+
53
+ if ((bitsOffset < 0) || ((bitsOffset + bitsSize) > (byteLength << 3)))
54
+ xsRangeError("invalid offset");
55
+
56
+ xsmcGet(xsVar(0), xsThis, xsID_buffer);
57
+ bytes = xsmcToArrayBuffer(xsVar(0));
58
+
59
+ xsmcGet(xsVar(0), xsThis, xsID_byteOffset);
60
+ bytes += xsmcToInteger(xsVar(0));
61
+ bytes += bitsOffset >> 3;
62
+ while (bitsSize) {
63
+ uint8_t mask;
64
+ uint8_t part = (uint8_t)bitsSize;
65
+ uint8_t available = 8 - (bitsOffset & 7);
66
+ if (part > available)
67
+ part = available;
68
+
69
+ mask = masks[part] << (available - part);
70
+ if (littleEndian) {
71
+ bitsValue |= ((*bytes & mask) >> (available - part)) << shift;
72
+ shift += part;
73
+ }
74
+ else {
75
+ bitsValue <<= part;
76
+ bitsValue |= (*bytes & mask) >> (available - part);
77
+ }
78
+ bytes++;
79
+
80
+ bitsSize -= part;
81
+ bitsOffset += part;
82
+ }
83
+
84
+ if (bitsValue & 0x80000000)
85
+ xsmcSetNumber(xsResult, bitsValue);
86
+ else
87
+ xsmcSetInteger(xsResult, bitsValue);
88
+ }
89
+
90
+ void BitsView_prototype_setIntBits(xsMachine *the)
91
+ {
92
+ xsUnknownError("unimplemented");
93
+ }
94
+
95
+ void BitsView_prototype_setUintBits(xsMachine *the)
96
+ {
97
+ int bitsOffset = xsmcToInteger(xsArg(0));
98
+ int bitsSize = xsmcToInteger(xsArg(1));
99
+ uint32_t bitsValue = (uint32_t)xsmcToInteger(xsArg(2));
100
+ int byteLength;
101
+ uint8_t *bytes;
102
+ uint8_t littleEndian = true;
103
+ static const uint8_t masks[] = {0, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF};
104
+
105
+ if ((bitsSize < 1) || (bitsSize > 32))
106
+ xsRangeError("invalid number of bits");
107
+
108
+ if (xsmcArgc > 3) {
109
+ if (xsmcTest(xsArg(3))) {
110
+ littleEndian = false;
111
+ bitsValue <<= (32 - bitsSize);
112
+ }
113
+ }
114
+
115
+ xsmcVars(1);
116
+
117
+ xsmcGet(xsVar(0), xsThis, xsID_byteLength);
118
+ byteLength = xsmcToInteger(xsVar(0));
119
+
120
+ if ((bitsOffset < 0) || ((bitsOffset + bitsSize) > (byteLength << 3)))
121
+ xsRangeError("invalid offset");
122
+
123
+ xsmcGet(xsVar(0), xsThis, xsID_buffer);
124
+ bytes = xsmcToArrayBuffer(xsVar(0));
125
+
126
+ xsmcGet(xsVar(0), xsThis, xsID_byteOffset);
127
+ bytes += xsmcToInteger(xsVar(0));
128
+ bytes += bitsOffset >> 3;
129
+ while (bitsSize) {
130
+ uint8_t mask;
131
+ uint8_t part = (uint8_t)bitsSize;
132
+ uint8_t available = 8 - (bitsOffset & 7);
133
+ if (part > available)
134
+ part = available;
135
+
136
+ mask = masks[part] << (available - part);
137
+ if (littleEndian) {
138
+ *bytes = (*bytes & ~mask) | ((bitsValue << (available - part)) & mask);
139
+ bitsValue >>= part;
140
+ }
141
+ else {
142
+ *bytes = (*bytes & ~mask) | ((bitsValue >> (24 + (bitsOffset & 7))) & mask);
143
+ bitsValue <<= part;
144
+ }
145
+ bytes++;
146
+
147
+ bitsSize -= part;
148
+ bitsOffset += part;
149
+ }
150
+ }
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright (c) 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
+ */
20
+
21
+ export class BitsView extends DataView {
22
+ // getIntBits(bitsOffset, bitsSize, endian) @ "BitsView_prototype_getIntBits"
23
+ getUintBits(bitsOffset, bitsSize, endian) @ "BitsView_prototype_getUintBits"
24
+ // setIntBits(bitsOffset, bitsSize, value, endian) @ "BitsView_prototype_setIntBits"
25
+ setUintBits(bitsOffset, bitsSize, value, endian) @ "BitsView_prototype_setUintBits"
26
+ }
27
+
28
+ export class UintBitsArray {
29
+ constructor(buffer, bitsSize) {
30
+ if ("number" === typeof buffer) {
31
+ this.length = buffer;
32
+ buffer = new ArrayBuffer(((bitsSize * buffer) + 7) >> 3);
33
+ }
34
+ else if (buffer instanceof ArrayBuffer)
35
+ this.length = (buffer.byteLength / bitsSize) | 0;
36
+ else
37
+ throw new Error("invalid buffer");
38
+ this.bitsSize = bitsSize;
39
+ return new Proxy(new BitsView(buffer), this);
40
+ }
41
+ get(target, key) {
42
+ if ("length" === key)
43
+ return this.length;
44
+ if ("buffer" === key)
45
+ return target.buffer;
46
+ const bitsSize = this.bitsSize;
47
+ return target.getUintBits(key * bitsSize, bitsSize);
48
+ }
49
+ set(target, key, value) {
50
+ const bitsSize = this.bitsSize;
51
+ return target.setUintBits(key * bitsSize, bitsSize, value);
52
+ }
53
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "modules": {
3
+ "url": "./url"
4
+ },
5
+ "preload": [
6
+ "url"
7
+ ],
8
+ "platforms": {
9
+ "esp": {
10
+ "recipes": {
11
+ "strings-in-flash-force-l32": [
12
+ "url*"
13
+ ]
14
+ }
15
+ }
16
+ }
17
+ }