goscript 0.0.50 → 0.0.51
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/compiler/analysis.go +18 -4
- package/compiler/compiler.go +8 -4
- package/compiler/expr-call-async.go +218 -13
- package/compiler/sanitize.go +1 -2
- package/compiler/spec-struct.go +3 -3
- package/compiler/spec.go +0 -21
- package/compiler/stmt-select.go +52 -1
- package/compiler/type.go +3 -3
- package/dist/gs/builtin/channel.d.ts +2 -2
- package/dist/gs/builtin/channel.js +12 -7
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/syscall/constants.d.ts +24 -0
- package/dist/gs/syscall/constants.js +27 -0
- package/dist/gs/syscall/constants.js.map +1 -0
- package/dist/gs/syscall/env.d.ts +6 -0
- package/dist/gs/syscall/env.js +43 -0
- package/dist/gs/syscall/env.js.map +1 -0
- package/dist/gs/syscall/errors.d.ts +111 -0
- package/dist/gs/syscall/errors.js +547 -0
- package/dist/gs/syscall/errors.js.map +1 -0
- package/dist/gs/syscall/fs.d.ts +29 -0
- package/dist/gs/syscall/fs.js +53 -0
- package/dist/gs/syscall/fs.js.map +1 -0
- package/dist/gs/syscall/index.d.ts +6 -80
- package/dist/gs/syscall/index.js +12 -168
- package/dist/gs/syscall/index.js.map +1 -1
- package/dist/gs/syscall/rawconn.d.ts +7 -0
- package/dist/gs/syscall/rawconn.js +19 -0
- package/dist/gs/syscall/rawconn.js.map +1 -0
- package/dist/gs/syscall/types.d.ts +12 -0
- package/dist/gs/syscall/types.js +2 -0
- package/dist/gs/syscall/types.js.map +1 -0
- package/gs/builtin/channel.ts +18 -12
- package/gs/syscall/constants.ts +29 -0
- package/gs/syscall/env.ts +47 -0
- package/gs/syscall/errors.ts +658 -0
- package/gs/syscall/fs.ts +62 -0
- package/gs/syscall/index.ts +12 -207
- package/gs/syscall/rawconn.ts +23 -0
- package/gs/syscall/types.ts +18 -0
- package/package.json +1 -1
|
@@ -1,80 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export declare const O_RDONLY = 0;
|
|
9
|
-
export declare const O_WRONLY = 1;
|
|
10
|
-
export declare const O_RDWR = 2;
|
|
11
|
-
export declare const O_APPEND = 8;
|
|
12
|
-
export declare const O_CREATE = 64;
|
|
13
|
-
export declare const O_EXCL = 128;
|
|
14
|
-
export declare const O_SYNC = 256;
|
|
15
|
-
export declare const O_TRUNC = 512;
|
|
16
|
-
export declare const Stdin = 0;
|
|
17
|
-
export declare const Stdout = 1;
|
|
18
|
-
export declare const Stderr = 2;
|
|
19
|
-
export declare const SIGINT = 2;
|
|
20
|
-
export declare const SIGTERM = 15;
|
|
21
|
-
export declare const S_IFMT = 61440;
|
|
22
|
-
export declare const S_IFREG = 32768;
|
|
23
|
-
export declare const S_IFDIR = 16384;
|
|
24
|
-
export declare const S_IFLNK = 40960;
|
|
25
|
-
export declare const S_IFBLK = 24576;
|
|
26
|
-
export declare const S_IFCHR = 8192;
|
|
27
|
-
export declare const S_IFIFO = 4096;
|
|
28
|
-
export declare const S_IFSOCK = 49152;
|
|
29
|
-
export declare const S_ISUID = 2048;
|
|
30
|
-
export declare const S_ISGID = 1024;
|
|
31
|
-
export declare const S_ISVTX = 512;
|
|
32
|
-
export declare function Getenv(key: string): [string, boolean];
|
|
33
|
-
export declare function Setenv(key: string, value: string): $.GoError;
|
|
34
|
-
export declare function Unsetenv(key: string): $.GoError;
|
|
35
|
-
export declare function Clearenv(): void;
|
|
36
|
-
export declare function Environ(): $.Slice<string>;
|
|
37
|
-
export declare class Dirent {
|
|
38
|
-
Name: $.Bytes;
|
|
39
|
-
Reclen: number;
|
|
40
|
-
constructor(init?: any);
|
|
41
|
-
}
|
|
42
|
-
export declare class Stat_t {
|
|
43
|
-
Dev: number;
|
|
44
|
-
Ino: number;
|
|
45
|
-
Mode: number;
|
|
46
|
-
Nlink: number;
|
|
47
|
-
Uid: number;
|
|
48
|
-
Gid: number;
|
|
49
|
-
Rdev: number;
|
|
50
|
-
Size: number;
|
|
51
|
-
Blksize: number;
|
|
52
|
-
Blocks: number;
|
|
53
|
-
Atime: number;
|
|
54
|
-
Mtime: number;
|
|
55
|
-
Ctime: number;
|
|
56
|
-
AtimeNsec: number;
|
|
57
|
-
MtimeNsec: number;
|
|
58
|
-
CtimeNsec: number;
|
|
59
|
-
constructor(init?: any);
|
|
60
|
-
clone(): Stat_t;
|
|
61
|
-
}
|
|
62
|
-
export interface RawConn {
|
|
63
|
-
Control(f: (fd: uintptr) => void): $.GoError;
|
|
64
|
-
Read(f: (fd: uintptr) => boolean): $.GoError;
|
|
65
|
-
Write(f: (fd: uintptr) => boolean): $.GoError;
|
|
66
|
-
}
|
|
67
|
-
export declare class StubRawConn implements RawConn {
|
|
68
|
-
Control(_f: (fd: uintptr) => void): $.GoError;
|
|
69
|
-
Read(_f: (fd: uintptr) => boolean): $.GoError;
|
|
70
|
-
Write(_f: (fd: uintptr) => boolean): $.GoError;
|
|
71
|
-
}
|
|
72
|
-
export declare const ENOSYS: Errno;
|
|
73
|
-
export declare const EISDIR: Errno;
|
|
74
|
-
export declare const ENOTDIR: Errno;
|
|
75
|
-
export declare const ERANGE: Errno;
|
|
76
|
-
export declare const ENOMEM: Errno;
|
|
77
|
-
export declare const ESRCH: Errno;
|
|
78
|
-
export declare function Open(_path: string, _flag: number, _perm: number): [number, $.GoError];
|
|
79
|
-
export declare function Sysctl(_name: string): [string, $.GoError];
|
|
80
|
-
export declare function Getpagesize(): number;
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './constants.js';
|
|
3
|
+
export * from './env.js';
|
|
4
|
+
export * from './fs.js';
|
|
5
|
+
export * from './errors.js';
|
|
6
|
+
export * from './rawconn.js';
|
package/dist/gs/syscall/index.js
CHANGED
|
@@ -1,169 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export const Stderr = 2;
|
|
14
|
-
export const SIGINT = 2;
|
|
15
|
-
export const SIGTERM = 15;
|
|
16
|
-
// File mode constants
|
|
17
|
-
export const S_IFMT = 0o170000;
|
|
18
|
-
export const S_IFREG = 0o100000;
|
|
19
|
-
export const S_IFDIR = 0o040000;
|
|
20
|
-
export const S_IFLNK = 0o120000;
|
|
21
|
-
export const S_IFBLK = 0o060000;
|
|
22
|
-
export const S_IFCHR = 0o020000;
|
|
23
|
-
export const S_IFIFO = 0o010000;
|
|
24
|
-
export const S_IFSOCK = 0o140000;
|
|
25
|
-
export const S_ISUID = 0o004000;
|
|
26
|
-
export const S_ISGID = 0o002000;
|
|
27
|
-
export const S_ISVTX = 0o001000;
|
|
28
|
-
// Environment variable functions using Node.js/browser APIs
|
|
29
|
-
export function Getenv(key) {
|
|
30
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
31
|
-
const value = process.env[key];
|
|
32
|
-
return value !== undefined ? [value, true] : ['', false];
|
|
33
|
-
}
|
|
34
|
-
return ['', false];
|
|
35
|
-
}
|
|
36
|
-
export function Setenv(key, value) {
|
|
37
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
38
|
-
process.env[key] = value;
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
return { Error: () => 'setenv not supported' };
|
|
42
|
-
}
|
|
43
|
-
export function Unsetenv(key) {
|
|
44
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
45
|
-
delete process.env[key];
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
return { Error: () => 'unsetenv not supported' };
|
|
49
|
-
}
|
|
50
|
-
export function Clearenv() {
|
|
51
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
52
|
-
for (const key in process.env) {
|
|
53
|
-
delete process.env[key];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export function Environ() {
|
|
58
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
59
|
-
const env = [];
|
|
60
|
-
for (const [key, value] of Object.entries(process.env)) {
|
|
61
|
-
if (value !== undefined) {
|
|
62
|
-
env.push(`${key}=${value}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return $.arrayToSlice(env);
|
|
66
|
-
}
|
|
67
|
-
return $.arrayToSlice([]);
|
|
68
|
-
}
|
|
69
|
-
// Dirent structure with Reclen field
|
|
70
|
-
export class Dirent {
|
|
71
|
-
Name = new Uint8Array(0);
|
|
72
|
-
Reclen = 0;
|
|
73
|
-
constructor(init) {
|
|
74
|
-
if (init?.Name)
|
|
75
|
-
this.Name = init.Name;
|
|
76
|
-
if (init?.Reclen)
|
|
77
|
-
this.Reclen = init.Reclen;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Stat_t structure stub
|
|
81
|
-
export class Stat_t {
|
|
82
|
-
Dev = 0;
|
|
83
|
-
Ino = 0;
|
|
84
|
-
Mode = 0;
|
|
85
|
-
Nlink = 0;
|
|
86
|
-
Uid = 0;
|
|
87
|
-
Gid = 0;
|
|
88
|
-
Rdev = 0;
|
|
89
|
-
Size = 0;
|
|
90
|
-
Blksize = 0;
|
|
91
|
-
Blocks = 0;
|
|
92
|
-
Atime = 0;
|
|
93
|
-
Mtime = 0;
|
|
94
|
-
Ctime = 0;
|
|
95
|
-
AtimeNsec = 0;
|
|
96
|
-
MtimeNsec = 0;
|
|
97
|
-
CtimeNsec = 0;
|
|
98
|
-
constructor(init) {
|
|
99
|
-
if (init) {
|
|
100
|
-
Object.assign(this, init);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
clone() {
|
|
104
|
-
return new Stat_t(this);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
// Stub implementation of RawConn that always returns ErrUnimplemented
|
|
108
|
-
export class StubRawConn {
|
|
109
|
-
Control(_f) {
|
|
110
|
-
return {
|
|
111
|
-
Error: () => 'operation not implemented in JavaScript environment',
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
Read(_f) {
|
|
115
|
-
return {
|
|
116
|
-
Error: () => 'operation not implemented in JavaScript environment',
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
Write(_f) {
|
|
120
|
-
return {
|
|
121
|
-
Error: () => 'operation not implemented in JavaScript environment',
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// Additional error constants - implement as Errno type
|
|
126
|
-
export const ENOSYS = {
|
|
127
|
-
Error: () => 'function not implemented',
|
|
128
|
-
Is: (target) => target === ENOSYS,
|
|
129
|
-
Errno: () => 38,
|
|
130
|
-
};
|
|
131
|
-
export const EISDIR = {
|
|
132
|
-
Error: () => 'is a directory',
|
|
133
|
-
Is: (target) => target === EISDIR,
|
|
134
|
-
Errno: () => 21,
|
|
135
|
-
};
|
|
136
|
-
export const ENOTDIR = {
|
|
137
|
-
Error: () => 'not a directory',
|
|
138
|
-
Is: (target) => target === ENOTDIR,
|
|
139
|
-
Errno: () => 20,
|
|
140
|
-
};
|
|
141
|
-
export const ERANGE = {
|
|
142
|
-
Error: () => 'result too large',
|
|
143
|
-
Is: (target) => target === ERANGE,
|
|
144
|
-
Errno: () => 34,
|
|
145
|
-
};
|
|
146
|
-
export const ENOMEM = {
|
|
147
|
-
Error: () => 'out of memory',
|
|
148
|
-
Is: (target) => target === ENOMEM,
|
|
149
|
-
Errno: () => 12,
|
|
150
|
-
};
|
|
151
|
-
export const ESRCH = {
|
|
152
|
-
Error: () => 'no such process',
|
|
153
|
-
Is: (target) => target === ESRCH,
|
|
154
|
-
Errno: () => 3,
|
|
155
|
-
};
|
|
156
|
-
// Additional missing syscall functions
|
|
157
|
-
export function Open(_path, _flag, _perm) {
|
|
158
|
-
return [-1, ENOSYS];
|
|
159
|
-
}
|
|
160
|
-
export function Sysctl(_name) {
|
|
161
|
-
return ['', ENOSYS];
|
|
162
|
-
}
|
|
163
|
-
// Getpagesize returns the underlying system's memory page size.
|
|
164
|
-
export function Getpagesize() {
|
|
165
|
-
// Return a standard page size for JavaScript environment
|
|
166
|
-
// Most systems use 4096 bytes as the default page size
|
|
167
|
-
return 4096;
|
|
168
|
-
}
|
|
1
|
+
// Re-export all types
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
// Re-export all constants
|
|
4
|
+
export * from './constants.js';
|
|
5
|
+
// Re-export environment functions
|
|
6
|
+
export * from './env.js';
|
|
7
|
+
// Re-export file system structures and functions
|
|
8
|
+
export * from './fs.js';
|
|
9
|
+
// Re-export error constants
|
|
10
|
+
export * from './errors.js';
|
|
11
|
+
// Re-export RawConn implementation
|
|
12
|
+
export * from './rawconn.js';
|
|
169
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../gs/syscall/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../gs/syscall/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,cAAc,YAAY,CAAA;AAE1B,0BAA0B;AAC1B,cAAc,gBAAgB,CAAA;AAE9B,kCAAkC;AAClC,cAAc,UAAU,CAAA;AAExB,iDAAiD;AACjD,cAAc,SAAS,CAAA;AAEvB,4BAA4B;AAC5B,cAAc,aAAa,CAAA;AAE3B,mCAAmC;AACnC,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js';
|
|
2
|
+
import { RawConn, uintptr } from './types.js';
|
|
3
|
+
export declare class StubRawConn implements RawConn {
|
|
4
|
+
Control(_f: (fd: uintptr) => void): $.GoError;
|
|
5
|
+
Read(_f: (fd: uintptr) => boolean): $.GoError;
|
|
6
|
+
Write(_f: (fd: uintptr) => boolean): $.GoError;
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Stub implementation of RawConn that always returns ErrUnimplemented
|
|
2
|
+
export class StubRawConn {
|
|
3
|
+
Control(_f) {
|
|
4
|
+
return {
|
|
5
|
+
Error: () => 'operation not implemented in JavaScript environment',
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
Read(_f) {
|
|
9
|
+
return {
|
|
10
|
+
Error: () => 'operation not implemented in JavaScript environment',
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
Write(_f) {
|
|
14
|
+
return {
|
|
15
|
+
Error: () => 'operation not implemented in JavaScript environment',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=rawconn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rawconn.js","sourceRoot":"","sources":["../../../gs/syscall/rawconn.ts"],"names":[],"mappings":"AAGA,sEAAsE;AACtE,MAAM,OAAO,WAAW;IACtB,OAAO,CAAC,EAAyB;QAC/B,OAAO;YACL,KAAK,EAAE,GAAG,EAAE,CAAC,qDAAqD;SACnE,CAAA;IACH,CAAC;IAED,IAAI,CAAC,EAA4B;QAC/B,OAAO;YACL,KAAK,EAAE,GAAG,EAAE,CAAC,qDAAqD;SACnE,CAAA;IACH,CAAC;IAED,KAAK,CAAC,EAA4B;QAChC,OAAO;YACL,KAAK,EAAE,GAAG,EAAE,CAAC,qDAAqD;SACnE,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js';
|
|
2
|
+
export type uintptr = number;
|
|
3
|
+
export interface Errno {
|
|
4
|
+
Error(): string;
|
|
5
|
+
Is(target: $.GoError): boolean;
|
|
6
|
+
Errno(): number;
|
|
7
|
+
}
|
|
8
|
+
export interface RawConn {
|
|
9
|
+
Control(f: (fd: uintptr) => void): $.GoError;
|
|
10
|
+
Read(f: (fd: uintptr) => boolean): $.GoError;
|
|
11
|
+
Write(f: (fd: uintptr) => boolean): $.GoError;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../gs/syscall/types.ts"],"names":[],"mappings":""}
|
package/gs/builtin/channel.ts
CHANGED
|
@@ -88,7 +88,7 @@ export interface SelectCase<T> {
|
|
|
88
88
|
channel: Channel<any> | ChannelRef<any> | null // Allow null and ChannelRef
|
|
89
89
|
value?: any // Value to send for send cases
|
|
90
90
|
// Optional handlers for when this case is selected
|
|
91
|
-
onSelected?: (result: SelectResult<T>) => Promise<
|
|
91
|
+
onSelected?: (result: SelectResult<T>) => Promise<any>
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
@@ -99,14 +99,14 @@ export interface SelectCase<T> {
|
|
|
99
99
|
* @param hasDefault Whether there is a default case
|
|
100
100
|
* @returns A promise that resolves with the result of the selected case
|
|
101
101
|
*/
|
|
102
|
-
export async function selectStatement<T>(
|
|
102
|
+
export async function selectStatement<T, V=void>(
|
|
103
103
|
cases: SelectCase<T>[],
|
|
104
104
|
hasDefault: boolean = false,
|
|
105
|
-
): Promise<
|
|
105
|
+
): Promise<[boolean, V]> {
|
|
106
106
|
if (cases.length === 0 && !hasDefault) {
|
|
107
107
|
// Go spec: If there are no cases, the select statement blocks forever.
|
|
108
108
|
// Emulate blocking forever with a promise that never resolves.
|
|
109
|
-
return new Promise<
|
|
109
|
+
return new Promise<[boolean, V]>(() => {}) // Promise never resolves
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
// 1. Check for ready (non-blocking) operations
|
|
@@ -143,19 +143,21 @@ export async function selectStatement<T>(
|
|
|
143
143
|
selectedCase.id,
|
|
144
144
|
)
|
|
145
145
|
if (selectedCase.onSelected) {
|
|
146
|
-
await selectedCase.onSelected(result as SelectResult<T>)
|
|
146
|
+
const handlerResult = await selectedCase.onSelected(result as SelectResult<T>)
|
|
147
|
+
return [handlerResult !== undefined, handlerResult as V]
|
|
147
148
|
}
|
|
148
149
|
} else {
|
|
149
150
|
const result = await selectedCase.channel.selectReceive(selectedCase.id)
|
|
150
151
|
if (selectedCase.onSelected) {
|
|
151
|
-
await selectedCase.onSelected(result)
|
|
152
|
+
const handlerResult = await selectedCase.onSelected(result)
|
|
153
|
+
return [handlerResult !== undefined, handlerResult as V]
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
156
|
} else {
|
|
155
157
|
// This case should ideally not happen if channel is required for non-default cases
|
|
156
158
|
console.error('Selected case without a channel:', selectedCase)
|
|
157
159
|
}
|
|
158
|
-
return // Return after executing a ready case
|
|
160
|
+
return [false, undefined as V] // Return after executing a ready case
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
// 2. If no operations are ready and there's a default case, select default
|
|
@@ -164,13 +166,14 @@ export async function selectStatement<T>(
|
|
|
164
166
|
const defaultCase = cases.find((c) => c.id === -1)
|
|
165
167
|
if (defaultCase && defaultCase.onSelected) {
|
|
166
168
|
// Execute the onSelected handler for the default case
|
|
167
|
-
await defaultCase.onSelected({
|
|
169
|
+
const handlerResult = await defaultCase.onSelected({
|
|
168
170
|
value: undefined,
|
|
169
171
|
ok: false,
|
|
170
172
|
id: -1,
|
|
171
|
-
} as SelectResult<T>)
|
|
173
|
+
} as SelectResult<T>)
|
|
174
|
+
return [handlerResult !== undefined, handlerResult as V]
|
|
172
175
|
}
|
|
173
|
-
return // Return after executing the default case
|
|
176
|
+
return [false, undefined as V] // Return after executing the default case
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
// 3. If no operations are ready and no default case, block until one is ready
|
|
@@ -190,16 +193,19 @@ export async function selectStatement<T>(
|
|
|
190
193
|
// If all non-default cases have nil channels, we effectively block forever
|
|
191
194
|
if (blockingPromises.length === 0) {
|
|
192
195
|
// No valid channels to operate on, block forever (unless there's a default)
|
|
193
|
-
return new Promise<
|
|
196
|
+
return new Promise<[boolean, V]>(() => {}) // Promise never resolves
|
|
194
197
|
}
|
|
195
198
|
|
|
196
199
|
const result = await Promise.race(blockingPromises)
|
|
197
200
|
// Execute onSelected handler for the selected case
|
|
198
201
|
const selectedCase = cases.find((c) => c.id === result.id)
|
|
199
202
|
if (selectedCase && selectedCase.onSelected) {
|
|
200
|
-
await selectedCase.onSelected(result)
|
|
203
|
+
const handlerResult = await selectedCase.onSelected(result)
|
|
204
|
+
return [handlerResult !== undefined, handlerResult as V]
|
|
201
205
|
}
|
|
206
|
+
|
|
202
207
|
// No explicit return needed here, as the function will implicitly return after the await
|
|
208
|
+
return [false, undefined as V]
|
|
203
209
|
}
|
|
204
210
|
|
|
205
211
|
/**
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Essential syscall constants
|
|
2
|
+
export const O_RDONLY = 0
|
|
3
|
+
export const O_WRONLY = 1
|
|
4
|
+
export const O_RDWR = 2
|
|
5
|
+
export const O_APPEND = 8
|
|
6
|
+
export const O_CREATE = 64
|
|
7
|
+
export const O_EXCL = 128
|
|
8
|
+
export const O_SYNC = 256
|
|
9
|
+
export const O_TRUNC = 512
|
|
10
|
+
|
|
11
|
+
export const Stdin = 0
|
|
12
|
+
export const Stdout = 1
|
|
13
|
+
export const Stderr = 2
|
|
14
|
+
|
|
15
|
+
export const SIGINT = 2
|
|
16
|
+
export const SIGTERM = 15
|
|
17
|
+
|
|
18
|
+
// File mode constants
|
|
19
|
+
export const S_IFMT = 0o170000
|
|
20
|
+
export const S_IFREG = 0o100000
|
|
21
|
+
export const S_IFDIR = 0o040000
|
|
22
|
+
export const S_IFLNK = 0o120000
|
|
23
|
+
export const S_IFBLK = 0o060000
|
|
24
|
+
export const S_IFCHR = 0o020000
|
|
25
|
+
export const S_IFIFO = 0o010000
|
|
26
|
+
export const S_IFSOCK = 0o140000
|
|
27
|
+
export const S_ISUID = 0o004000
|
|
28
|
+
export const S_ISGID = 0o002000
|
|
29
|
+
export const S_ISVTX = 0o001000
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
|
|
3
|
+
// Environment variable functions using Node.js/browser APIs
|
|
4
|
+
export function Getenv(key: string): [string, boolean] {
|
|
5
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
6
|
+
const value = process.env[key]
|
|
7
|
+
return value !== undefined ? [value, true] : ['', false]
|
|
8
|
+
}
|
|
9
|
+
return ['', false]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function Setenv(key: string, value: string): $.GoError {
|
|
13
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
14
|
+
process.env[key] = value
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
return { Error: () => 'setenv not supported' }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function Unsetenv(key: string): $.GoError {
|
|
21
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
22
|
+
delete process.env[key]
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
return { Error: () => 'unsetenv not supported' }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function Clearenv(): void {
|
|
29
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
30
|
+
for (const key in process.env) {
|
|
31
|
+
delete process.env[key]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function Environ(): $.Slice<string> {
|
|
37
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
38
|
+
const env: string[] = []
|
|
39
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
40
|
+
if (value !== undefined) {
|
|
41
|
+
env.push(`${key}=${value}`)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return $.arrayToSlice(env)
|
|
45
|
+
}
|
|
46
|
+
return $.arrayToSlice([])
|
|
47
|
+
}
|