@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
package/api.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * Also, update golden master test/test-xs-perf.js to reflect new meter
8
8
  * version.
9
9
  */
10
- export const METER_TYPE = 'xs-meter-25';
10
+ export const METER_TYPE = 'xs-meter-26';
11
11
 
12
12
  export const ExitCode = {
13
13
  E_UNKNOWN_ERROR: -1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/xsnap",
3
- "version": "0.14.3-dev-b047af2.0+b047af2",
3
+ "version": "0.14.3-dev-3eb4230.0+3eb4230",
4
4
  "description": "Snapshotting VM worker based on Moddable's XS Javascript engine",
5
5
  "author": "Agoric",
6
6
  "license": "Apache-2.0",
@@ -13,10 +13,10 @@
13
13
  "scripts": {
14
14
  "repl": "node src/xsrepl.js",
15
15
  "build:bin": "if test -d ./test; then node src/build.js; else yarn build:from-env; fi",
16
- "build:env": "if test -d ./test; then node src/build.js --show-env > build.env; fi",
16
+ "build:env": "test -d ./test && node src/build.js --show-env > build.env",
17
17
  "build:from-env": "{ cat build.env; echo node src/build.js; } | xargs env",
18
18
  "build": "yarn build:bin && yarn build:env",
19
- "postinstall": "node src/build.js",
19
+ "postinstall": "yarn build:from-env",
20
20
  "clean": "rm -rf xsnap-native/xsnap/build",
21
21
  "lint": "run-s --continue-on-error lint:*",
22
22
  "lint:js": "eslint 'src/**/*.js' 'test/**/*.js' api.js",
@@ -27,21 +27,21 @@
27
27
  "test:xs": "exit 0"
28
28
  },
29
29
  "dependencies": {
30
- "@agoric/assert": "0.6.1-dev-b047af2.0+b047af2",
31
- "@agoric/internal": "0.3.3-dev-b047af2.0+b047af2",
32
- "@agoric/xsnap-lockdown": "0.14.1-dev-b047af2.0+b047af2",
33
- "@endo/bundle-source": "^3.1.0",
34
- "@endo/eventual-send": "^1.1.2",
35
- "@endo/init": "^1.0.4",
36
- "@endo/netstring": "^1.0.4",
37
- "@endo/promise-kit": "^1.0.4",
38
- "@endo/stream": "^1.1.0",
39
- "@endo/stream-node": "^1.0.4",
30
+ "@agoric/assert": "0.6.1-dev-3eb4230.0+3eb4230",
31
+ "@agoric/internal": "0.3.3-dev-3eb4230.0+3eb4230",
32
+ "@agoric/xsnap-lockdown": "0.14.1-dev-3eb4230.0+3eb4230",
33
+ "@endo/bundle-source": "^3.2.1",
34
+ "@endo/eventual-send": "^1.2.0",
35
+ "@endo/init": "^1.1.0",
36
+ "@endo/netstring": "^1.0.5",
37
+ "@endo/promise-kit": "^1.1.0",
38
+ "@endo/stream": "^1.2.0",
39
+ "@endo/stream-node": "^1.1.0",
40
40
  "glob": "^7.1.6",
41
41
  "tmp": "^0.2.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@endo/base64": "^1.0.2",
44
+ "@endo/base64": "^1.0.3",
45
45
  "@types/glob": "^8.1.0",
46
46
  "ava": "^5.3.0",
47
47
  "c8": "^9.1.0"
@@ -50,14 +50,7 @@
50
50
  "LICENSE*",
51
51
  "api.js",
52
52
  "build.env",
53
- "moddable/modules/data",
54
- "moddable/xs/includes",
55
- "moddable/xs/makefiles",
56
- "moddable/xs/platforms/*.h",
57
- "moddable/xs/sources",
58
- "src",
59
- "xsnap-native/xsnap/makefiles",
60
- "xsnap-native/xsnap/sources"
53
+ "src"
61
54
  ],
62
55
  "publishConfig": {
63
56
  "access": "public"
@@ -75,5 +68,5 @@
75
68
  "typeCoverage": {
76
69
  "atLeast": 94.44
77
70
  },
78
- "gitHead": "b047af28aef5e4fd7e66e31de252f7233ccb5e29"
71
+ "gitHead": "3eb4230d9b76e6145385b96882120c3f9529cfb9"
79
72
  }
package/src/build.js CHANGED
@@ -149,9 +149,12 @@ const makeSubmodule = (path, repoUrl, { git }) => {
149
149
  * rmdirSync: typeof import('fs').rmdirSync,
150
150
  * readFile: typeof import('fs').promises.readFile,
151
151
  * },
152
+ * os: {
153
+ * type: typeof import('os').type,
154
+ * }
152
155
  * }} io
153
156
  */
154
- const updateSubmodules = async (args, { env, stdout, spawn, fs }) => {
157
+ async function main(args, { env, stdout, spawn, fs, os }) {
155
158
  const git = makeCLI('git', { spawn });
156
159
 
157
160
  // When changing/adding entries here, make sure to search the whole project
@@ -211,22 +214,7 @@ const updateSubmodules = async (args, { env, stdout, spawn, fs }) => {
211
214
  await submodule.init();
212
215
  }
213
216
  }
214
- };
215
217
 
216
- /**
217
- * @param {{
218
- * spawn: typeof import('child_process').spawn,
219
- * fs: {
220
- * existsSync: typeof import('fs').existsSync,
221
- * rmdirSync: typeof import('fs').rmdirSync,
222
- * readFile: typeof import('fs').promises.readFile,
223
- * },
224
- * os: {
225
- * type: typeof import('os').type,
226
- * }
227
- * }} io
228
- */
229
- const makeXsnap = async ({ spawn, fs, os }) => {
230
218
  const pjson = await fs.readFile(asset('../package.json'), 'utf-8');
231
219
  const pkg = JSON.parse(pjson);
232
220
 
@@ -251,51 +239,6 @@ const makeXsnap = async ({ spawn, fs, os }) => {
251
239
  },
252
240
  );
253
241
  }
254
- };
255
-
256
- /**
257
- * @param {string[]} args
258
- * @param {{
259
- * env: Record<string, string | undefined>,
260
- * stdout: typeof process.stdout,
261
- * spawn: typeof import('child_process').spawn,
262
- * fs: {
263
- * existsSync: typeof import('fs').existsSync,
264
- * rmdirSync: typeof import('fs').rmdirSync,
265
- * readFile: typeof import('fs').promises.readFile,
266
- * },
267
- * os: {
268
- * type: typeof import('os').type,
269
- * }
270
- * }} io
271
- */
272
- async function main(args, { env, stdout, spawn, fs, os }) {
273
- // I solemnly swear I will do no synchronous work followed by a variable
274
- // number turns of the event loop.
275
- await null;
276
-
277
- // If this is a working copy of xsnap in a checkout of agoric-sdk, we need to
278
- // either clone or update submodules.
279
- // Otherwise, we are running from an extracted npm tarball in a dependent
280
- // package's node_modules, in which case we should just `make` with the
281
- // `moddable` directory provided by npm.
282
- // This will avoid rebuilding native xsnap in the common case for end users.
283
- //
284
- // | moddable/ | moddable/.git | working copy |
285
- // | --------- | ------------- | ------------ |
286
- // | ABSENT | ABSENT | YES |
287
- // | ABSENT | EXISTS | * |
288
- // | EXISTS | ABSENT | NO |
289
- // | EXISTS | EXISTS | YES |
290
- //
291
- // We short-circuit after a single stat if moddable/.git exists because that
292
- // implies that moddable/ exists.
293
- const isWorkingCopy =
294
- fs.existsSync('moddable/.git') || !fs.existsSync('moddable');
295
- if (isWorkingCopy) {
296
- await updateSubmodules(args, { env, stdout, spawn, fs });
297
- }
298
- await makeXsnap({ spawn, fs, os });
299
242
  }
300
243
 
301
244
  const run = () =>
@@ -1,28 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-2017 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
- base64
23
- */
24
-
25
- export default class {
26
- static encode(buffer) @ "xs_base64_encode";
27
- static decode(string) @ "xs_base64_decode";
28
- }
@@ -1,11 +0,0 @@
1
- {
2
- "modules": {
3
- "*": [
4
- "./base64",
5
- "./modBase64"
6
- ]
7
- },
8
- "preload": [
9
- "base64"
10
- ]
11
- }
@@ -1,188 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-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
- * 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
- /*
39
- modeled on FskStrB64Decode and FskStrB64Encode from KPR.
40
- */
41
-
42
- #include "xsmc.h"
43
- #include "xsHost.h"
44
-
45
- void xs_base64_encode(xsMachine *the)
46
- {
47
- static const char b64[] ICACHE_XS6RO2_ATTR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
48
- xsType srcType;
49
- uint8_t *src, *dst;
50
- uint32_t srcSize, dstSize;
51
- uint8_t a, b, c;
52
-
53
- srcType = xsmcTypeOf(xsArg(0));
54
- if (xsStringType == srcType) {
55
- src = (uint8_t *)xsmcToString(xsArg(0));
56
- srcSize = c_strlen((char *)src);
57
- }
58
- else
59
- xsmcGetBufferReadable(xsArg(0), (void **)&src, &srcSize);
60
- dstSize = (((srcSize + 2) / 3) * 4) + 1;
61
-
62
- xsResult = xsStringBuffer(NULL, dstSize);
63
- if (xsStringType == srcType)
64
- src = (uint8_t *)xsmcToString(xsArg(0)); // refresh pointer
65
- else
66
- xsmcGetBufferReadable(xsArg(0), (void **)&src, &srcSize);
67
- dst = (uint8_t *)xsmcToString(xsResult);
68
-
69
- while (srcSize > 2) {
70
- a = c_read8(src++);
71
- b = c_read8(src++);
72
- c = c_read8(src++);
73
- *dst++ = c_read8(b64 + ((a & 0xfc) >> 2));
74
- *dst++ = c_read8(b64 + (((a & 0x3) << 4) | ((b & 0xf0) >> 4)));
75
- *dst++ = c_read8(b64 + (((b & 0xf) << 2) | ((c & 0xc0) >> 6)));
76
- *dst++ = c_read8(b64 + (c & 0x3f));
77
- srcSize -= 3;
78
- }
79
-
80
- if (srcSize == 2) {
81
- a = c_read8(src++);
82
- b = c_read8(src++);
83
- *dst++ = c_read8(b64 + ((a & 0xfc) >> 2));
84
- *dst++ = c_read8(b64 + (((a & 0x3) << 4) | ((b & 0xf0) >> 4)));
85
- *dst++ = c_read8(b64 + ((b & 0xf) << 2));
86
- *dst++ = '=';
87
- }
88
- else if (srcSize == 1) {
89
- a = c_read8(src++);
90
- *dst++ = c_read8(b64 + ((a & 0xfc) >> 2));
91
- *dst++ = c_read8(b64 + ((a & 0x3) << 4));
92
- *dst++ = '=';
93
- *dst++ = '=';
94
- }
95
-
96
- *dst++ = 0;
97
- }
98
-
99
- void xs_base64_decode(xsMachine *the)
100
- {
101
- uint8_t *src;
102
- uint32_t srcSize, dstSize, srcIndex, dstIndex;
103
- uint8_t aFlag = 0;
104
- uint8_t aByte;
105
- uint8_t aBuffer[4];
106
- uint8_t *dst, *dstStart;
107
-
108
- src = (uint8_t *)xsmcToString(xsArg(0));
109
- srcSize = c_strlen((char *)src);
110
-
111
- dstSize = (srcSize / 4) * 3;
112
- if (c_read8(src + srcSize - 1) == '=')
113
- dstSize--;
114
- if (c_read8(src + srcSize - 2) == '=')
115
- dstSize--;
116
- srcIndex = 0;
117
-
118
- xsmcSetArrayBufferResizable(xsResult, NULL, dstSize, dstSize);
119
- dst = dstStart = xsmcToArrayBuffer(xsResult);
120
-
121
- src = (uint8_t *)xsmcToString(xsArg(0)); // refresh pointer
122
-
123
- dstIndex = 3;
124
- while ((aByte = c_read8(src++))) {
125
- if (('A' <= aByte) && (aByte <= 'Z'))
126
- aByte = aByte - 'A';
127
- else if (('a' <= aByte) && (aByte <= 'z'))
128
- aByte = aByte - 'a' + 26;
129
- else if (('0' <= aByte) && (aByte <= '9'))
130
- aByte = aByte - '0' + 52;
131
- else if (aByte == '+')
132
- aByte = 62;
133
- else if (aByte == '/')
134
- aByte = 63;
135
- else if (aByte == '=') {
136
- if (srcIndex == 2) {
137
- if (c_read8(src) == '=') {
138
- aBuffer[srcIndex++] = 0;
139
- dstIndex = 1;
140
- aByte = 0;
141
- aFlag = 1;
142
- }
143
- else
144
- continue;
145
- }
146
- else if (srcIndex == 3) {
147
- dstIndex = 2;
148
- aByte = 0;
149
- aFlag = 1;
150
- }
151
- else
152
- continue;
153
- }
154
- else
155
- continue;
156
- aBuffer[srcIndex++] = aByte;
157
- if (srcIndex == 4) {
158
- *dst++ = (aBuffer[0] << 2) | ((aBuffer[1] & 0x30) >> 4);
159
- if (dstIndex > 1)
160
- *dst++ = ((aBuffer[1] & 0x0F) << 4) | ((aBuffer[2] & 0x3C) >> 2);
161
- if (dstIndex > 2)
162
- *dst++ = ((aBuffer[2] & 0x03) << 6) | (aBuffer[3] & 0x3F);
163
- srcIndex = 0;
164
- }
165
- if (aFlag)
166
- break;
167
- }
168
-
169
- xsmcSetArrayBufferLength(xsResult, dst - dstStart);
170
- }
171
-
172
- void modInstallBase64(xsMachine *the)
173
- {
174
- #define kNamespace (0)
175
- #define kScratch (1)
176
-
177
- xsBeginHost(the);
178
- xsmcVars(2);
179
-
180
- xsVar(kNamespace) = xsNewObject();
181
- xsmcSet(xsGlobal, xsID("Base64"), xsVar(kNamespace));
182
- xsVar(kScratch) = xsNewHostFunction(xs_base64_encode, 1);
183
- xsmcSet(xsVar(kNamespace), xsID("encode"), xsVar(kScratch));
184
- xsVar(kScratch) = xsNewHostFunction(xs_base64_decode, 1);
185
- xsmcSet(xsVar(kNamespace), xsID("decode"), xsVar(kScratch));
186
-
187
- xsEndHost(the);
188
- }
@@ -1,106 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-2019 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Tools.
5
- *
6
- * The Moddable SDK Tools is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU 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 Tools 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 General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with the Moddable SDK Tools. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
- const BinaryMessage = {
22
- Float32: {
23
- bytesLength:4,
24
- getter:DataView.prototype.getFloat32,
25
- setter:DataView.prototype.setFloat32,
26
- },
27
- Float64: {
28
- bytesLength:8,
29
- getter:DataView.prototype.getFloat64,
30
- setter:DataView.prototype.setFloat64,
31
- },
32
- Int8: {
33
- bytesLength:1,
34
- getter:DataView.prototype.getInt8,
35
- setter:DataView.prototype.setInt8,
36
- },
37
- Int16: {
38
- bytesLength:2,
39
- getter:DataView.prototype.getInt16,
40
- setter:DataView.prototype.setInt16,
41
- },
42
- Int32: {
43
- bytesLength:4,
44
- getter:DataView.prototype.getInt32,
45
- setter:DataView.prototype.setInt32,
46
- },
47
- Uint8: {
48
- bytesLength:1,
49
- getter:DataView.prototype.getUint8,
50
- setter:DataView.prototype.setUint8,
51
- },
52
- Uint16: {
53
- bytesLength:2,
54
- getter:DataView.prototype.getUint16,
55
- setter:DataView.prototype.setUint16,
56
- },
57
- Uint32: {
58
- bytesLength:4,
59
- getter:DataView.prototype.getUint32,
60
- setter:DataView.prototype.setUint32,
61
- },
62
- generate(format) {
63
- let message = {};
64
- format.forEach(item => {
65
- let value = 0;
66
- let range = item.range;
67
- if (range)
68
- value = range[value];
69
- message[item.name] = value;
70
- });
71
- return message;
72
- },
73
- parse(format, buffer, endian) {
74
- let view = new DataView(buffer);
75
- let message = {};
76
- let bytesLength = 0;
77
- format.forEach(item => {
78
- let value = item.type.getter.call(view, bytesLength, endian);
79
- let range = item.range;
80
- if (range)
81
- value = range[value];
82
- message[item.name] = value;
83
- bytesLength += item.type.bytesLength;
84
- });
85
- return message;
86
- },
87
- serialize(format, message, endian) {
88
- let bytesLength = format.reduce((sum, item) => sum + item.type.bytesLength, 0);
89
- let buffer = new ArrayBuffer(bytesLength);
90
- let view = new DataView(buffer);
91
- bytesLength = 0;
92
- format.forEach(item => {
93
- let value = message[item.name];
94
- let range = item.range;
95
- if (range)
96
- value = range.findIndex(string => string == value);
97
- item.type.setter.call(view, bytesLength, value, endian);
98
- bytesLength += item.type.bytesLength;
99
- });
100
- return buffer;
101
- },
102
- }
103
-
104
- Object.freeze(BinaryMessage, true);
105
-
106
- export default BinaryMessage;