@agoric/xsnap 0.14.3-dev-b047af2.0 → 0.14.3-dev-2a16ddd.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 (125) hide show
  1. package/package.json +8 -15
  2. package/src/build.js +4 -61
  3. package/moddable/modules/data/base64/base64.js +0 -28
  4. package/moddable/modules/data/base64/manifest.json +0 -11
  5. package/moddable/modules/data/base64/modBase64.c +0 -188
  6. package/moddable/modules/data/binaryMessage/BinaryMessage.js +0 -106
  7. package/moddable/modules/data/crc/crc.c +0 -205
  8. package/moddable/modules/data/crc/crc.js +0 -36
  9. package/moddable/modules/data/crc/manifest.json +0 -8
  10. package/moddable/modules/data/hex/hex.js +0 -28
  11. package/moddable/modules/data/hex/manifest.json +0 -11
  12. package/moddable/modules/data/hex/modHex.c +0 -139
  13. package/moddable/modules/data/logical/logical.js +0 -32
  14. package/moddable/modules/data/logical/modLogical.c +0 -98
  15. package/moddable/modules/data/qrcode/manifest.json +0 -9
  16. package/moddable/modules/data/qrcode/qrcode.c +0 -93
  17. package/moddable/modules/data/qrcode/qrcode.js +0 -23
  18. package/moddable/modules/data/qrcode/qrcodegen.c +0 -1025
  19. package/moddable/modules/data/qrcode/qrcodegen.h +0 -267
  20. package/moddable/modules/data/text/decoder/manifest.json +0 -8
  21. package/moddable/modules/data/text/decoder/textdecoder.c +0 -480
  22. package/moddable/modules/data/text/decoder/textdecoder.js +0 -27
  23. package/moddable/modules/data/text/encoder/manifest.json +0 -8
  24. package/moddable/modules/data/text/encoder/textencoder.c +0 -232
  25. package/moddable/modules/data/text/encoder/textencoder.js +0 -24
  26. package/moddable/modules/data/tinyint/tinyint.c +0 -150
  27. package/moddable/modules/data/tinyint/tinyint.js +0 -53
  28. package/moddable/modules/data/url/manifest.json +0 -17
  29. package/moddable/modules/data/url/url.c +0 -1959
  30. package/moddable/modules/data/url/url.js +0 -210
  31. package/moddable/modules/data/wavreader/manifest.json +0 -8
  32. package/moddable/modules/data/wavreader/wavreader.js +0 -128
  33. package/moddable/modules/data/zlib/deflate.c +0 -161
  34. package/moddable/modules/data/zlib/deflate.js +0 -63
  35. package/moddable/modules/data/zlib/inflate.c +0 -145
  36. package/moddable/modules/data/zlib/inflate.js +0 -66
  37. package/moddable/modules/data/zlib/manifest_deflate.json +0 -9
  38. package/moddable/modules/data/zlib/manifest_inflate.json +0 -9
  39. package/moddable/modules/data/zlib/miniz.c +0 -4924
  40. package/moddable/xs/includes/xs.d.ts +0 -73
  41. package/moddable/xs/includes/xs.h +0 -1533
  42. package/moddable/xs/includes/xsmc.h +0 -206
  43. package/moddable/xs/makefiles/lin/makefile +0 -33
  44. package/moddable/xs/makefiles/lin/xsc.mk +0 -118
  45. package/moddable/xs/makefiles/lin/xsid.mk +0 -90
  46. package/moddable/xs/makefiles/lin/xsl.mk +0 -168
  47. package/moddable/xs/makefiles/lin/xst.mk +0 -201
  48. package/moddable/xs/makefiles/mac/makefile +0 -33
  49. package/moddable/xs/makefiles/mac/xsc.mk +0 -130
  50. package/moddable/xs/makefiles/mac/xsid.mk +0 -102
  51. package/moddable/xs/makefiles/mac/xsl.mk +0 -177
  52. package/moddable/xs/makefiles/mac/xst.mk +0 -203
  53. package/moddable/xs/makefiles/mac/xst_no_asan.txt +0 -52
  54. package/moddable/xs/makefiles/win/build.bat +0 -26
  55. package/moddable/xs/makefiles/win/xsc.mak +0 -142
  56. package/moddable/xs/makefiles/win/xsid.mak +0 -113
  57. package/moddable/xs/makefiles/win/xsl.mak +0 -186
  58. package/moddable/xs/makefiles/win/xst.mak +0 -195
  59. package/moddable/xs/platforms/lin_xs.h +0 -99
  60. package/moddable/xs/platforms/mac_xs.h +0 -97
  61. package/moddable/xs/platforms/wasm_xs.h +0 -79
  62. package/moddable/xs/platforms/win_xs.h +0 -104
  63. package/moddable/xs/platforms/xsHost.h +0 -63
  64. package/moddable/xs/platforms/xsPlatform.h +0 -618
  65. package/moddable/xs/sources/xsAPI.c +0 -2555
  66. package/moddable/xs/sources/xsAll.c +0 -294
  67. package/moddable/xs/sources/xsAll.h +0 -2741
  68. package/moddable/xs/sources/xsArguments.c +0 -222
  69. package/moddable/xs/sources/xsArray.c +0 -2657
  70. package/moddable/xs/sources/xsAtomics.c +0 -844
  71. package/moddable/xs/sources/xsBigInt.c +0 -1859
  72. package/moddable/xs/sources/xsBoolean.c +0 -109
  73. package/moddable/xs/sources/xsCode.c +0 -4493
  74. package/moddable/xs/sources/xsCommon.c +0 -1710
  75. package/moddable/xs/sources/xsCommon.h +0 -1142
  76. package/moddable/xs/sources/xsDataView.c +0 -2890
  77. package/moddable/xs/sources/xsDate.c +0 -1541
  78. package/moddable/xs/sources/xsDebug.c +0 -2710
  79. package/moddable/xs/sources/xsDefaults.c +0 -134
  80. package/moddable/xs/sources/xsError.c +0 -353
  81. package/moddable/xs/sources/xsFunction.c +0 -776
  82. package/moddable/xs/sources/xsGenerator.c +0 -865
  83. package/moddable/xs/sources/xsGlobal.c +0 -839
  84. package/moddable/xs/sources/xsJSON.c +0 -1091
  85. package/moddable/xs/sources/xsLexical.c +0 -1969
  86. package/moddable/xs/sources/xsLockdown.c +0 -933
  87. package/moddable/xs/sources/xsMapSet.c +0 -1649
  88. package/moddable/xs/sources/xsMarshall.c +0 -1020
  89. package/moddable/xs/sources/xsMath.c +0 -624
  90. package/moddable/xs/sources/xsMemory.c +0 -1941
  91. package/moddable/xs/sources/xsModule.c +0 -3101
  92. package/moddable/xs/sources/xsNumber.c +0 -560
  93. package/moddable/xs/sources/xsObject.c +0 -1102
  94. package/moddable/xs/sources/xsPlatforms.c +0 -480
  95. package/moddable/xs/sources/xsProfile.c +0 -577
  96. package/moddable/xs/sources/xsPromise.c +0 -1199
  97. package/moddable/xs/sources/xsProperty.c +0 -636
  98. package/moddable/xs/sources/xsProxy.c +0 -1014
  99. package/moddable/xs/sources/xsRegExp.c +0 -1168
  100. package/moddable/xs/sources/xsRun.c +0 -4889
  101. package/moddable/xs/sources/xsScope.c +0 -1293
  102. package/moddable/xs/sources/xsScript.c +0 -288
  103. package/moddable/xs/sources/xsScript.h +0 -1186
  104. package/moddable/xs/sources/xsSnapshot.c +0 -2161
  105. package/moddable/xs/sources/xsSnapshot.h +0 -51
  106. package/moddable/xs/sources/xsSourceMap.c +0 -218
  107. package/moddable/xs/sources/xsString.c +0 -3332
  108. package/moddable/xs/sources/xsSymbol.c +0 -503
  109. package/moddable/xs/sources/xsSyntaxical.c +0 -4193
  110. package/moddable/xs/sources/xsTree.c +0 -1893
  111. package/moddable/xs/sources/xsType.c +0 -1488
  112. package/moddable/xs/sources/xsdtoa.c +0 -6672
  113. package/moddable/xs/sources/xsmc.c +0 -340
  114. package/moddable/xs/sources/xsre.c +0 -7578
  115. package/xsnap-native/xsnap/makefiles/lin/makefile +0 -10
  116. package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +0 -153
  117. package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +0 -144
  118. package/xsnap-native/xsnap/makefiles/mac/makefile +0 -10
  119. package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +0 -162
  120. package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +0 -153
  121. package/xsnap-native/xsnap/sources/xsnap-worker.c +0 -996
  122. package/xsnap-native/xsnap/sources/xsnap.c +0 -716
  123. package/xsnap-native/xsnap/sources/xsnap.h +0 -142
  124. package/xsnap-native/xsnap/sources/xsnapPlatform.c +0 -1496
  125. package/xsnap-native/xsnap/sources/xsnapPlatform.h +0 -105
@@ -1,210 +0,0 @@
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
- // https://url.spec.whatwg.org/#url-class
22
-
23
- function parseURL(url) @ "fx_parseURL"
24
- function serializeURL(url) @ "fx_serializeURL"
25
- function parseQuery(query) @ "fx_parseQuery"
26
- function serializeQuery(pairs) @ "fx_serializeQuery"
27
-
28
- const SCHEME = 1;
29
- const USERNAME = 2;
30
- const PASSWORD = 3;
31
- const HOST = 4;
32
- const HOSTNAME = 5;
33
- const PORT = 6;
34
- const PATH = 7;
35
- const QUERY = 8;
36
- const FRAGMENT = 9;
37
- const ORIGIN = 10;
38
-
39
- class URL {
40
- #parts;
41
- #searchParams;
42
- constructor(href, base) {
43
- if (base !== undefined)
44
- this.#parts = parseURL(href, parseURL(base));
45
- else
46
- this.#parts = parseURL(href);
47
- this.#searchParams = new URLSearchParams(this.#parts.query, this.#parts);
48
- }
49
- get hash() {
50
- return serializeURL(this.#parts, FRAGMENT);
51
- }
52
- set hash(it) {
53
- parseURL(it, this.#parts, FRAGMENT);
54
- }
55
- get host() {
56
- return serializeURL(this.#parts, HOST);
57
- }
58
- set host(it) {
59
- parseURL(it, this.#parts, HOST);
60
- }
61
- get hostname() {
62
- return serializeURL(this.#parts, HOSTNAME);
63
- }
64
- set hostname(it) {
65
- parseURL(it, this.#parts, HOSTNAME);
66
- }
67
- get href() {
68
- return serializeURL(this.#parts);
69
- }
70
- set href(it) {
71
- this.#parts = parseURL(it);
72
- this.#searchParams.updatePairs();
73
- }
74
- get origin() {
75
- return serializeURL(this.#parts, ORIGIN);
76
- }
77
- get password() {
78
- return serializeURL(this.#parts, PASSWORD);
79
- }
80
- set password(it) {
81
- parseURL(it, this.#parts, PASSWORD);
82
- }
83
- get pathname() {
84
- return serializeURL(this.#parts, PATH);
85
- }
86
- set pathname(it) {
87
- parseURL(it, this.#parts, PATH);
88
- }
89
- get port() {
90
- return serializeURL(this.#parts, PORT);
91
- }
92
- set port(it) {
93
- parseURL(it, this.#parts, PORT);
94
- }
95
- get protocol() {
96
- return serializeURL(this.#parts, SCHEME);
97
- }
98
- set protocol(it) {
99
- parseURL(it, this.#parts, SCHEME);
100
- }
101
- get search() {
102
- return serializeURL(this.#parts, QUERY);
103
- }
104
- set search(it) {
105
- parseURL(it, this.#parts, QUERY);
106
- this.#searchParams.updatePairs();
107
- }
108
- get searchParams() {
109
- return this.#searchParams;
110
- }
111
- get username() {
112
- return serializeURL(this.#parts, USERNAME);
113
- }
114
- set username(it) {
115
- parseURL(it, this.#parts, USERNAME);
116
- }
117
- toJSON() {
118
- return serializeURL(this.#parts);
119
- }
120
- toString() {
121
- return serializeURL(this.#parts);
122
- }
123
- }
124
-
125
- // https://url.spec.whatwg.org/#interface-urlsearchparams
126
-
127
- class URLSearchParams {
128
- #pairs = null;
129
- #parts = null;
130
- constructor(it = "", parts = null) {
131
- if (typeof(it) == "object") {
132
- this.#pairs = [];
133
- if (Array.isArray(it)) {
134
- for (let item of it) {
135
- if (item.length != 2)
136
- throw new TypeError("invalid parameter");
137
- this.append(item[0], item[1]);
138
- }
139
- }
140
- else {
141
- for (let name in it)
142
- this.append(name, it[name]);
143
- }
144
- }
145
- else {
146
- this.#pairs = parseQuery(it);
147
- this.#parts = parts;
148
- }
149
- }
150
- get length() {
151
- return this.#pairs.length;
152
- }
153
- append(name, value) {
154
- this.#pairs.push({ name, value });
155
- this.updateParts();
156
- }
157
- delete(name) {
158
- this.#pairs = this.#pairs.filter(pair => pair.name != name);
159
- this.updateParts();
160
- }
161
- get(name) {
162
- const pair = this.#pairs.find(pair => pair.name == name);
163
- return pair ? pair.value : null;
164
- }
165
- getAll(name) {
166
- return this.#pairs.filter(pair => pair.name == name).map(pair => pair.value);
167
- }
168
- has(name) {
169
- const pair = this.#pairs.find(pair => pair.name == name);
170
- return pair ? true : false;
171
- }
172
- set(name, value) {
173
- const pair = this.#pairs.find(pair => pair.name == name);
174
- if (pair)
175
- pair.value = value;
176
- else
177
- this.#pairs.push({ name, value });
178
- this.updateParts();
179
- }
180
- toString() {
181
- return serializeQuery(this.#pairs);
182
- }
183
- updatePairs() {
184
- if (this.#parts)
185
- this.#pairs = parseQuery(this.#parts.query);
186
- }
187
- updateParts() {
188
- if (this.#parts)
189
- this.#parts.query = serializeQuery(this.#pairs);
190
- }
191
- [Symbol.iterator]() {
192
- const pairs = this.#pairs
193
- let index = 0;
194
- const iteraror = {
195
- next() {
196
- if (index < pairs.length) {
197
- const pair = pairs[index];
198
- index++;
199
- return { value: [pair.name, pair.value], done: false };
200
- }
201
- return { value: undefined, done: true };
202
- }
203
- }
204
- return iteraror;
205
- }
206
- }
207
-
208
- export { URL, URLSearchParams }
209
- export default URL;
210
-
@@ -1,8 +0,0 @@
1
- {
2
- "modules": {
3
- "data/wavreader": "./wavreader"
4
- },
5
- "preload": [
6
- "data/wavreader"
7
- ]
8
- }
@@ -1,128 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-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
- class WavReader {
22
- constructor(buffer) {
23
- this.wav = new DataView(buffer);
24
- this.position = 0;
25
- this.waveSize = buffer.byteLength;
26
-
27
- if ("RIFF" !== this.readFourCC())
28
- throw new Error("expected RIFF");
29
- this.seekBy(4); // file size
30
- if ("WAVE" !== this.readFourCC())
31
- throw new Error("expected WAVE");
32
-
33
- if ("JUNK" === this.readFourCC())
34
- this.seekBy(this.readUint32())
35
- else
36
- this.seekBy(-4);
37
-
38
- if ("fmt " !== this.readFourCC())
39
- throw new Error("expected fmt");
40
- let next = this.readUint32();
41
- next += this.position;
42
-
43
- this.audioFormat = this.readUint16();
44
- this.numChannels = this.readUint16();
45
- this.sampleRate = this.readUint32();
46
- this.seekBy(4 + 2);
47
- this.bitsPerSample = this.readUint16();
48
-
49
- this.seekTo(next);
50
-
51
- while ("data" !== this.readFourCC())
52
- this.seekBy(this.readUint32());
53
-
54
- this.samples = Math.floor(this.readUint32() / ((this.numChannels * this.bitsPerSample) >> 3));
55
- }
56
-
57
- getSamples(buffer, count) { // always returns signed 16-bit sample values
58
- this.samples -= count;
59
- if (this.samples < 0)
60
- throw Error("out of samples");
61
-
62
- count *= this.numChannels;
63
- let i = 0;
64
- if (16 === this.bitsPerSample) {
65
- while (count--)
66
- buffer[i++] = this.readInt16();
67
- }
68
- else
69
- if (8 == this.bitsPerSample) {
70
- while (count--) {
71
- let value = this.readInt8();
72
- buffer[i++] = value << 8; // write Uint8 representation of value into low bits
73
- }
74
- }
75
- }
76
-
77
- readFourCC() {
78
- let result = String.fromCharCode(this.wav.getUint8(this.position), this.wav.getUint8(this.position + 1),
79
- this.wav.getUint8(this.position + 2), this.wav.getUint8(this.position + 3));
80
- this.position += 4;
81
- if (this.position > this.waveSize)
82
- throw new Error("eof");
83
- return result;
84
- }
85
- readUint32() {
86
- let result = this.wav.getUint32(this.position, true);
87
- this.position += 4;
88
- if (this.position > this.waveSize)
89
- throw new Error("eof");
90
- return result;
91
- }
92
- readUint16() {
93
- let result = this.wav.getUint16(this.position, true);
94
- this.position += 2;
95
- if (this.position > this.waveSize)
96
- throw new Error("eof");
97
- return result;
98
- }
99
- readInt16() {
100
- let result = this.wav.getInt16(this.position, true);
101
- this.position += 2;
102
- if (this.position > this.waveSize)
103
- throw new Error("eof");
104
- return result;
105
- }
106
- readUint8() {
107
- let result = this.wav.getUint8(this.position, true);
108
- this.position += 1;
109
- if (this.position > this.waveSize)
110
- throw new Error("eof");
111
- return result;
112
- }
113
- readInt8() {
114
- let result = this.wav.getInt8(this.position, true);
115
- this.position += 1;
116
- if (this.position > this.waveSize)
117
- throw new Error("eof");
118
- return result;
119
- }
120
- seekBy(count) {
121
- this.position += count;
122
- }
123
- seekTo(position) {
124
- this.position = position;
125
- }
126
- }
127
-
128
- export default WavReader;
@@ -1,161 +0,0 @@
1
- /*
2
- * Copyright (c) 2019-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
- #include "mc.xs.h" // for xsID_ values
24
-
25
- #define MINIZ_HEADER_FILE_ONLY
26
- #include "miniz.c"
27
-
28
- static void *zAlloc(void *opaque, size_t items, size_t size)
29
- {
30
- return c_malloc(items * size);
31
- }
32
-
33
- static void zFree(void *opaque, void *address)
34
- {
35
- if (address)
36
- c_free(address);
37
- }
38
-
39
- void xs_deflate_destructor(void *data)
40
- {
41
- if (data) {
42
- deflateEnd((z_stream *)data);
43
- c_free(data);
44
- }
45
- }
46
-
47
- void xs_deflate(xsMachine *the)
48
- {
49
- int windowBits = Z_DEFAULT_WINDOW_BITS, level = MZ_DEFAULT_COMPRESSION, strategy = Z_DEFAULT_STRATEGY;
50
- z_stream *zlib;
51
-
52
- xsmcVars(1);
53
- if (xsmcHas(xsArg(0), xsID_windowBits)) {
54
- xsmcGet(xsVar(0), xsArg(0), xsID_windowBits);
55
- windowBits = xsmcToInteger(xsVar(0));
56
- if ((15 != windowBits) && (-15 != windowBits))
57
- xsRangeError("invalid windowBits");
58
- }
59
-
60
- if (xsmcHas(xsArg(0), xsID_level)) {
61
- xsmcGet(xsVar(0), xsArg(0), xsID_level);
62
- level = xsmcToInteger(xsVar(0));
63
- if ((level < -1) || (level > 10))
64
- xsRangeError("invalid level");
65
- }
66
-
67
- if (xsmcHas(xsArg(0), xsID_strategy)) {
68
- xsmcGet(xsVar(0), xsArg(0), xsID_strategy);
69
- strategy = xsmcToInteger(xsVar(0));
70
- if ((strategy < 0) || (strategy > 4))
71
- xsRangeError("invalid level");
72
- }
73
-
74
- zlib = c_malloc(sizeof(z_stream));
75
- if (!zlib)
76
- xsUnknownError("no memory");
77
-
78
- zlib->zalloc = zAlloc;
79
- zlib->zfree = zFree;
80
-
81
- if (Z_OK != deflateInit2(zlib, level, MZ_DEFLATED, windowBits, 1, strategy)) {
82
- c_free(zlib);
83
- xsUnknownError("deflateInit2 failed");
84
- }
85
-
86
- xsmcSetHostData(xsThis, zlib);
87
- }
88
-
89
- void xs_deflate_close(xsMachine *the)
90
- {
91
- z_stream *zlib = xsmcGetHostData(xsThis);
92
- if (zlib && xsmcGetHostDataValidate(xsThis, xs_deflate_destructor)) {
93
- xs_deflate_destructor(zlib);
94
- xsmcSetHostData(xsThis, NULL);
95
- xsmcSetHostDestructor(xsThis, NULL);
96
- }
97
- }
98
-
99
- void xs_deflate_push(xsMachine *the)
100
- {
101
- z_stream *zlib = xsmcGetHostDataValidate(xsThis, xs_deflate_destructor);
102
- uint8_t output[1024];
103
- int inputOffset = 0;
104
- xsUnsignedValue inputRemaining;
105
- void *input;
106
- int inputEnd = (xsmcArgc > 1) ? xsmcTest(xsArg(1)) : 0;
107
- int status = Z_OK;
108
- uint8_t isString = xsStringType == xsmcTypeOf(xsArg(0));
109
-
110
- if (isString)
111
- inputRemaining = c_strlen(xsmcToString(xsArg(0)));
112
- else
113
- xsmcGetBufferReadable(xsArg(0), &input, &inputRemaining);
114
-
115
- while ((0 != inputRemaining) || (Z_OK == status)) {
116
- zlib->next_out = output;
117
- zlib->avail_out = sizeof(output);
118
- zlib->total_out = 0;
119
-
120
- if (isString)
121
- zlib->next_in = inputOffset + (uint8_t *)xsmcToString(xsArg(0));
122
- else {
123
- xsUnsignedValue ignore;
124
- xsmcGetBufferReadable(xsArg(0), &input, &ignore);
125
- zlib->next_in = inputOffset + (uint8_t *)input;
126
- }
127
- zlib->avail_in = inputRemaining;
128
- zlib->total_in = 0;
129
-
130
- status = deflate(zlib, (inputEnd ? Z_FINISH : Z_NO_FLUSH));
131
- if (Z_BUF_ERROR == status) {
132
- status = Z_OK;
133
- goto bail;
134
- }
135
- if ((Z_OK != status) && (Z_STREAM_END != status)) {
136
- xs_deflate_close(the);
137
-
138
- xsmcSetInteger(xsResult, status);
139
- xsCall1(xsThis, xsID_onEnd, xsResult);
140
- goto bail;
141
- }
142
-
143
- if (zlib->total_out) {
144
- xsmcSetArrayBuffer(xsResult, output, zlib->total_out);
145
- xsCall1(xsThis, xsID_onData, xsResult);
146
- }
147
-
148
- inputOffset += zlib->total_in;
149
- inputRemaining -= zlib->total_in;
150
- }
151
-
152
- if (inputEnd || (status == Z_STREAM_END)) {
153
- xs_deflate_close(the);
154
-
155
- xsmcSetInteger(xsResult, (Z_STREAM_END == status) ? Z_OK : status);
156
- xsCall1(xsThis, xsID_onEnd, xsResult);
157
- }
158
-
159
- bail:
160
- xsmcSetBoolean(xsResult, (Z_OK == status) || (Z_STREAM_END == status));
161
- }
@@ -1,63 +0,0 @@
1
- /*
2
- * Copyright (c) 2019-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
-
22
- class Deflate @ "xs_deflate_destructor" {
23
- err = 0;
24
- chunks = [];
25
-
26
- constructor(options = {}) {
27
- build.call(this, options);
28
- this.onData = onData;
29
- this.onEnd = onEnd;
30
- }
31
- close() @ "xs_deflate_close";
32
-
33
- push(buffer, end) @ "xs_deflate_push";
34
- }
35
-
36
- function build(options) @ "xs_deflate";
37
-
38
- function onData(chunk) {
39
- this.chunks.push(chunk);
40
- }
41
-
42
- function onEnd(err) {
43
- this.err = err;
44
- if (err) {
45
- delete this.chunks;
46
- return;
47
- }
48
-
49
- // join chunks
50
- let total = 0;
51
- for (let i = 0, chunks = this.chunks, length = chunks.length; i < length; i++)
52
- total += chunks[i].byteLength;
53
-
54
- this.result = new Uint8Array(total);
55
- let offset = 0;
56
- for (let i = 0, chunks = this.chunks, length = chunks.length; i < length; i++) {
57
- this.result.set(new Uint8Array(this.chunks[i]), offset);
58
- offset += chunks[i].byteLength;
59
- }
60
- delete this.chunks;
61
- }
62
-
63
- export default Deflate;
@@ -1,145 +0,0 @@
1
- /*
2
- * Copyright (c) 2019-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
-
22
- #include "xsmc.h"
23
- #include "xsHost.h"
24
- #include "mc.xs.h" // for xsID_ values
25
-
26
- #define MINIZ_HEADER_FILE_ONLY
27
- #include "miniz.c"
28
-
29
- static void *zAlloc(void *opaque, size_t items, size_t size)
30
- {
31
- return c_malloc(items * size);
32
- }
33
-
34
- static void zFree(void *opaque, void *address)
35
- {
36
- if (address)
37
- c_free(address);
38
- }
39
-
40
- void xs_inflate_destructor(void *data)
41
- {
42
- if (data) {
43
- inflateEnd((z_stream *)data);
44
- c_free(data);
45
- }
46
- }
47
-
48
- void xs_inflate(xsMachine *the)
49
- {
50
- int windowBits = 15;
51
- z_stream *zlib;
52
-
53
- xsmcVars(1);
54
- if (xsmcHas(xsArg(0), xsID_windowBits)) {
55
- xsmcGet(xsVar(0), xsArg(0), xsID_windowBits);
56
- windowBits = xsmcToInteger(xsVar(0));
57
- if ((15 != windowBits) && (-15 != windowBits))
58
- xsRangeError("invalid windowBits");
59
- }
60
-
61
- zlib = c_malloc(sizeof(z_stream));
62
- if (!zlib)
63
- xsUnknownError("no memory");
64
-
65
- zlib->zalloc = zAlloc;
66
- zlib->zfree = zFree;
67
-
68
- if (Z_OK != inflateInit2(zlib, windowBits)) {
69
- c_free(zlib);
70
- xsUnknownError("inflateInit2 failed");
71
- }
72
-
73
- xsmcSetHostData(xsThis, zlib);
74
- }
75
-
76
- void xs_inflate_close(xsMachine *the)
77
- {
78
- z_stream *zlib = xsmcGetHostData(xsThis);
79
- if (zlib && xsmcGetHostDataValidate(xsThis, xs_inflate_destructor)) {
80
- xs_inflate_destructor(zlib);
81
- xsmcSetHostData(xsThis, NULL);
82
- xsmcSetHostDestructor(xsThis, NULL);
83
- }
84
- }
85
-
86
- void xs_inflate_push(xsMachine *the)
87
- {
88
- z_stream *zlib = xsmcGetHostDataValidate(xsThis, xs_inflate_destructor);
89
- uint8_t output[1024];
90
- int inputOffset = 0;
91
- uint8_t *input;
92
- xsUnsignedValue inputRemaining, ignore;
93
- //@@int inputEnd = xsmcTest(xsArg(1));
94
- int inputEnd = 0;
95
- int status = Z_OK;
96
-
97
- xsmcGetBufferReadable(xsArg(0), (void **)&input, &inputRemaining);
98
- while (Z_OK == status) {
99
- zlib->next_out = output;
100
- zlib->avail_out = sizeof(output);
101
- zlib->total_out = 0;
102
-
103
- xsmcGetBufferReadable(xsArg(0), (void **)&input, &ignore);
104
- zlib->next_in = inputOffset + input;
105
- zlib->avail_in = inputRemaining;
106
- zlib->total_in = 0;
107
-
108
- status = inflate(zlib, (inputEnd ? Z_FINISH : MZ_NO_FLUSH));
109
- if ((Z_OK != status) && (Z_STREAM_END != status)) {
110
- if (Z_DATA_ERROR == status) {
111
- xs_inflate_close(the);
112
- xsUnknownError("bad zlib data");
113
- }
114
- }
115
-
116
- if (zlib->total_out) {
117
- xsmcSetArrayBuffer(xsResult, output, zlib->total_out);
118
- xsCall1(xsThis, xsID_onData, xsResult);
119
- }
120
-
121
- inputOffset += zlib->total_in;
122
- inputRemaining -= zlib->total_in;
123
-
124
- if (Z_STREAM_END == status)
125
- break;
126
-
127
- if (Z_BUF_ERROR == status) {
128
- if (!inputRemaining && !zlib->total_out)
129
- break;
130
- status = Z_OK;
131
- }
132
- }
133
-
134
- if (inputEnd || (status == Z_STREAM_END)) {
135
- if (Z_STREAM_END != status)
136
- inflateEnd(zlib);
137
-
138
- xs_inflate_close(the);
139
-
140
- xsmcSetInteger(xsResult, (Z_STREAM_END == status) ? Z_OK : status);
141
- xsCall1(xsThis, xsID_onEnd, xsResult);
142
- }
143
-
144
- xsmcSetInteger(xsResult, inputRemaining);
145
- }