@nodetool-ai/sandbox-runtime 0.0.0-stage → 0.8.9-bootstrap.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 +24 -2
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/host-access-gate.d.ts +24 -0
- package/dist/host-access-gate.d.ts.map +1 -0
- package/dist/host-access-gate.js +31 -0
- package/dist/host-access-gate.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +318 -0
- package/dist/index.js.map +1 -0
- package/dist/js-sandbox-worker/engine.d.ts +4 -0
- package/dist/js-sandbox-worker/engine.d.ts.map +1 -0
- package/dist/js-sandbox-worker/engine.js +82 -0
- package/dist/js-sandbox-worker/engine.js.map +1 -0
- package/dist/js-sandbox-worker/host.d.ts +136 -0
- package/dist/js-sandbox-worker/host.d.ts.map +1 -0
- package/dist/js-sandbox-worker/host.js +482 -0
- package/dist/js-sandbox-worker/host.js.map +1 -0
- package/dist/js-sandbox-worker/interpreter.d.ts +276 -0
- package/dist/js-sandbox-worker/interpreter.d.ts.map +1 -0
- package/dist/js-sandbox-worker/interpreter.js +1318 -0
- package/dist/js-sandbox-worker/interpreter.js.map +1 -0
- package/dist/js-sandbox-worker/protocol.d.ts +168 -0
- package/dist/js-sandbox-worker/protocol.d.ts.map +1 -0
- package/dist/js-sandbox-worker/protocol.js +217 -0
- package/dist/js-sandbox-worker/protocol.js.map +1 -0
- package/dist/js-sandbox-worker/worker-entry.d.ts +26 -0
- package/dist/js-sandbox-worker/worker-entry.d.ts.map +1 -0
- package/dist/js-sandbox-worker/worker-entry.js +308 -0
- package/dist/js-sandbox-worker/worker-entry.js.map +1 -0
- package/dist/limits.d.ts +77 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +56 -0
- package/dist/limits.js.map +1 -0
- package/dist/sandbox-bootstrap-modules.d.ts +54 -0
- package/dist/sandbox-bootstrap-modules.d.ts.map +1 -0
- package/dist/sandbox-bootstrap-modules.js +104 -0
- package/dist/sandbox-bootstrap-modules.js.map +1 -0
- package/dist/sandbox-bytes.d.ts +43 -0
- package/dist/sandbox-bytes.d.ts.map +1 -0
- package/dist/sandbox-bytes.js +61 -0
- package/dist/sandbox-bytes.js.map +1 -0
- package/dist/sandbox-canvas-api.d.ts +30 -0
- package/dist/sandbox-canvas-api.d.ts.map +1 -0
- package/dist/sandbox-canvas-api.js +81 -0
- package/dist/sandbox-canvas-api.js.map +1 -0
- package/dist/sandbox-constants.d.ts +5 -0
- package/dist/sandbox-constants.d.ts.map +1 -0
- package/dist/sandbox-constants.js +13 -0
- package/dist/sandbox-constants.js.map +1 -0
- package/dist/sandbox-json-transport.d.ts +107 -0
- package/dist/sandbox-json-transport.d.ts.map +1 -0
- package/dist/sandbox-json-transport.js +324 -0
- package/dist/sandbox-json-transport.js.map +1 -0
- package/dist/timeline-capture.d.ts +21 -0
- package/dist/timeline-capture.d.ts.map +1 -0
- package/dist/timeline-capture.js +564 -0
- package/dist/timeline-capture.js.map +1 -0
- package/dist/utils/type-guards.d.ts +26 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/utils/type-guards.js +44 -0
- package/dist/utils/type-guards.js.map +1 -0
- package/package.json +138 -4
- package/vendor/README.md +17 -0
- package/vendor/quickjs/LICENSE +21 -0
- package/vendor/quickjs/PROVENANCE.json +8 -0
- package/vendor/quickjs/adapter/fetch.d.ts +56 -0
- package/vendor/quickjs/adapter/fetch.js +140 -0
- package/vendor/quickjs/createTimeInterval.d.ts +9 -0
- package/vendor/quickjs/createTimeInterval.js +22 -0
- package/vendor/quickjs/createVirtualFileSystem.d.ts +13 -0
- package/vendor/quickjs/createVirtualFileSystem.js +191 -0
- package/vendor/quickjs/index.d.ts +77 -0
- package/vendor/quickjs/index.js +77 -0
- package/vendor/quickjs/loadAsyncQuickJs.d.ts +12 -0
- package/vendor/quickjs/loadAsyncQuickJs.js +66 -0
- package/vendor/quickjs/loadQuickJs.d.ts +12 -0
- package/vendor/quickjs/loadQuickJs.js +73 -0
- package/vendor/quickjs/modules/assert.d.ts +2 -0
- package/vendor/quickjs/modules/assert.js +47 -0
- package/vendor/quickjs/modules/buffer.d.ts +2 -0
- package/vendor/quickjs/modules/buffer.js +106 -0
- package/vendor/quickjs/modules/build/test-lib.js +2 -0
- package/vendor/quickjs/modules/events.d.ts +2 -0
- package/vendor/quickjs/modules/events.js +4 -0
- package/vendor/quickjs/modules/fs.d.ts +2 -0
- package/vendor/quickjs/modules/fs.js +76 -0
- package/vendor/quickjs/modules/fs_promises.d.ts +2 -0
- package/vendor/quickjs/modules/fs_promises.js +328 -0
- package/vendor/quickjs/modules/module.d.ts +2 -0
- package/vendor/quickjs/modules/module.js +33 -0
- package/vendor/quickjs/modules/nodeCompatibility/headers.d.ts +2 -0
- package/vendor/quickjs/modules/nodeCompatibility/headers.js +58 -0
- package/vendor/quickjs/modules/nodeCompatibility/request.d.ts +2 -0
- package/vendor/quickjs/modules/nodeCompatibility/request.js +5 -0
- package/vendor/quickjs/modules/nodeCompatibility/response.d.ts +2 -0
- package/vendor/quickjs/modules/nodeCompatibility/response.js +5 -0
- package/vendor/quickjs/modules/path.d.ts +2 -0
- package/vendor/quickjs/modules/path.js +504 -0
- package/vendor/quickjs/modules/process.d.ts +2 -0
- package/vendor/quickjs/modules/process.js +309 -0
- package/vendor/quickjs/modules/punycode.d.ts +2 -0
- package/vendor/quickjs/modules/punycode.js +443 -0
- package/vendor/quickjs/modules/querystring.d.ts +2 -0
- package/vendor/quickjs/modules/querystring.js +15 -0
- package/vendor/quickjs/modules/string_decoder.d.ts +2 -0
- package/vendor/quickjs/modules/string_decoder.js +223 -0
- package/vendor/quickjs/modules/timers.d.ts +2 -0
- package/vendor/quickjs/modules/timers.js +10 -0
- package/vendor/quickjs/modules/timers_promises.d.ts +2 -0
- package/vendor/quickjs/modules/timers_promises.js +40 -0
- package/vendor/quickjs/modules/url.d.ts +2 -0
- package/vendor/quickjs/modules/url.js +104 -0
- package/vendor/quickjs/modules/util.d.ts +2 -0
- package/vendor/quickjs/modules/util.js +233 -0
- package/vendor/quickjs/package.json +3 -0
- package/vendor/quickjs/sandbox/asyncVersion/createAsyncEvalCodeFunction.d.ts +4 -0
- package/vendor/quickjs/sandbox/asyncVersion/createAsyncEvalCodeFunction.js +76 -0
- package/vendor/quickjs/sandbox/asyncVersion/createAsyncValidateCodeFunction.d.ts +3 -0
- package/vendor/quickjs/sandbox/asyncVersion/createAsyncValidateCodeFunction.js +22 -0
- package/vendor/quickjs/sandbox/asyncVersion/executeAsyncSandboxFunction.d.ts +12 -0
- package/vendor/quickjs/sandbox/asyncVersion/executeAsyncSandboxFunction.js +9 -0
- package/vendor/quickjs/sandbox/asyncVersion/getAsyncModuleLoader.d.ts +4 -0
- package/vendor/quickjs/sandbox/asyncVersion/getAsyncModuleLoader.js +30 -0
- package/vendor/quickjs/sandbox/asyncVersion/modulePathNormalizerAsync.d.ts +2 -0
- package/vendor/quickjs/sandbox/asyncVersion/modulePathNormalizerAsync.js +12 -0
- package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncNodeCompatibility.d.ts +3 -0
- package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncNodeCompatibility.js +11 -0
- package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncSandbox.d.ts +4 -0
- package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncSandbox.js +10 -0
- package/vendor/quickjs/sandbox/expose/expose.d.ts +3 -0
- package/vendor/quickjs/sandbox/expose/expose.js +155 -0
- package/vendor/quickjs/sandbox/expose/isES2015Class.d.ts +1 -0
- package/vendor/quickjs/sandbox/expose/isES2015Class.js +4 -0
- package/vendor/quickjs/sandbox/expose/isObject.d.ts +1 -0
- package/vendor/quickjs/sandbox/expose/isObject.js +4 -0
- package/vendor/quickjs/sandbox/expose/pendingHostPromises.d.ts +6 -0
- package/vendor/quickjs/sandbox/expose/pendingHostPromises.js +40 -0
- package/vendor/quickjs/sandbox/getMaxIntervalAmount.d.ts +8 -0
- package/vendor/quickjs/sandbox/getMaxIntervalAmount.js +12 -0
- package/vendor/quickjs/sandbox/getMaxTimeoutAmount.d.ts +8 -0
- package/vendor/quickjs/sandbox/getMaxTimeoutAmount.js +12 -0
- package/vendor/quickjs/sandbox/handleEvalError.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleEvalError.js +21 -0
- package/vendor/quickjs/sandbox/handleToNative/handleToNative.d.ts +9 -0
- package/vendor/quickjs/sandbox/handleToNative/handleToNative.js +153 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/index.d.ts +10 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/index.js +36 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeArrayBuffer.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeArrayBuffer.js +4 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeBuffer.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeBuffer.js +16 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeDate.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeDate.js +16 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeError.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeError.js +18 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeHeaders.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeHeaders.js +17 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeMap.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeMap.js +18 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeSet.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeSet.js +16 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeURLSearchParams.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeURLSearchParams.js +17 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeUrl.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeUrl.js +17 -0
- package/vendor/quickjs/sandbox/helper.d.ts +2 -0
- package/vendor/quickjs/sandbox/helper.js +14 -0
- package/vendor/quickjs/sandbox/provide/provideConsole.d.ts +6 -0
- package/vendor/quickjs/sandbox/provide/provideConsole.js +53 -0
- package/vendor/quickjs/sandbox/provide/provideEnv.d.ts +3 -0
- package/vendor/quickjs/sandbox/provide/provideEnv.js +10 -0
- package/vendor/quickjs/sandbox/provide/provideFs.d.ts +4 -0
- package/vendor/quickjs/sandbox/provide/provideFs.js +159 -0
- package/vendor/quickjs/sandbox/provide/provideHttp.d.ts +9 -0
- package/vendor/quickjs/sandbox/provide/provideHttp.js +42 -0
- package/vendor/quickjs/sandbox/provide/provideTimingFunctions.d.ts +7 -0
- package/vendor/quickjs/sandbox/provide/provideTimingFunctions.js +119 -0
- package/vendor/quickjs/sandbox/setupFileSystem.d.ts +3 -0
- package/vendor/quickjs/sandbox/setupFileSystem.js +13 -0
- package/vendor/quickjs/sandbox/syncVersion/createEvalCodeFunction.d.ts +4 -0
- package/vendor/quickjs/sandbox/syncVersion/createEvalCodeFunction.js +76 -0
- package/vendor/quickjs/sandbox/syncVersion/createValidateCodeFunction.d.ts +3 -0
- package/vendor/quickjs/sandbox/syncVersion/createValidateCodeFunction.js +22 -0
- package/vendor/quickjs/sandbox/syncVersion/executeSandboxFunction.d.ts +12 -0
- package/vendor/quickjs/sandbox/syncVersion/executeSandboxFunction.js +9 -0
- package/vendor/quickjs/sandbox/syncVersion/getModuleLoader.d.ts +4 -0
- package/vendor/quickjs/sandbox/syncVersion/getModuleLoader.js +30 -0
- package/vendor/quickjs/sandbox/syncVersion/modulePathNormalizer.d.ts +2 -0
- package/vendor/quickjs/sandbox/syncVersion/modulePathNormalizer.js +12 -0
- package/vendor/quickjs/sandbox/syncVersion/prepareNodeCompatibility.d.ts +3 -0
- package/vendor/quickjs/sandbox/syncVersion/prepareNodeCompatibility.js +11 -0
- package/vendor/quickjs/sandbox/syncVersion/prepareSandbox.d.ts +4 -0
- package/vendor/quickjs/sandbox/syncVersion/prepareSandbox.js +10 -0
- package/vendor/quickjs/types/CodeFunctionInput.d.ts +12 -0
- package/vendor/quickjs/types/CodeFunctionInput.js +1 -0
- package/vendor/quickjs/types/ErrorResponse.d.ts +9 -0
- package/vendor/quickjs/types/ErrorResponse.js +1 -0
- package/vendor/quickjs/types/LoadQuickJsOptions.d.ts +3 -0
- package/vendor/quickjs/types/LoadQuickJsOptions.js +1 -0
- package/vendor/quickjs/types/OkResponse.d.ts +4 -0
- package/vendor/quickjs/types/OkResponse.js +1 -0
- package/vendor/quickjs/types/OkResponseCheck.d.ts +3 -0
- package/vendor/quickjs/types/OkResponseCheck.js +1 -0
- package/vendor/quickjs/types/Prettify.d.ts +3 -0
- package/vendor/quickjs/types/Prettify.js +1 -0
- package/vendor/quickjs/types/RuntimeOptions.d.ts +87 -0
- package/vendor/quickjs/types/RuntimeOptions.js +1 -0
- package/vendor/quickjs/types/SandboxEvalCode.d.ts +5 -0
- package/vendor/quickjs/types/SandboxEvalCode.js +1 -0
- package/vendor/quickjs/types/SandboxFunction.d.ts +16 -0
- package/vendor/quickjs/types/SandboxFunction.js +1 -0
- package/vendor/quickjs/types/SandboxOptions.d.ts +152 -0
- package/vendor/quickjs/types/SandboxOptions.js +1 -0
- package/vendor/quickjs/types/SandboxValidateCode.d.ts +9 -0
- package/vendor/quickjs/types/SandboxValidateCode.js +1 -0
- package/vendor/quickjs/types/Serializer.d.ts +2 -0
- package/vendor/quickjs/types/Serializer.js +1 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
export default `
|
|
2
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
5
|
+
// copy of this software and associated documentation files (the
|
|
6
|
+
// "Software"), to deal in the Software without restriction, including
|
|
7
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
9
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
10
|
+
// following conditions:
|
|
11
|
+
//
|
|
12
|
+
// The above copyright notice and this permission notice shall be included
|
|
13
|
+
// in all copies or substantial portions of the Software.
|
|
14
|
+
//
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
16
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
18
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
19
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
20
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
21
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
import {Buffer} from 'node:buffer';
|
|
24
|
+
|
|
25
|
+
var isBufferEncoding = Buffer.isEncoding
|
|
26
|
+
|| function(encoding) {
|
|
27
|
+
switch (encoding && encoding.toLowerCase()) {
|
|
28
|
+
case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;
|
|
29
|
+
default: return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function assertEncoding(encoding) {
|
|
35
|
+
if (encoding && !isBufferEncoding(encoding)) {
|
|
36
|
+
throw new Error('Unknown encoding: ' + encoding);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// StringDecoder provides an interface for efficiently splitting a series of
|
|
41
|
+
// buffers into a series of JS strings without breaking apart multi-byte
|
|
42
|
+
// characters. CESU-8 is handled as part of the UTF-8 encoding.
|
|
43
|
+
//
|
|
44
|
+
// @TODO Handling all encodings inside a single object makes it very difficult
|
|
45
|
+
// to reason about this code, so it should be split up in the future.
|
|
46
|
+
// @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
|
|
47
|
+
// points as used by CESU-8.
|
|
48
|
+
export function StringDecoder(encoding) {
|
|
49
|
+
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
|
|
50
|
+
assertEncoding(encoding);
|
|
51
|
+
switch (this.encoding) {
|
|
52
|
+
case 'utf8':
|
|
53
|
+
// CESU-8 represents each of Surrogate Pair by 3-bytes
|
|
54
|
+
this.surrogateSize = 3;
|
|
55
|
+
break;
|
|
56
|
+
case 'ucs2':
|
|
57
|
+
case 'utf16le':
|
|
58
|
+
// UTF-16 represents each of Surrogate Pair by 2-bytes
|
|
59
|
+
this.surrogateSize = 2;
|
|
60
|
+
this.detectIncompleteChar = utf16DetectIncompleteChar;
|
|
61
|
+
break;
|
|
62
|
+
case 'base64':
|
|
63
|
+
// Base-64 stores 3 bytes in 4 chars, and pads the remainder.
|
|
64
|
+
this.surrogateSize = 3;
|
|
65
|
+
this.detectIncompleteChar = base64DetectIncompleteChar;
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
this.write = passThroughWrite;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Enough space to store all bytes of a single character. UTF-8 needs 4
|
|
73
|
+
// bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
|
|
74
|
+
this.charBuffer = new Buffer(6);
|
|
75
|
+
// Number of bytes received for the current incomplete multi-byte character.
|
|
76
|
+
this.charReceived = 0;
|
|
77
|
+
// Number of bytes expected for the current incomplete multi-byte character.
|
|
78
|
+
this.charLength = 0;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
// write decodes the given buffer and returns it as JS string that is
|
|
83
|
+
// guaranteed to not contain any partial multi-byte characters. Any partial
|
|
84
|
+
// character found at the end of the buffer is buffered up, and will be
|
|
85
|
+
// returned when calling write again with the remaining bytes.
|
|
86
|
+
//
|
|
87
|
+
// Note: Converting a Buffer containing an orphan surrogate to a String
|
|
88
|
+
// currently works, but converting a String to a Buffer (via \`new Buffer\`, or
|
|
89
|
+
// Buffer#write) will replace incomplete surrogates with the unicode
|
|
90
|
+
// replacement character. See https://codereview.chromium.org/121173009/ .
|
|
91
|
+
StringDecoder.prototype.write = function(buffer) {
|
|
92
|
+
var charStr = '';
|
|
93
|
+
// if our last write ended with an incomplete multibyte character
|
|
94
|
+
while (this.charLength) {
|
|
95
|
+
// determine how many remaining bytes this buffer has to offer for this char
|
|
96
|
+
var available = (buffer.length >= this.charLength - this.charReceived) ?
|
|
97
|
+
this.charLength - this.charReceived :
|
|
98
|
+
buffer.length;
|
|
99
|
+
|
|
100
|
+
// add the new bytes to the char buffer
|
|
101
|
+
buffer.copy(this.charBuffer, this.charReceived, 0, available);
|
|
102
|
+
this.charReceived += available;
|
|
103
|
+
|
|
104
|
+
if (this.charReceived < this.charLength) {
|
|
105
|
+
// still not enough chars in this buffer? wait for more ...
|
|
106
|
+
return '';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// remove bytes belonging to the current character from the buffer
|
|
110
|
+
buffer = buffer.slice(available, buffer.length);
|
|
111
|
+
|
|
112
|
+
// get the character that was split
|
|
113
|
+
charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
|
|
114
|
+
|
|
115
|
+
// CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
|
|
116
|
+
var charCode = charStr.charCodeAt(charStr.length - 1);
|
|
117
|
+
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
|
118
|
+
this.charLength += this.surrogateSize;
|
|
119
|
+
charStr = '';
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
this.charReceived = this.charLength = 0;
|
|
123
|
+
|
|
124
|
+
// if there are no more bytes in this buffer, just emit our char
|
|
125
|
+
if (buffer.length === 0) {
|
|
126
|
+
return charStr;
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// determine and set charLength / charReceived
|
|
132
|
+
this.detectIncompleteChar(buffer);
|
|
133
|
+
|
|
134
|
+
var end = buffer.length;
|
|
135
|
+
if (this.charLength) {
|
|
136
|
+
// buffer the incomplete character bytes we got
|
|
137
|
+
buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
|
|
138
|
+
end -= this.charReceived;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
charStr += buffer.toString(this.encoding, 0, end);
|
|
142
|
+
|
|
143
|
+
var end = charStr.length - 1;
|
|
144
|
+
var charCode = charStr.charCodeAt(end);
|
|
145
|
+
// CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
|
|
146
|
+
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
|
147
|
+
var size = this.surrogateSize;
|
|
148
|
+
this.charLength += size;
|
|
149
|
+
this.charReceived += size;
|
|
150
|
+
this.charBuffer.copy(this.charBuffer, size, 0, size);
|
|
151
|
+
buffer.copy(this.charBuffer, 0, 0, size);
|
|
152
|
+
return charStr.substring(0, end);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// or just emit the charStr
|
|
156
|
+
return charStr;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// detectIncompleteChar determines if there is an incomplete UTF-8 character at
|
|
160
|
+
// the end of the given buffer. If so, it sets this.charLength to the byte
|
|
161
|
+
// length that character, and sets this.charReceived to the number of bytes
|
|
162
|
+
// that are available for this character.
|
|
163
|
+
StringDecoder.prototype.detectIncompleteChar = function(buffer) {
|
|
164
|
+
// determine how many bytes we have to check at the end of this buffer
|
|
165
|
+
var i = (buffer.length >= 3) ? 3 : buffer.length;
|
|
166
|
+
|
|
167
|
+
// Figure out if one of the last i bytes of our buffer announces an
|
|
168
|
+
// incomplete char.
|
|
169
|
+
for (; i > 0; i--) {
|
|
170
|
+
var c = buffer[buffer.length - i];
|
|
171
|
+
|
|
172
|
+
// See http://en.wikipedia.org/wiki/UTF-8#Description
|
|
173
|
+
|
|
174
|
+
// 110XXXXX
|
|
175
|
+
if (i == 1 && c >> 5 == 0x06) {
|
|
176
|
+
this.charLength = 2;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 1110XXXX
|
|
181
|
+
if (i <= 2 && c >> 4 == 0x0E) {
|
|
182
|
+
this.charLength = 3;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 11110XXX
|
|
187
|
+
if (i <= 3 && c >> 3 == 0x1E) {
|
|
188
|
+
this.charLength = 4;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
this.charReceived = i;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
StringDecoder.prototype.end = function(buffer) {
|
|
196
|
+
var res = '';
|
|
197
|
+
if (buffer && buffer.length)
|
|
198
|
+
res = this.write(buffer);
|
|
199
|
+
|
|
200
|
+
if (this.charReceived) {
|
|
201
|
+
var cr = this.charReceived;
|
|
202
|
+
var buf = this.charBuffer;
|
|
203
|
+
var enc = this.encoding;
|
|
204
|
+
res += buf.slice(0, cr).toString(enc);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return res;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
function passThroughWrite(buffer) {
|
|
211
|
+
return buffer.toString(this.encoding);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function utf16DetectIncompleteChar(buffer) {
|
|
215
|
+
this.charReceived = buffer.length % 2;
|
|
216
|
+
this.charLength = this.charReceived ? 2 : 0;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function base64DetectIncompleteChar(buffer) {
|
|
220
|
+
this.charReceived = buffer.length % 3;
|
|
221
|
+
this.charLength = this.charReceived ? 3 : 0;
|
|
222
|
+
}
|
|
223
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "\nexport setTimeout\nexport clearTimeout\nexport setInterval\nexport clearInterval\nexport setImmediate\nexport clearImmediate\n\nexport default {setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate }\n";
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "\nexport const setTimeout = (delay, value, options) => new Promise((resolve, reject) => {\n const id = globalThis.setTimeout(() => resolve(value), delay);\n if (options && options.signal) {\n const abortHandler = () => {\n globalThis.clearTimeout(id);\n reject(options.signal.reason ?? new Error('AbortError'));\n };\n if (options.signal.aborted) {\n abortHandler();\n return;\n }\n options.signal.addEventListener('abort', abortHandler, { once: true });\n }\n});\n\nexport const setImmediate = (value, options) => new Promise((resolve, reject) => {\n const id = globalThis.setTimeout(() => resolve(value), 0);\n if (options && options.signal) {\n const abortHandler = () => {\n globalThis.clearTimeout(id);\n reject(options.signal.reason ?? new Error('AbortError'));\n };\n if (options.signal.aborted) {\n abortHandler();\n return;\n }\n options.signal.addEventListener('abort', abortHandler, { once: true });\n }\n});\n\nexport async function* setInterval(delay, value) {\n while (true) {\n await new Promise((resolve) => globalThis.setTimeout(resolve, delay));\n yield value;\n }\n}\n\nexport default { setTimeout, setImmediate, setInterval }\n";
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export default `
|
|
2
|
+
export const setTimeout = (delay, value, options) => new Promise((resolve, reject) => {
|
|
3
|
+
const id = globalThis.setTimeout(() => resolve(value), delay);
|
|
4
|
+
if (options && options.signal) {
|
|
5
|
+
const abortHandler = () => {
|
|
6
|
+
globalThis.clearTimeout(id);
|
|
7
|
+
reject(options.signal.reason ?? new Error('AbortError'));
|
|
8
|
+
};
|
|
9
|
+
if (options.signal.aborted) {
|
|
10
|
+
abortHandler();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
options.signal.addEventListener('abort', abortHandler, { once: true });
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const setImmediate = (value, options) => new Promise((resolve, reject) => {
|
|
18
|
+
const id = globalThis.setTimeout(() => resolve(value), 0);
|
|
19
|
+
if (options && options.signal) {
|
|
20
|
+
const abortHandler = () => {
|
|
21
|
+
globalThis.clearTimeout(id);
|
|
22
|
+
reject(options.signal.reason ?? new Error('AbortError'));
|
|
23
|
+
};
|
|
24
|
+
if (options.signal.aborted) {
|
|
25
|
+
abortHandler();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
options.signal.addEventListener('abort', abortHandler, { once: true });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export async function* setInterval(delay, value) {
|
|
33
|
+
while (true) {
|
|
34
|
+
await new Promise((resolve) => globalThis.setTimeout(resolve, delay));
|
|
35
|
+
yield value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default { setTimeout, setImmediate, setInterval }
|
|
40
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "\n\nexport class URL {\n constructor(url, base) {\n const parser = __parseURL(url,base)\n this.href = parser.href;\n this.protocol = parser.protocol;\n this.host = parser.host;\n this.hostname = parser.hostname;\n this.port = parser.port;\n this.pathname = parser.pathname;\n this.search = parser.search;\n this.searchParams = new URLSearchParams(parser.search)\n this.hash = parser.hash;\n this.username = parser.username;\n this.password = parser.password;\n this.origin = parser.protocol+'//'+parser.host;\n }\n\n toString() {\n return this.href;\n }\n\n toJSON() {\n return this.href;\n }\n}\n\n\n\n\nexport class URLSearchParams {\n constructor(init = '') {\n this.params = {};\n\n if (typeof init === 'string') {\n this._parseFromString(init);\n } else if (init instanceof URLSearchParams) {\n init.forEach((value, key) => this.append(key, value));\n } else if (typeof init === 'object') {\n Object.keys(init).forEach(key => this.append(key, init[key]));\n }\n }\n\n _parseFromString(query) {\n if (query.startsWith('?')) {\n query = query.slice(1);\n }\n query.split('&').forEach(pair => {\n const [key, value] = pair.split('=').map(decodeURIComponent);\n this.append(key, value);\n });\n }\n\n append(key, value) {\n if (!this.params[key]) {\n this.params[key] = [];\n }\n this.params[key].push(value);\n }\n\n delete(key) {\n delete this.params[key];\n }\n\n get(key) {\n return this.params[key] ? this.params[key][0] : null;\n }\n\n getAll(key) {\n return this.params[key] || [];\n }\n\n has(key) {\n return this.params.hasOwnProperty(key);\n }\n\n set(key, value) {\n this.params[key] = [value];\n }\n\n toString() {\n return Object.keys(this.params)\n .map(key => this.params[key]\n .map(value => encodeURIComponent(key)+'='+encodeURIComponent(value))\n .join('&'))\n .join('&');\n }\n\n forEach(callback, thisArg) {\n Object.keys(this.params).forEach(key => {\n this.params[key].forEach(value => {\n callback.call(thisArg, value, key, this);\n });\n });\n }\n}\n\nglobalThis.URLSearchParams = URLSearchParams;\nglobalThis.URL = URL;\n\n\nexport default { URLSearchParams, URL }\n";
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export default `
|
|
2
|
+
|
|
3
|
+
export class URL {
|
|
4
|
+
constructor(url, base) {
|
|
5
|
+
const parser = __parseURL(url,base)
|
|
6
|
+
this.href = parser.href;
|
|
7
|
+
this.protocol = parser.protocol;
|
|
8
|
+
this.host = parser.host;
|
|
9
|
+
this.hostname = parser.hostname;
|
|
10
|
+
this.port = parser.port;
|
|
11
|
+
this.pathname = parser.pathname;
|
|
12
|
+
this.search = parser.search;
|
|
13
|
+
this.searchParams = new URLSearchParams(parser.search)
|
|
14
|
+
this.hash = parser.hash;
|
|
15
|
+
this.username = parser.username;
|
|
16
|
+
this.password = parser.password;
|
|
17
|
+
this.origin = parser.protocol+'//'+parser.host;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toString() {
|
|
21
|
+
return this.href;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
toJSON() {
|
|
25
|
+
return this.href;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export class URLSearchParams {
|
|
33
|
+
constructor(init = '') {
|
|
34
|
+
this.params = {};
|
|
35
|
+
|
|
36
|
+
if (typeof init === 'string') {
|
|
37
|
+
this._parseFromString(init);
|
|
38
|
+
} else if (init instanceof URLSearchParams) {
|
|
39
|
+
init.forEach((value, key) => this.append(key, value));
|
|
40
|
+
} else if (typeof init === 'object') {
|
|
41
|
+
Object.keys(init).forEach(key => this.append(key, init[key]));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_parseFromString(query) {
|
|
46
|
+
if (query.startsWith('?')) {
|
|
47
|
+
query = query.slice(1);
|
|
48
|
+
}
|
|
49
|
+
query.split('&').forEach(pair => {
|
|
50
|
+
const [key, value] = pair.split('=').map(decodeURIComponent);
|
|
51
|
+
this.append(key, value);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
append(key, value) {
|
|
56
|
+
if (!this.params[key]) {
|
|
57
|
+
this.params[key] = [];
|
|
58
|
+
}
|
|
59
|
+
this.params[key].push(value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
delete(key) {
|
|
63
|
+
delete this.params[key];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get(key) {
|
|
67
|
+
return this.params[key] ? this.params[key][0] : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getAll(key) {
|
|
71
|
+
return this.params[key] || [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
has(key) {
|
|
75
|
+
return this.params.hasOwnProperty(key);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
set(key, value) {
|
|
79
|
+
this.params[key] = [value];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
toString() {
|
|
83
|
+
return Object.keys(this.params)
|
|
84
|
+
.map(key => this.params[key]
|
|
85
|
+
.map(value => encodeURIComponent(key)+'='+encodeURIComponent(value))
|
|
86
|
+
.join('&'))
|
|
87
|
+
.join('&');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
forEach(callback, thisArg) {
|
|
91
|
+
Object.keys(this.params).forEach(key => {
|
|
92
|
+
this.params[key].forEach(value => {
|
|
93
|
+
callback.call(thisArg, value, key, this);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
globalThis.URLSearchParams = URLSearchParams;
|
|
100
|
+
globalThis.URL = URL;
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
export default { URLSearchParams, URL }
|
|
104
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "\n\nclass TextEncoder {\n encode(input = '') {\n const utf8 = unescape(encodeURIComponent(input));\n const result = new Uint8Array(utf8.length);\n \n for (let i = 0; i < utf8.length; i++) {\n result[i] = utf8.charCodeAt(i);\n }\n \n return result;\n }\n}\n\nclass TextDecoder {\n constructor(encoding = 'utf-8') {\n if (encoding !== 'utf-8') {\n throw new Error('Only utf-8 encoding is supported');\n }\n }\n\n decode(input = new Uint8Array()) {\n let str = '';\n for (let i = 0; i < input.length; i++) {\n str += String.fromCharCode(input[i]);\n }\n return decodeURIComponent(escape(str));\n }\n}\n\n// Promisify: converts a callback-based function to a promise-based one\nfunction promisify(fn) {\n return function (...args) {\n return new Promise((resolve, reject) => {\n fn(...args, (err, result) => {\n if (err) {\n reject(err);\n } else {\n resolve(result);\n }\n });\n });\n };\n}\n\n// Callbackify: converts a promise-based function to a callback-based one\nfunction callbackify(fn) {\n return function (...args) {\n const cb = args.pop();\n fn(...args)\n .then((result) => cb(null, result))\n .catch((err) => cb(err));\n };\n}\n\n// Inherits: implements inheritance\nfunction inherits(ctor, superCtor) {\n if (typeof superCtor !== 'function' && superCtor !== null) {\n throw new TypeError('Super constructor must either be a function or null');\n }\n\n ctor.super_ = superCtor;\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(ctor.prototype, superCtor.prototype);\n } else {\n ctor.prototype.__proto__ = superCtor.prototype;\n }\n}\n\n// Deprecate: marks a method as deprecated\nfunction deprecate(fn, msg) {\n let warned = false;\n function deprecated(...args) {\n if (!warned) {\n console.warn(`DeprecationWarning: ${msg}`);\n warned = true;\n }\n return fn.apply(this, args);\n }\n return deprecated;\n}\n\nconst types = {\n isAnyArrayBuffer(value) {\n return value instanceof ArrayBuffer || value instanceof SharedArrayBuffer;\n },\n isArrayBufferView(value) {\n return ArrayBuffer.isView(value);\n },\n isArgumentsObject(value) {\n return Object.prototype.toString.call(value) === '[object Arguments]';\n },\n isArrayBuffer(value) {\n return value instanceof ArrayBuffer;\n },\n isAsyncFunction(value) {\n return Object.prototype.toString.call(value) === '[object AsyncFunction]';\n },\n isBigInt64Array(value) {\n return value instanceof BigInt64Array;\n },\n isBigUint64Array(value) {\n return value instanceof BigUint64Array;\n },\n isBooleanObject(value) {\n return typeof value === 'object' && typeof value.valueOf() === 'boolean';\n },\n isBoxedPrimitive(value) {\n return ['[object Number]', '[object String]', '[object Boolean]', '[object Symbol]'].includes(Object.prototype.toString.call(value));\n },\n isCryptoKey(value) {\n return typeof CryptoKey !== 'undefined' && value instanceof CryptoKey;\n },\n isDataView(value) {\n return value instanceof DataView;\n },\n isDate(value) {\n return value instanceof Date;\n },\n isExternal(value) {\n return false; // Node.js specific\n },\n isFloat32Array(value) {\n return value instanceof Float32Array;\n },\n isFloat64Array(value) {\n return value instanceof Float64Array;\n },\n isGeneratorFunction(value) {\n return Object.prototype.toString.call(value) === '[object GeneratorFunction]';\n },\n isGeneratorObject(value) {\n return Object.prototype.toString.call(value) === '[object Generator]';\n },\n isInt8Array(value) {\n return value instanceof Int8Array;\n },\n isInt16Array(value) {\n return value instanceof Int16Array;\n },\n isInt32Array(value) {\n return value instanceof Int32Array;\n },\n isKeyObject(value) {\n return false; // Node.js specific\n },\n isMap(value) {\n return value instanceof Map;\n },\n isMapIterator(value) {\n return Object.prototype.toString.call(value) === '[object Map Iterator]';\n },\n isModuleNamespaceObject(value) {\n return Object.prototype.toString.call(value) === '[object Module]';\n },\n isNativeError(value) {\n return value instanceof Error;\n },\n isNumberObject(value) {\n return typeof value === 'object' && typeof value.valueOf() === 'number';\n },\n isPromise(value) {\n return value instanceof Promise;\n },\n isProxy(value) {\n try {\n Proxy.revocable(value, {});\n return true;\n } catch (e) {\n return false;\n }\n },\n isRegExp(value) {\n return value instanceof RegExp;\n },\n isSet(value) {\n return value instanceof Set;\n },\n isSetIterator(value) {\n return Object.prototype.toString.call(value) === '[object Set Iterator]';\n },\n isSharedArrayBuffer(value) {\n return value instanceof SharedArrayBuffer;\n },\n isStringObject(value) {\n return typeof value === 'object' && typeof value.valueOf() === 'string';\n },\n isSymbolObject(value) {\n return typeof value === 'object' && typeof value.valueOf() === 'symbol';\n },\n isTypedArray(value) {\n return ArrayBuffer.isView(value) && !(value instanceof DataView);\n },\n isUint8Array(value) {\n return value instanceof Uint8Array;\n },\n isUint8ClampedArray(value) {\n return value instanceof Uint8ClampedArray;\n },\n isUint16Array(value) {\n return value instanceof Uint16Array;\n },\n isUint32Array(value) {\n return value instanceof Uint32Array;\n },\n isWeakMap(value) {\n return value instanceof WeakMap;\n },\n isWeakSet(value) {\n return value instanceof WeakSet;\n },\n }\n\n\nconst util = {\n promisify,\n callbackify,\n inherits,\n deprecate,\n types,\n TextEncoder,\n TextDecoder\n};\n\nglobalThis.TextEncoder = TextEncoder;\nglobalThis.TextDecoder = TextDecoder;\n\nexport default util;\n\nexport { promisify, callbackify, inherits, deprecate, types, TextEncoder,TextDecoder };\n\n";
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
export default `
|
|
2
|
+
|
|
3
|
+
class TextEncoder {
|
|
4
|
+
encode(input = '') {
|
|
5
|
+
const utf8 = unescape(encodeURIComponent(input));
|
|
6
|
+
const result = new Uint8Array(utf8.length);
|
|
7
|
+
|
|
8
|
+
for (let i = 0; i < utf8.length; i++) {
|
|
9
|
+
result[i] = utf8.charCodeAt(i);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class TextDecoder {
|
|
17
|
+
constructor(encoding = 'utf-8') {
|
|
18
|
+
if (encoding !== 'utf-8') {
|
|
19
|
+
throw new Error('Only utf-8 encoding is supported');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
decode(input = new Uint8Array()) {
|
|
24
|
+
let str = '';
|
|
25
|
+
for (let i = 0; i < input.length; i++) {
|
|
26
|
+
str += String.fromCharCode(input[i]);
|
|
27
|
+
}
|
|
28
|
+
return decodeURIComponent(escape(str));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Promisify: converts a callback-based function to a promise-based one
|
|
33
|
+
function promisify(fn) {
|
|
34
|
+
return function (...args) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
fn(...args, (err, result) => {
|
|
37
|
+
if (err) {
|
|
38
|
+
reject(err);
|
|
39
|
+
} else {
|
|
40
|
+
resolve(result);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Callbackify: converts a promise-based function to a callback-based one
|
|
48
|
+
function callbackify(fn) {
|
|
49
|
+
return function (...args) {
|
|
50
|
+
const cb = args.pop();
|
|
51
|
+
fn(...args)
|
|
52
|
+
.then((result) => cb(null, result))
|
|
53
|
+
.catch((err) => cb(err));
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Inherits: implements inheritance
|
|
58
|
+
function inherits(ctor, superCtor) {
|
|
59
|
+
if (typeof superCtor !== 'function' && superCtor !== null) {
|
|
60
|
+
throw new TypeError('Super constructor must either be a function or null');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ctor.super_ = superCtor;
|
|
64
|
+
if (Object.setPrototypeOf) {
|
|
65
|
+
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
|
|
66
|
+
} else {
|
|
67
|
+
ctor.prototype.__proto__ = superCtor.prototype;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Deprecate: marks a method as deprecated
|
|
72
|
+
function deprecate(fn, msg) {
|
|
73
|
+
let warned = false;
|
|
74
|
+
function deprecated(...args) {
|
|
75
|
+
if (!warned) {
|
|
76
|
+
console.warn(\`DeprecationWarning: \${msg}\`);
|
|
77
|
+
warned = true;
|
|
78
|
+
}
|
|
79
|
+
return fn.apply(this, args);
|
|
80
|
+
}
|
|
81
|
+
return deprecated;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const types = {
|
|
85
|
+
isAnyArrayBuffer(value) {
|
|
86
|
+
return value instanceof ArrayBuffer || value instanceof SharedArrayBuffer;
|
|
87
|
+
},
|
|
88
|
+
isArrayBufferView(value) {
|
|
89
|
+
return ArrayBuffer.isView(value);
|
|
90
|
+
},
|
|
91
|
+
isArgumentsObject(value) {
|
|
92
|
+
return Object.prototype.toString.call(value) === '[object Arguments]';
|
|
93
|
+
},
|
|
94
|
+
isArrayBuffer(value) {
|
|
95
|
+
return value instanceof ArrayBuffer;
|
|
96
|
+
},
|
|
97
|
+
isAsyncFunction(value) {
|
|
98
|
+
return Object.prototype.toString.call(value) === '[object AsyncFunction]';
|
|
99
|
+
},
|
|
100
|
+
isBigInt64Array(value) {
|
|
101
|
+
return value instanceof BigInt64Array;
|
|
102
|
+
},
|
|
103
|
+
isBigUint64Array(value) {
|
|
104
|
+
return value instanceof BigUint64Array;
|
|
105
|
+
},
|
|
106
|
+
isBooleanObject(value) {
|
|
107
|
+
return typeof value === 'object' && typeof value.valueOf() === 'boolean';
|
|
108
|
+
},
|
|
109
|
+
isBoxedPrimitive(value) {
|
|
110
|
+
return ['[object Number]', '[object String]', '[object Boolean]', '[object Symbol]'].includes(Object.prototype.toString.call(value));
|
|
111
|
+
},
|
|
112
|
+
isCryptoKey(value) {
|
|
113
|
+
return typeof CryptoKey !== 'undefined' && value instanceof CryptoKey;
|
|
114
|
+
},
|
|
115
|
+
isDataView(value) {
|
|
116
|
+
return value instanceof DataView;
|
|
117
|
+
},
|
|
118
|
+
isDate(value) {
|
|
119
|
+
return value instanceof Date;
|
|
120
|
+
},
|
|
121
|
+
isExternal(value) {
|
|
122
|
+
return false; // Node.js specific
|
|
123
|
+
},
|
|
124
|
+
isFloat32Array(value) {
|
|
125
|
+
return value instanceof Float32Array;
|
|
126
|
+
},
|
|
127
|
+
isFloat64Array(value) {
|
|
128
|
+
return value instanceof Float64Array;
|
|
129
|
+
},
|
|
130
|
+
isGeneratorFunction(value) {
|
|
131
|
+
return Object.prototype.toString.call(value) === '[object GeneratorFunction]';
|
|
132
|
+
},
|
|
133
|
+
isGeneratorObject(value) {
|
|
134
|
+
return Object.prototype.toString.call(value) === '[object Generator]';
|
|
135
|
+
},
|
|
136
|
+
isInt8Array(value) {
|
|
137
|
+
return value instanceof Int8Array;
|
|
138
|
+
},
|
|
139
|
+
isInt16Array(value) {
|
|
140
|
+
return value instanceof Int16Array;
|
|
141
|
+
},
|
|
142
|
+
isInt32Array(value) {
|
|
143
|
+
return value instanceof Int32Array;
|
|
144
|
+
},
|
|
145
|
+
isKeyObject(value) {
|
|
146
|
+
return false; // Node.js specific
|
|
147
|
+
},
|
|
148
|
+
isMap(value) {
|
|
149
|
+
return value instanceof Map;
|
|
150
|
+
},
|
|
151
|
+
isMapIterator(value) {
|
|
152
|
+
return Object.prototype.toString.call(value) === '[object Map Iterator]';
|
|
153
|
+
},
|
|
154
|
+
isModuleNamespaceObject(value) {
|
|
155
|
+
return Object.prototype.toString.call(value) === '[object Module]';
|
|
156
|
+
},
|
|
157
|
+
isNativeError(value) {
|
|
158
|
+
return value instanceof Error;
|
|
159
|
+
},
|
|
160
|
+
isNumberObject(value) {
|
|
161
|
+
return typeof value === 'object' && typeof value.valueOf() === 'number';
|
|
162
|
+
},
|
|
163
|
+
isPromise(value) {
|
|
164
|
+
return value instanceof Promise;
|
|
165
|
+
},
|
|
166
|
+
isProxy(value) {
|
|
167
|
+
try {
|
|
168
|
+
Proxy.revocable(value, {});
|
|
169
|
+
return true;
|
|
170
|
+
} catch (e) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
isRegExp(value) {
|
|
175
|
+
return value instanceof RegExp;
|
|
176
|
+
},
|
|
177
|
+
isSet(value) {
|
|
178
|
+
return value instanceof Set;
|
|
179
|
+
},
|
|
180
|
+
isSetIterator(value) {
|
|
181
|
+
return Object.prototype.toString.call(value) === '[object Set Iterator]';
|
|
182
|
+
},
|
|
183
|
+
isSharedArrayBuffer(value) {
|
|
184
|
+
return value instanceof SharedArrayBuffer;
|
|
185
|
+
},
|
|
186
|
+
isStringObject(value) {
|
|
187
|
+
return typeof value === 'object' && typeof value.valueOf() === 'string';
|
|
188
|
+
},
|
|
189
|
+
isSymbolObject(value) {
|
|
190
|
+
return typeof value === 'object' && typeof value.valueOf() === 'symbol';
|
|
191
|
+
},
|
|
192
|
+
isTypedArray(value) {
|
|
193
|
+
return ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
194
|
+
},
|
|
195
|
+
isUint8Array(value) {
|
|
196
|
+
return value instanceof Uint8Array;
|
|
197
|
+
},
|
|
198
|
+
isUint8ClampedArray(value) {
|
|
199
|
+
return value instanceof Uint8ClampedArray;
|
|
200
|
+
},
|
|
201
|
+
isUint16Array(value) {
|
|
202
|
+
return value instanceof Uint16Array;
|
|
203
|
+
},
|
|
204
|
+
isUint32Array(value) {
|
|
205
|
+
return value instanceof Uint32Array;
|
|
206
|
+
},
|
|
207
|
+
isWeakMap(value) {
|
|
208
|
+
return value instanceof WeakMap;
|
|
209
|
+
},
|
|
210
|
+
isWeakSet(value) {
|
|
211
|
+
return value instanceof WeakSet;
|
|
212
|
+
},
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
const util = {
|
|
217
|
+
promisify,
|
|
218
|
+
callbackify,
|
|
219
|
+
inherits,
|
|
220
|
+
deprecate,
|
|
221
|
+
types,
|
|
222
|
+
TextEncoder,
|
|
223
|
+
TextDecoder
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
globalThis.TextEncoder = TextEncoder;
|
|
227
|
+
globalThis.TextDecoder = TextDecoder;
|
|
228
|
+
|
|
229
|
+
export default util;
|
|
230
|
+
|
|
231
|
+
export { promisify, callbackify, inherits, deprecate, types, TextEncoder,TextDecoder };
|
|
232
|
+
|
|
233
|
+
`;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Scope } from 'quickjs-emscripten-core';
|
|
2
|
+
import type { CodeFunctionAsyncInput } from '../../types/CodeFunctionInput.js';
|
|
3
|
+
import type { SandboxEvalCode } from '../../types/SandboxEvalCode.js';
|
|
4
|
+
export declare const createAsyncEvalCodeFunction: (input: CodeFunctionAsyncInput, scope: Scope) => SandboxEvalCode;
|