@agoric/xsnap 0.14.3-u14.0 → 0.14.3-u16.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.
- package/README.md +3 -3
- package/api.js +4 -2
- package/build.env +1 -1
- package/moddable/modules/data/base64/base64.js +28 -0
- package/moddable/modules/data/base64/manifest.json +11 -0
- package/moddable/modules/data/base64/modBase64.c +188 -0
- package/moddable/modules/data/binaryMessage/BinaryMessage.js +106 -0
- package/moddable/modules/data/crc/crc.c +205 -0
- package/moddable/modules/data/crc/crc.js +36 -0
- package/moddable/modules/data/crc/manifest.json +8 -0
- package/moddable/modules/data/hex/hex.js +28 -0
- package/moddable/modules/data/hex/manifest.json +11 -0
- package/moddable/modules/data/hex/modHex.c +139 -0
- package/moddable/modules/data/logical/logical.js +32 -0
- package/moddable/modules/data/logical/modLogical.c +98 -0
- package/moddable/modules/data/qrcode/manifest.json +9 -0
- package/moddable/modules/data/qrcode/qrcode.c +93 -0
- package/moddable/modules/data/qrcode/qrcode.js +23 -0
- package/moddable/modules/data/qrcode/qrcodegen.c +1025 -0
- package/moddable/modules/data/qrcode/qrcodegen.h +267 -0
- package/moddable/modules/data/text/decoder/manifest.json +8 -0
- package/moddable/modules/data/text/decoder/textdecoder.c +480 -0
- package/moddable/modules/data/text/decoder/textdecoder.js +27 -0
- package/moddable/modules/data/text/encoder/manifest.json +8 -0
- package/moddable/modules/data/text/encoder/textencoder.c +232 -0
- package/moddable/modules/data/text/encoder/textencoder.js +24 -0
- package/moddable/modules/data/tinyint/tinyint.c +150 -0
- package/moddable/modules/data/tinyint/tinyint.js +53 -0
- package/moddable/modules/data/url/manifest.json +17 -0
- package/moddable/modules/data/url/url.c +1959 -0
- package/moddable/modules/data/url/url.js +210 -0
- package/moddable/modules/data/wavreader/manifest.json +8 -0
- package/moddable/modules/data/wavreader/wavreader.js +128 -0
- package/moddable/modules/data/zlib/deflate.c +161 -0
- package/moddable/modules/data/zlib/deflate.js +63 -0
- package/moddable/modules/data/zlib/inflate.c +145 -0
- package/moddable/modules/data/zlib/inflate.js +66 -0
- package/moddable/modules/data/zlib/manifest_deflate.json +9 -0
- package/moddable/modules/data/zlib/manifest_inflate.json +9 -0
- package/moddable/modules/data/zlib/miniz.c +4924 -0
- package/moddable/xs/includes/xs.d.ts +73 -0
- package/moddable/xs/includes/xs.h +1533 -0
- package/moddable/xs/includes/xsmc.h +206 -0
- package/moddable/xs/makefiles/lin/makefile +33 -0
- package/moddable/xs/makefiles/lin/xsc.mk +118 -0
- package/moddable/xs/makefiles/lin/xsid.mk +90 -0
- package/moddable/xs/makefiles/lin/xsl.mk +168 -0
- package/moddable/xs/makefiles/lin/xst.mk +201 -0
- package/moddable/xs/makefiles/mac/makefile +33 -0
- package/moddable/xs/makefiles/mac/xsc.mk +130 -0
- package/moddable/xs/makefiles/mac/xsid.mk +102 -0
- package/moddable/xs/makefiles/mac/xsl.mk +177 -0
- package/moddable/xs/makefiles/mac/xst.mk +203 -0
- package/moddable/xs/makefiles/mac/xst_no_asan.txt +52 -0
- package/moddable/xs/makefiles/win/build.bat +26 -0
- package/moddable/xs/makefiles/win/xsc.mak +142 -0
- package/moddable/xs/makefiles/win/xsid.mak +113 -0
- package/moddable/xs/makefiles/win/xsl.mak +186 -0
- package/moddable/xs/makefiles/win/xst.mak +195 -0
- package/moddable/xs/platforms/lin_xs.h +99 -0
- package/moddable/xs/platforms/mac_xs.h +97 -0
- package/moddable/xs/platforms/wasm_xs.h +79 -0
- package/moddable/xs/platforms/win_xs.h +104 -0
- package/moddable/xs/platforms/xsHost.h +63 -0
- package/moddable/xs/platforms/xsPlatform.h +618 -0
- package/moddable/xs/sources/xsAPI.c +2555 -0
- package/moddable/xs/sources/xsAll.c +294 -0
- package/moddable/xs/sources/xsAll.h +2741 -0
- package/moddable/xs/sources/xsArguments.c +222 -0
- package/moddable/xs/sources/xsArray.c +2657 -0
- package/moddable/xs/sources/xsAtomics.c +844 -0
- package/moddable/xs/sources/xsBigInt.c +1859 -0
- package/moddable/xs/sources/xsBoolean.c +109 -0
- package/moddable/xs/sources/xsCode.c +4493 -0
- package/moddable/xs/sources/xsCommon.c +1710 -0
- package/moddable/xs/sources/xsCommon.h +1142 -0
- package/moddable/xs/sources/xsDataView.c +2890 -0
- package/moddable/xs/sources/xsDate.c +1541 -0
- package/moddable/xs/sources/xsDebug.c +2710 -0
- package/moddable/xs/sources/xsDefaults.c +134 -0
- package/moddable/xs/sources/xsError.c +353 -0
- package/moddable/xs/sources/xsFunction.c +776 -0
- package/moddable/xs/sources/xsGenerator.c +865 -0
- package/moddable/xs/sources/xsGlobal.c +839 -0
- package/moddable/xs/sources/xsJSON.c +1091 -0
- package/moddable/xs/sources/xsLexical.c +1969 -0
- package/moddable/xs/sources/xsLockdown.c +933 -0
- package/moddable/xs/sources/xsMapSet.c +1649 -0
- package/moddable/xs/sources/xsMarshall.c +1020 -0
- package/moddable/xs/sources/xsMath.c +624 -0
- package/moddable/xs/sources/xsMemory.c +1941 -0
- package/moddable/xs/sources/xsModule.c +3101 -0
- package/moddable/xs/sources/xsNumber.c +560 -0
- package/moddable/xs/sources/xsObject.c +1102 -0
- package/moddable/xs/sources/xsPlatforms.c +480 -0
- package/moddable/xs/sources/xsProfile.c +577 -0
- package/moddable/xs/sources/xsPromise.c +1199 -0
- package/moddable/xs/sources/xsProperty.c +636 -0
- package/moddable/xs/sources/xsProxy.c +1014 -0
- package/moddable/xs/sources/xsRegExp.c +1168 -0
- package/moddable/xs/sources/xsRun.c +4889 -0
- package/moddable/xs/sources/xsScope.c +1293 -0
- package/moddable/xs/sources/xsScript.c +288 -0
- package/moddable/xs/sources/xsScript.h +1186 -0
- package/moddable/xs/sources/xsSnapshot.c +2161 -0
- package/moddable/xs/sources/xsSnapshot.h +51 -0
- package/moddable/xs/sources/xsSourceMap.c +218 -0
- package/moddable/xs/sources/xsString.c +3332 -0
- package/moddable/xs/sources/xsSymbol.c +503 -0
- package/moddable/xs/sources/xsSyntaxical.c +4193 -0
- package/moddable/xs/sources/xsTree.c +1893 -0
- package/moddable/xs/sources/xsType.c +1488 -0
- package/moddable/xs/sources/xsdtoa.c +6672 -0
- package/moddable/xs/sources/xsmc.c +340 -0
- package/moddable/xs/sources/xsre.c +7578 -0
- package/package.json +37 -20
- package/scripts/get_xsnap_version.sh +14 -0
- package/scripts/test-package.sh +21 -0
- package/src/avaAssertXS.js +6 -2
- package/src/avaHandler.cjs +2 -5
- package/src/avaXS.js +7 -8
- package/src/build.js +161 -28
- package/src/replay.js +0 -3
- package/src/xsnap.js +105 -91
- package/src/xsrepl.js +2 -3
- package/xsnap-native/xsnap/makefiles/lin/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +156 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +144 -0
- package/xsnap-native/xsnap/makefiles/mac/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +165 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +153 -0
- package/xsnap-native/xsnap/sources/xsnap-worker.c +1008 -0
- package/xsnap-native/xsnap/sources/xsnap.c +717 -0
- package/xsnap-native/xsnap/sources/xsnap.h +142 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.c +1501 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.h +105 -0
- package/CHANGELOG.md +0 -654
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Some time later, possibly on a different computer…
|
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
24
|
const decoder = new TextDecoder();
|
|
25
|
-
const worker = await xsnap({
|
|
25
|
+
const worker = await xsnap({
|
|
26
26
|
snapshotStream: fs.createFileStream('bootstrap.xss'),
|
|
27
27
|
});
|
|
28
28
|
const response = await worker.issueCommand('1');
|
|
@@ -57,7 +57,7 @@ The REPL supports special commands `load` and `save` for snapshots, and `quit`
|
|
|
57
57
|
to quit.
|
|
58
58
|
Load and save don't take arguments; just type the file name on the next prompt.
|
|
59
59
|
|
|
60
|
-
```
|
|
60
|
+
```console
|
|
61
61
|
$ xsrepl
|
|
62
62
|
xs> globalThis.x = 42;
|
|
63
63
|
xs> x
|
|
@@ -67,7 +67,7 @@ file> temp.xss
|
|
|
67
67
|
xs> quit
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
```
|
|
70
|
+
```console
|
|
71
71
|
$ xsrepl
|
|
72
72
|
xs> load
|
|
73
73
|
file> temp.xss
|
package/api.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* The version identifier for our meter type.
|
|
5
5
|
*
|
|
6
6
|
* TODO Bump this whenever there's a change to metering semantics.
|
|
7
|
-
* Also, update golden master test/
|
|
7
|
+
* Also, update golden master test/xs-perf.test.js to reflect new meter
|
|
8
8
|
* version.
|
|
9
9
|
*/
|
|
10
|
-
export const METER_TYPE = 'xs-meter-
|
|
10
|
+
export const METER_TYPE = 'xs-meter-28';
|
|
11
11
|
|
|
12
12
|
export const ExitCode = {
|
|
13
13
|
E_UNKNOWN_ERROR: -1,
|
|
@@ -43,6 +43,7 @@ export class ErrorSignal extends Error {
|
|
|
43
43
|
this.code = signal;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
harden(ErrorSignal);
|
|
46
47
|
|
|
47
48
|
export class ErrorCode extends Error {
|
|
48
49
|
/**
|
|
@@ -55,3 +56,4 @@ export class ErrorCode extends Error {
|
|
|
55
56
|
this.code = code;
|
|
56
57
|
}
|
|
57
58
|
}
|
|
59
|
+
harden(ErrorCode);
|
package/build.env
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
MODDABLE_URL=https://github.com/agoric-labs/moddable.git
|
|
2
2
|
MODDABLE_COMMIT_HASH=f6c5951fc055e4ca592b9166b9ae3cbb9cca6bf0
|
|
3
3
|
XSNAP_NATIVE_URL=https://github.com/agoric-labs/xsnap-pub
|
|
4
|
-
XSNAP_NATIVE_COMMIT_HASH=
|
|
4
|
+
XSNAP_NATIVE_COMMIT_HASH=eef9b67da5517ed18ff9e0073b842db20924eae3
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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;
|
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
|
|
24
|
+
// https://graphics.stanford.edu/~seander/bithacks.html
|
|
25
|
+
uint8_t reflect8(uint8_t b) {
|
|
26
|
+
return ((b * 0x0802LU & 0x22110LU) | (b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static void make_crc8_table(uint8_t polynomial, uint8_t *crc8_table)
|
|
30
|
+
{
|
|
31
|
+
int i, j, cur;
|
|
32
|
+
|
|
33
|
+
for (i=0; i<256; i++) {
|
|
34
|
+
for (cur=i, j=0; j<8; j++) {
|
|
35
|
+
if (cur & 0x80)
|
|
36
|
+
cur = ((cur << 1) ^ polynomial) % 256;
|
|
37
|
+
else
|
|
38
|
+
cur = (cur << 1) % 256;
|
|
39
|
+
}
|
|
40
|
+
crc8_table[i] = cur;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static uint8_t checksum8(uint8_t *bytes, uint32_t length, uint8_t *crc8_table, uint8_t crc, uint8_t refIn) {
|
|
45
|
+
uint32_t i;
|
|
46
|
+
|
|
47
|
+
for (i=0; i<length; i++) {
|
|
48
|
+
uint8_t b = bytes[i];
|
|
49
|
+
if (refIn)
|
|
50
|
+
b = reflect8(b);
|
|
51
|
+
crc = crc8_table[(crc ^ b) % 256];
|
|
52
|
+
}
|
|
53
|
+
return crc;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
typedef struct {
|
|
57
|
+
uint8_t reset;
|
|
58
|
+
uint8_t initial;
|
|
59
|
+
uint8_t reflectInput;
|
|
60
|
+
uint8_t reflectOutput;
|
|
61
|
+
uint8_t xorOutput;
|
|
62
|
+
uint8_t table[256];
|
|
63
|
+
} CRC8Record, *CRC8;
|
|
64
|
+
|
|
65
|
+
void xs_crc8_destructor(void *data)
|
|
66
|
+
{
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
void xs_crc8(xsMachine *the)
|
|
70
|
+
{
|
|
71
|
+
int argc = xsmcArgc;
|
|
72
|
+
int polynomial = xsmcToInteger(xsArg(0));
|
|
73
|
+
int initial = (argc > 1) ? xsmcToInteger(xsArg(1)) : 0;
|
|
74
|
+
int reflectInput = (argc > 2) ? xsmcToInteger(xsArg(2)) : 0;
|
|
75
|
+
int reflectOutput = (argc > 3) ? xsmcToInteger(xsArg(3)) : 0;
|
|
76
|
+
int xorOutput = (argc > 4) ? xsmcToInteger(xsArg(4)) : 0;
|
|
77
|
+
CRC8 crc8 = xsmcSetHostChunk(xsThis, NULL, sizeof(CRC8Record));
|
|
78
|
+
|
|
79
|
+
crc8->reset = initial;
|
|
80
|
+
crc8->initial = initial;
|
|
81
|
+
crc8->reflectInput = reflectInput;
|
|
82
|
+
crc8->reflectOutput = reflectOutput;
|
|
83
|
+
crc8->xorOutput = xorOutput;
|
|
84
|
+
|
|
85
|
+
make_crc8_table(polynomial, crc8->table);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
void xs_crc8_close(xsMachine *the)
|
|
89
|
+
{
|
|
90
|
+
xsmcSetHostData(xsThis, NULL);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
void xs_crc8_reset(xsMachine *the)
|
|
94
|
+
{
|
|
95
|
+
CRC8 crc8 = xsmcGetHostChunk(xsThis);
|
|
96
|
+
|
|
97
|
+
crc8->initial = crc8->reset;
|
|
98
|
+
xsResult = xsThis;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
void xs_crc8_checksum(xsMachine *the)
|
|
102
|
+
{
|
|
103
|
+
CRC8 crc8 = xsmcGetHostChunk(xsThis);
|
|
104
|
+
uint8_t *data;
|
|
105
|
+
uint32_t length;
|
|
106
|
+
|
|
107
|
+
xsmcGetBufferReadable(xsArg(0), (void **)&data, &length);
|
|
108
|
+
crc8->initial = checksum8(data, length, crc8->table, crc8->initial, crc8->reflectInput);
|
|
109
|
+
|
|
110
|
+
uint8_t crc = crc8->initial;
|
|
111
|
+
if (crc8->reflectOutput)
|
|
112
|
+
crc = reflect8(crc);
|
|
113
|
+
|
|
114
|
+
xsmcSetInteger(xsResult, crc ^ crc8->xorOutput);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
static void make_crc16_table(uint16_t polynomial, uint16_t *crc16_table) {
|
|
119
|
+
int i, j;
|
|
120
|
+
uint16_t crc;
|
|
121
|
+
|
|
122
|
+
for (i=0; i<256; i++) {
|
|
123
|
+
for (crc=i<<8, j=0; j<8; j++) {
|
|
124
|
+
if (crc & 0x8000) {
|
|
125
|
+
crc <<= 1;
|
|
126
|
+
crc ^= polynomial;
|
|
127
|
+
}
|
|
128
|
+
else
|
|
129
|
+
crc <<= 1;
|
|
130
|
+
}
|
|
131
|
+
crc16_table[i] = crc;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static uint16_t checksum16(uint8_t *bytes, uint32_t length, uint16_t *crc16_table, uint16_t crc, uint8_t refIn) {
|
|
136
|
+
uint32_t i;
|
|
137
|
+
|
|
138
|
+
for (i=0; i<length; i++) {
|
|
139
|
+
uint8_t b = bytes[i];
|
|
140
|
+
if (refIn)
|
|
141
|
+
b = reflect8(b);
|
|
142
|
+
crc = crc ^ (b << 8);
|
|
143
|
+
crc = ((crc << 8) ^ crc16_table[crc >> 8]);
|
|
144
|
+
}
|
|
145
|
+
return crc;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
typedef struct {
|
|
149
|
+
uint16_t reset;
|
|
150
|
+
uint16_t initial;
|
|
151
|
+
uint16_t reflectInput;
|
|
152
|
+
uint16_t reflectOutput;
|
|
153
|
+
uint16_t xorOutput;
|
|
154
|
+
uint16_t table[256];
|
|
155
|
+
} CRC16Record, *CRC16;
|
|
156
|
+
|
|
157
|
+
void xs_crc16_destructor(void *data)
|
|
158
|
+
{
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
void xs_crc16(xsMachine *the)
|
|
162
|
+
{
|
|
163
|
+
int argc = xsmcArgc;
|
|
164
|
+
int polynomial = xsmcToInteger(xsArg(0));
|
|
165
|
+
int initial = (argc > 1) ? xsmcToInteger(xsArg(1)) : 0;
|
|
166
|
+
int reflectInput = (argc > 2) ? xsmcToInteger(xsArg(2)) : 0;
|
|
167
|
+
int reflectOutput = (argc > 3) ? xsmcToInteger(xsArg(3)) : 0;
|
|
168
|
+
int xorOutput = (argc > 4) ? xsmcToInteger(xsArg(4)) : 0;
|
|
169
|
+
CRC16 crc16 = xsmcSetHostChunk(xsThis, NULL, sizeof(CRC16Record));
|
|
170
|
+
|
|
171
|
+
crc16->reset = initial;
|
|
172
|
+
crc16->initial = initial;
|
|
173
|
+
crc16->reflectInput = reflectInput;
|
|
174
|
+
crc16->reflectOutput = reflectOutput;
|
|
175
|
+
crc16->xorOutput = xorOutput;
|
|
176
|
+
|
|
177
|
+
make_crc16_table(polynomial, crc16->table);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
void xs_crc16_close(xsMachine *the)
|
|
181
|
+
{
|
|
182
|
+
xsmcSetHostData(xsThis, NULL);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void xs_crc16_reset(xsMachine *the)
|
|
186
|
+
{
|
|
187
|
+
CRC16 crc16 = xsmcGetHostChunk(xsThis);
|
|
188
|
+
|
|
189
|
+
crc16->initial = crc16->reset;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
void xs_crc16_checksum(xsMachine *the)
|
|
193
|
+
{
|
|
194
|
+
CRC16 crc16 = xsmcGetHostChunk(xsThis);
|
|
195
|
+
uint8_t *data;
|
|
196
|
+
uint32_t length;
|
|
197
|
+
|
|
198
|
+
xsmcGetBufferReadable(xsArg(0), (void **)&data, &length);
|
|
199
|
+
crc16->initial = checksum16(data, length, crc16->table, crc16->initial, crc16->reflectInput);
|
|
200
|
+
|
|
201
|
+
uint16_t crc = crc16->initial;
|
|
202
|
+
if (crc16->reflectOutput)
|
|
203
|
+
crc = (reflect8(crc & 0xff) << 8) | reflect8(crc >> 8);
|
|
204
|
+
xsmcSetInteger(xsResult, crc ^ crc16->xorOutput);
|
|
205
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
|
|
22
|
+
class CRC8 @ "xs_crc8_destructor" {
|
|
23
|
+
constructor(polynomial, initial, reflectInput, reflectOutput, xorOutput) @ "xs_crc8";
|
|
24
|
+
close() @ "xs_crc8_close";
|
|
25
|
+
checksum(buffer) @ "xs_crc8_checksum";
|
|
26
|
+
reset() @ "xs_crc8_reset";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class CRC16 @ "xs_crc16_destructor" {
|
|
30
|
+
constructor(polynomial, initial, reflectInput, reflectOutput, xorOutput) @ "xs_crc16";
|
|
31
|
+
close() @ "xs_crc16_close";
|
|
32
|
+
checksum(buffer) @ "xs_crc16_checksum";
|
|
33
|
+
reset() @ "xs_crc16_reset";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { CRC8 as default, CRC8, CRC16 };
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
hex
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export default class {
|
|
26
|
+
static toString(buffer) @ "xs_hex_toString";
|
|
27
|
+
static toBuffer(string) @ "xs_hex_toBuffer";
|
|
28
|
+
}
|