disruption
This commit is contained in:
@@ -554,6 +554,7 @@ load_log_config()
|
||||
log = function(name, args) {
|
||||
var sinks = channel_sinks[name]
|
||||
var event = args[0]
|
||||
var c_stack = args[1]
|
||||
var caller = null
|
||||
var stack = null
|
||||
var rec = null
|
||||
@@ -566,8 +567,15 @@ log = function(name, args) {
|
||||
return
|
||||
}
|
||||
|
||||
caller = caller_info(2)
|
||||
if (stack_channels[name]) stack = os.stack(1)
|
||||
// C-provided stack (from JS_Log callback) overrides caller_info/os.stack
|
||||
if (c_stack && length(c_stack) > 0) {
|
||||
caller = {file: c_stack[0].file, line: c_stack[0].line}
|
||||
if (stack_channels[name]) stack = c_stack
|
||||
} else {
|
||||
caller = caller_info(2)
|
||||
if (stack_channels[name]) stack = os.stack(1)
|
||||
}
|
||||
|
||||
rec = {
|
||||
actor_id: _cell.id,
|
||||
timestamp: time.number(),
|
||||
@@ -581,6 +589,9 @@ log = function(name, args) {
|
||||
arrfor(wildcard_sinks, function(sink) { dispatch_to_sink(sink, rec) })
|
||||
}
|
||||
|
||||
// Wire C-level JS_Log through the ƿit log system
|
||||
actor_mod.set_log(log)
|
||||
|
||||
var pronto = use_core('pronto')
|
||||
var fallback = pronto.fallback
|
||||
var parallel = pronto.parallel
|
||||
|
||||
@@ -31,7 +31,7 @@ static int js2fd(JSContext *ctx, JSValueConst val)
|
||||
{
|
||||
int fd;
|
||||
if (JS_ToInt32(ctx, &fd, val) < 0) {
|
||||
JS_ThrowTypeError(ctx, "Expected file descriptor number");
|
||||
JS_RaiseDisrupt(ctx, "Expected file descriptor number");
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
@@ -67,7 +67,7 @@ JSC_SCALL(fd_open,
|
||||
|
||||
int fd = open(str, flags, mode);
|
||||
if (fd < 0)
|
||||
ret = JS_ThrowInternalError(js, "open failed: %s", strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "open failed: %s", strerror(errno));
|
||||
else
|
||||
ret = JS_NewInt32(js, fd);
|
||||
)
|
||||
@@ -103,12 +103,12 @@ JSC_CCALL(fd_read,
|
||||
|
||||
void *buf = malloc(size);
|
||||
if (!buf)
|
||||
return JS_ThrowInternalError(js, "malloc failed");
|
||||
return JS_RaiseDisrupt(js, "malloc failed");
|
||||
|
||||
ssize_t bytes_read = read(fd, buf, size);
|
||||
if (bytes_read < 0) {
|
||||
free(buf);
|
||||
return JS_ThrowInternalError(js, "read failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "read failed: %s", strerror(errno));
|
||||
}
|
||||
|
||||
ret = js_new_blob_stoned_copy(js, buf, bytes_read);
|
||||
@@ -119,10 +119,10 @@ JSC_CCALL(fd_read,
|
||||
JSC_SCALL(fd_slurp,
|
||||
struct stat st;
|
||||
if (stat(str, &st) != 0)
|
||||
return JS_ThrowInternalError(js, "stat failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "stat failed: %s", strerror(errno));
|
||||
|
||||
if (!S_ISREG(st.st_mode))
|
||||
return JS_ThrowTypeError(js, "path is not a regular file");
|
||||
return JS_RaiseDisrupt(js, "path is not a regular file");
|
||||
|
||||
size_t size = st.st_size;
|
||||
if (size == 0)
|
||||
@@ -131,12 +131,12 @@ JSC_SCALL(fd_slurp,
|
||||
#ifndef _WIN32
|
||||
int fd = open(str, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return JS_ThrowInternalError(js, "open failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "open failed: %s", strerror(errno));
|
||||
|
||||
void *data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (data == MAP_FAILED) {
|
||||
close(fd);
|
||||
return JS_ThrowInternalError(js, "mmap failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "mmap failed: %s", strerror(errno));
|
||||
}
|
||||
ret = js_new_blob_stoned_copy(js, data, size);
|
||||
munmap(data, size);
|
||||
@@ -145,19 +145,19 @@ JSC_SCALL(fd_slurp,
|
||||
// Windows: use memory mapping for optimal performance
|
||||
HANDLE hFile = CreateFileA(str, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
return JS_ThrowInternalError(js, "CreateFile failed: %lu", GetLastError());
|
||||
return JS_RaiseDisrupt(js, "CreateFile failed: %lu", GetLastError());
|
||||
|
||||
HANDLE hMapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
if (hMapping == NULL) {
|
||||
CloseHandle(hFile);
|
||||
return JS_ThrowInternalError(js, "CreateFileMapping failed: %lu", GetLastError());
|
||||
return JS_RaiseDisrupt(js, "CreateFileMapping failed: %lu", GetLastError());
|
||||
}
|
||||
|
||||
void *data = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
|
||||
if (data == NULL) {
|
||||
CloseHandle(hMapping);
|
||||
CloseHandle(hFile);
|
||||
return JS_ThrowInternalError(js, "MapViewOfFile failed: %lu", GetLastError());
|
||||
return JS_RaiseDisrupt(js, "MapViewOfFile failed: %lu", GetLastError());
|
||||
}
|
||||
|
||||
ret = js_new_blob_stoned_copy(js, data, size);
|
||||
@@ -183,7 +183,7 @@ JSC_CCALL(fd_lseek,
|
||||
|
||||
off_t new_pos = lseek(fd, offset, whence);
|
||||
if (new_pos < 0)
|
||||
return JS_ThrowInternalError(js, "lseek failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "lseek failed: %s", strerror(errno));
|
||||
|
||||
return JS_NewInt64(js, new_pos);
|
||||
)
|
||||
@@ -191,7 +191,7 @@ JSC_CCALL(fd_lseek,
|
||||
JSC_CCALL(fd_getcwd,
|
||||
char buf[PATH_MAX];
|
||||
if (getcwd(buf, sizeof(buf)) == NULL)
|
||||
return JS_ThrowInternalError(js, "getcwd failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "getcwd failed: %s", strerror(errno));
|
||||
return JS_NewString(js, buf);
|
||||
)
|
||||
|
||||
@@ -225,7 +225,7 @@ JSC_SCALL(fd_rmdir,
|
||||
} else {
|
||||
if (unlink(full_path) != 0) {
|
||||
FindClose(hFind);
|
||||
ret = JS_ThrowInternalError(js, "could not remove file %s: %s", full_path, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "could not remove file %s: %s", full_path, strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ JSC_SCALL(fd_rmdir,
|
||||
} else {
|
||||
if (unlink(full_path) != 0) {
|
||||
closedir(dir);
|
||||
ret = JS_ThrowInternalError(js, "could not remove file %s: %s", full_path, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "could not remove file %s: %s", full_path, strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -265,44 +265,44 @@ JSC_SCALL(fd_rmdir,
|
||||
}
|
||||
|
||||
if (rmdir(str) != 0)
|
||||
ret = JS_ThrowInternalError(js, "could not remove directory %s: %s", str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "could not remove directory %s: %s", str, strerror(errno));
|
||||
)
|
||||
|
||||
JSC_SCALL(fd_mkdir,
|
||||
if (mkdir(str, 0755) != 0)
|
||||
ret = JS_ThrowInternalError(js, "could not make directory %s: %s", str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "could not make directory %s: %s", str, strerror(errno));
|
||||
)
|
||||
|
||||
JSC_SCALL(fd_mv,
|
||||
if (argc < 2)
|
||||
ret = JS_ThrowTypeError(js, "fd.mv requires 2 arguments: old path and new path");
|
||||
ret = JS_RaiseDisrupt(js, "fd.mv requires 2 arguments: old path and new path");
|
||||
else if (!JS_IsText(argv[1]))
|
||||
ret = JS_ThrowTypeError(js, "second argument must be a string (new path)");
|
||||
ret = JS_RaiseDisrupt(js, "second argument must be a string (new path)");
|
||||
else {
|
||||
const char *new_path = JS_ToCString(js, argv[1]);
|
||||
if (rename(str, new_path) != 0)
|
||||
ret = JS_ThrowInternalError(js, "could not rename %s to %s: %s", str, new_path, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "could not rename %s to %s: %s", str, new_path, strerror(errno));
|
||||
JS_FreeCString(js, new_path);
|
||||
}
|
||||
)
|
||||
|
||||
JSC_SCALL(fd_symlink,
|
||||
if (argc < 2)
|
||||
ret = JS_ThrowTypeError(js, "fd.symlink requires 2 arguments: target and link path");
|
||||
ret = JS_RaiseDisrupt(js, "fd.symlink requires 2 arguments: target and link path");
|
||||
else if (!JS_IsText(argv[1]))
|
||||
ret = JS_ThrowTypeError(js, "second argument must be a string (link path)");
|
||||
ret = JS_RaiseDisrupt(js, "second argument must be a string (link path)");
|
||||
else {
|
||||
const char *link_path = JS_ToCString(js, argv[1]);
|
||||
#ifdef _WIN32
|
||||
if (!CreateSymbolicLinkA(link_path, str, SYMBOLIC_LINK_FLAG_DIRECTORY)) {
|
||||
// Try file
|
||||
if (!CreateSymbolicLinkA(link_path, str, 0)) {
|
||||
ret = JS_ThrowInternalError(js, "could not create symlink %s -> %s: %lu", link_path, str, GetLastError());
|
||||
ret = JS_RaiseDisrupt(js, "could not create symlink %s -> %s: %lu", link_path, str, GetLastError());
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (symlink(str, link_path) != 0)
|
||||
ret = JS_ThrowInternalError(js, "could not create symlink %s -> %s: %s", link_path, str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "could not create symlink %s -> %s: %s", link_path, str, strerror(errno));
|
||||
#endif
|
||||
JS_FreeCString(js, link_path);
|
||||
}
|
||||
@@ -320,14 +320,14 @@ JSC_SCALL(fd_unlink,
|
||||
if (err == ERROR_ACCESS_DENIED) {
|
||||
// Might be a directory, try RemoveDirectory
|
||||
if (!RemoveDirectoryA(str))
|
||||
ret = JS_ThrowInternalError(js, "could not remove %s: error %lu", str, GetLastError());
|
||||
ret = JS_RaiseDisrupt(js, "could not remove %s: error %lu", str, GetLastError());
|
||||
} else {
|
||||
ret = JS_ThrowInternalError(js, "could not remove file %s: error %lu", str, err);
|
||||
ret = JS_RaiseDisrupt(js, "could not remove file %s: error %lu", str, err);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (unlink(str) != 0)
|
||||
ret = JS_ThrowInternalError(js, "could not remove file %s: %s", str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "could not remove file %s: %s", str, strerror(errno));
|
||||
#endif
|
||||
)
|
||||
|
||||
@@ -386,7 +386,7 @@ static int remove_recursive(const char *path) {
|
||||
|
||||
JSC_SCALL(fd_rm,
|
||||
if (remove_recursive(str) != 0)
|
||||
ret = JS_ThrowInternalError(js, "could not remove %s: %s", str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "could not remove %s: %s", str, strerror(errno));
|
||||
)
|
||||
|
||||
JSC_CCALL(fd_fsync,
|
||||
@@ -394,7 +394,7 @@ JSC_CCALL(fd_fsync,
|
||||
if (fd < 0) return JS_EXCEPTION;
|
||||
|
||||
if (fsync(fd) != 0)
|
||||
return JS_ThrowInternalError(js, "fsync failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "fsync failed: %s", strerror(errno));
|
||||
|
||||
return JS_NULL;
|
||||
)
|
||||
@@ -404,7 +404,7 @@ JSC_CCALL(fd_close,
|
||||
if (fd < 0) return JS_EXCEPTION;
|
||||
|
||||
if (close(fd) != 0)
|
||||
return JS_ThrowInternalError(js, "close failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "close failed: %s", strerror(errno));
|
||||
|
||||
return JS_NULL;
|
||||
)
|
||||
@@ -415,7 +415,7 @@ JSC_CCALL(fd_fstat,
|
||||
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) != 0)
|
||||
return JS_ThrowInternalError(js, "fstat failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "fstat failed: %s", strerror(errno));
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_ROOT(obj, JS_NewObject(js));
|
||||
@@ -496,7 +496,7 @@ JSC_SCALL(fd_readdir,
|
||||
snprintf(path, sizeof(path), "%s\\*", str);
|
||||
HANDLE hFind = FindFirstFile(path, &ffd);
|
||||
if (hFind == INVALID_HANDLE_VALUE) {
|
||||
ret = JS_ThrowInternalError(js, "FindFirstFile failed for %s", path);
|
||||
ret = JS_RaiseDisrupt(js, "FindFirstFile failed for %s", path);
|
||||
} else {
|
||||
JS_ROOT(arr, JS_NewArray(js));
|
||||
do {
|
||||
@@ -519,7 +519,7 @@ JSC_SCALL(fd_readdir,
|
||||
closedir(d);
|
||||
ret = arr.val;
|
||||
} else {
|
||||
ret = JS_ThrowInternalError(js, "opendir failed for %s: %s", str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "opendir failed for %s: %s", str, strerror(errno));
|
||||
}
|
||||
#endif
|
||||
JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame);
|
||||
@@ -565,7 +565,7 @@ JSC_CCALL(fd_slurpwrite,
|
||||
if (!str) return JS_EXCEPTION;
|
||||
int fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if (fd < 0) {
|
||||
ret = JS_ThrowInternalError(js, "open failed for %s: %s", str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "open failed for %s: %s", str, strerror(errno));
|
||||
JS_FreeCString(js, str);
|
||||
return ret;
|
||||
}
|
||||
@@ -574,7 +574,7 @@ JSC_CCALL(fd_slurpwrite,
|
||||
close(fd);
|
||||
|
||||
if (written != (ssize_t)len) {
|
||||
ret = JS_ThrowInternalError(js, "write failed for %s: %s", str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "write failed for %s: %s", str, strerror(errno));
|
||||
JS_FreeCString(js, str);
|
||||
return ret;
|
||||
}
|
||||
@@ -596,7 +596,7 @@ JSC_CCALL(fd_slurpappend,
|
||||
if (!str) return JS_EXCEPTION;
|
||||
int fd = open(str, O_WRONLY | O_CREAT | O_APPEND, 0644);
|
||||
if (fd < 0) {
|
||||
ret = JS_ThrowInternalError(js, "open failed for %s: %s", str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "open failed for %s: %s", str, strerror(errno));
|
||||
JS_FreeCString(js, str);
|
||||
return ret;
|
||||
}
|
||||
@@ -605,7 +605,7 @@ JSC_CCALL(fd_slurpappend,
|
||||
close(fd);
|
||||
|
||||
if (written != (ssize_t)len) {
|
||||
ret = JS_ThrowInternalError(js, "write failed for %s: %s", str, strerror(errno));
|
||||
ret = JS_RaiseDisrupt(js, "write failed for %s: %s", str, strerror(errno));
|
||||
JS_FreeCString(js, str);
|
||||
return ret;
|
||||
}
|
||||
@@ -702,7 +702,7 @@ JSC_CCALL(fd_realpath,
|
||||
char resolved[PATH_MAX];
|
||||
DWORD len = GetFullPathNameA(path, PATH_MAX, resolved, NULL);
|
||||
if (len == 0 || len >= PATH_MAX) {
|
||||
JSValue err = JS_ThrowInternalError(js, "realpath failed for %s: %s", path, strerror(errno));
|
||||
JSValue err = JS_RaiseDisrupt(js, "realpath failed for %s: %s", path, strerror(errno));
|
||||
JS_FreeCString(js, path);
|
||||
return err;
|
||||
}
|
||||
@@ -711,7 +711,7 @@ JSC_CCALL(fd_realpath,
|
||||
#else
|
||||
char *resolved = realpath(path, NULL);
|
||||
if (!resolved) {
|
||||
JSValue err = JS_ThrowInternalError(js, "realpath failed for %s: %s", path, strerror(errno));
|
||||
JSValue err = JS_RaiseDisrupt(js, "realpath failed for %s: %s", path, strerror(errno));
|
||||
JS_FreeCString(js, path);
|
||||
return err;
|
||||
}
|
||||
@@ -745,13 +745,13 @@ JSC_CCALL(fd_readlink,
|
||||
|
||||
#ifdef _WIN32
|
||||
JS_FreeCString(js, path);
|
||||
return JS_ThrowInternalError(js, "readlink not supported on Windows");
|
||||
return JS_RaiseDisrupt(js, "readlink not supported on Windows");
|
||||
#else
|
||||
char buf[PATH_MAX];
|
||||
ssize_t len = readlink(path, buf, sizeof(buf) - 1);
|
||||
JS_FreeCString(js, path);
|
||||
if (len < 0) {
|
||||
return JS_ThrowInternalError(js, "readlink failed: %s", strerror(errno));
|
||||
return JS_RaiseDisrupt(js, "readlink failed: %s", strerror(errno));
|
||||
}
|
||||
buf[len] = '\0';
|
||||
return JS_NewString(js, buf);
|
||||
|
||||
@@ -98,7 +98,7 @@ static JSValue js_os_totalmem(JSContext *js, JSValue self, int argc, JSValue *ar
|
||||
#ifdef _WIN32
|
||||
MEMORYSTATUSEX statex;
|
||||
statex.dwLength = sizeof(statex);
|
||||
if (!GlobalMemoryStatusEx(&statex)) return JS_ThrowInternalError(js,"GlobalMemoryStatusEx failed");
|
||||
if (!GlobalMemoryStatusEx(&statex)) return JS_RaiseDisrupt(js,"GlobalMemoryStatusEx failed");
|
||||
return JS_NewInt64(js,(int64_t)(statex.ullTotalPhys / (1024 * 1024)));
|
||||
#elif defined(__linux__)
|
||||
struct sysinfo info;
|
||||
@@ -150,7 +150,7 @@ static JSValue js_os_hostname(JSContext *js, JSValue self, int argc, JSValue *ar
|
||||
return JS_NewString(js, buffer);
|
||||
#else
|
||||
struct utsname buffer;
|
||||
if (uname(&buffer) != 0) return JS_ThrowReferenceError(js,"Could not get hostname.");
|
||||
if (uname(&buffer) != 0) return JS_RaiseDisrupt(js,"Could not get hostname.");
|
||||
return JS_NewString(js, buffer.nodename);
|
||||
#endif
|
||||
return ret;
|
||||
@@ -189,7 +189,7 @@ static JSValue js_os_freemem(JSContext *js, JSValue self, int argc, JSValue *arg
|
||||
#ifdef _WIN32
|
||||
MEMORYSTATUSEX statex;
|
||||
statex.dwLength = sizeof(statex);
|
||||
if (!GlobalMemoryStatusEx(&statex)) return JS_ThrowInternalError(js,"GlobalMemoryStatusEx failed");
|
||||
if (!GlobalMemoryStatusEx(&statex)) return JS_RaiseDisrupt(js,"GlobalMemoryStatusEx failed");
|
||||
return JS_NewInt64(js,(int64_t)statex.ullAvailPhys);
|
||||
#elif defined(__linux__)
|
||||
struct sysinfo info;
|
||||
@@ -316,12 +316,12 @@ JSC_CCALL(os_exit,
|
||||
static JSValue js_os_dylib_open(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||
{
|
||||
if (argc < 1) {
|
||||
return JS_ThrowTypeError(js, "dylib_open requires a path argument");
|
||||
return JS_RaiseDisrupt(js, "dylib_open requires a path argument");
|
||||
}
|
||||
|
||||
const char *path = JS_ToCString(js, argv[0]);
|
||||
if (!path) {
|
||||
return JS_ThrowTypeError(js, "path must be a string");
|
||||
return JS_RaiseDisrupt(js, "path must be a string");
|
||||
}
|
||||
|
||||
void *handle;
|
||||
@@ -341,7 +341,7 @@ static JSValue js_os_dylib_open(JSContext *js, JSValue self, int argc, JSValue *
|
||||
error_msg = dl_error;
|
||||
}
|
||||
#endif
|
||||
return JS_ThrowReferenceError(js, "Failed to load library: %s", error_msg);
|
||||
return JS_RaiseDisrupt(js, "Failed to load library: %s", error_msg);
|
||||
}
|
||||
|
||||
JSValue dylib_obj = JS_NewObjectClass(js, js_dylib_class_id);
|
||||
@@ -396,17 +396,17 @@ static JSValue js_os_dylib_preload(JSContext *js, JSValue self, int argc, JSValu
|
||||
static JSValue js_os_dylib_symbol(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
return JS_ThrowTypeError(js, "dylib_symbol requires dylib object and symbol name");
|
||||
return JS_RaiseDisrupt(js, "dylib_symbol requires dylib object and symbol name");
|
||||
}
|
||||
|
||||
void *handle = JS_GetOpaque(argv[0], js_dylib_class_id);
|
||||
if (!handle) {
|
||||
return JS_ThrowTypeError(js, "First argument must be a dylib object");
|
||||
return JS_RaiseDisrupt(js, "First argument must be a dylib object");
|
||||
}
|
||||
|
||||
const char *symbol_name = JS_ToCString(js, argv[1]);
|
||||
if (!symbol_name) {
|
||||
return JS_ThrowTypeError(js, "symbol name must be a string");
|
||||
return JS_RaiseDisrupt(js, "symbol name must be a string");
|
||||
}
|
||||
|
||||
JSValue (*symbol)(JSContext *js);
|
||||
@@ -426,7 +426,7 @@ static JSValue js_os_dylib_symbol(JSContext *js, JSValue self, int argc, JSValue
|
||||
error_msg = dl_error;
|
||||
}
|
||||
#endif
|
||||
return JS_ThrowReferenceError(js, "Failed to load symbol: %s", error_msg);
|
||||
return JS_RaiseDisrupt(js, "Failed to load symbol: %s", error_msg);
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
@@ -437,17 +437,17 @@ static JSValue js_os_dylib_symbol(JSContext *js, JSValue self, int argc, JSValue
|
||||
static JSValue js_os_dylib_has_symbol(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
return JS_ThrowTypeError(js, "dylib_has_symbol requires dylib object and symbol name");
|
||||
return JS_RaiseDisrupt(js, "dylib_has_symbol requires dylib object and symbol name");
|
||||
}
|
||||
|
||||
void *handle = JS_GetOpaque(argv[0], js_dylib_class_id);
|
||||
if (!handle) {
|
||||
return JS_ThrowTypeError(js, "First argument must be a dylib object");
|
||||
return JS_RaiseDisrupt(js, "First argument must be a dylib object");
|
||||
}
|
||||
|
||||
const char *symbol_name = JS_ToCString(js, argv[1]);
|
||||
if (!symbol_name) {
|
||||
return JS_ThrowTypeError(js, "symbol name must be a string");
|
||||
return JS_RaiseDisrupt(js, "symbol name must be a string");
|
||||
}
|
||||
|
||||
void *symbol;
|
||||
@@ -465,7 +465,7 @@ static JSValue js_os_dylib_has_symbol(JSContext *js, JSValue self, int argc, JSV
|
||||
static JSValue js_os_dylib_close(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||
{
|
||||
if (argc < 1)
|
||||
return JS_ThrowTypeError(js, "dylib_close requires a dylib object");
|
||||
return JS_RaiseDisrupt(js, "dylib_close requires a dylib object");
|
||||
void *handle = JS_GetOpaque(argv[0], js_dylib_class_id);
|
||||
if (handle) {
|
||||
#ifdef _WIN32
|
||||
@@ -487,11 +487,11 @@ extern JSValue js_os_qbe(JSContext *, JSValue, int, JSValue *);
|
||||
static JSValue js_os_native_module_load(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||
{
|
||||
if (argc < 1)
|
||||
return JS_ThrowTypeError(js, "native_module_load requires a dylib object");
|
||||
return JS_RaiseDisrupt(js, "native_module_load requires a dylib object");
|
||||
|
||||
void *handle = JS_GetOpaque(argv[0], js_dylib_class_id);
|
||||
if (!handle)
|
||||
return JS_ThrowTypeError(js, "First argument must be a dylib object");
|
||||
return JS_RaiseDisrupt(js, "First argument must be a dylib object");
|
||||
|
||||
JSValue env = (argc >= 2) ? argv[1] : JS_NULL;
|
||||
return cell_rt_native_module_load(js, handle, env);
|
||||
@@ -500,11 +500,11 @@ static JSValue js_os_native_module_load(JSContext *js, JSValue self, int argc, J
|
||||
static JSValue js_os_native_module_load_named(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
return JS_ThrowTypeError(js, "native_module_load_named requires (dylib, sym_name)");
|
||||
return JS_RaiseDisrupt(js, "native_module_load_named requires (dylib, sym_name)");
|
||||
|
||||
void *handle = JS_GetOpaque(argv[0], js_dylib_class_id);
|
||||
if (!handle)
|
||||
return JS_ThrowTypeError(js, "First argument must be a dylib object");
|
||||
return JS_RaiseDisrupt(js, "First argument must be a dylib object");
|
||||
|
||||
const char *sym_name = JS_ToCString(js, argv[1]);
|
||||
if (!sym_name)
|
||||
@@ -532,11 +532,11 @@ static JSValue js_os_load_internal(JSContext *js, JSValue self, int argc, JSValu
|
||||
handle = dlopen(NULL, RTLD_LAZY);
|
||||
#endif
|
||||
if (argc < 1)
|
||||
return JS_ThrowTypeError(js, "load_internal requires a symbol name");
|
||||
return JS_RaiseDisrupt(js, "load_internal requires a symbol name");
|
||||
|
||||
const char *symbol_name = JS_ToCString(js, argv[0]);
|
||||
if (!symbol_name)
|
||||
return JS_ThrowTypeError(js, "symbol name must be a string");
|
||||
return JS_RaiseDisrupt(js, "symbol name must be a string");
|
||||
|
||||
JSValue (*symbol)(JSContext *js);
|
||||
#if defined(_WIN32)
|
||||
@@ -562,11 +562,11 @@ static JSValue js_os_internal_exists(JSContext *js, JSValue self, int argc, JSVa
|
||||
handle = dlopen(NULL, RTLD_LAZY);
|
||||
#endif
|
||||
if (argc < 1)
|
||||
return JS_ThrowTypeError(js, "internal_exists requires a symbol name");
|
||||
return JS_RaiseDisrupt(js, "internal_exists requires a symbol name");
|
||||
|
||||
const char *symbol_name = JS_ToCString(js, argv[0]);
|
||||
if (!symbol_name)
|
||||
return JS_ThrowTypeError(js, "symbol name must be a string");
|
||||
return JS_RaiseDisrupt(js, "symbol name must be a string");
|
||||
|
||||
void *symbol;
|
||||
#if defined(_WIN32)
|
||||
|
||||
@@ -96,11 +96,11 @@ JSC_CCALL(os_exit,
|
||||
|
||||
// dylib functions - assuming static build for now unless side modules are used
|
||||
static JSValue js_os_dylib_open(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
||||
return JS_ThrowInternalError(js, "dylib_open: not supported on Emscripten");
|
||||
return JS_RaiseDisrupt(js, "dylib_open: not supported on Emscripten");
|
||||
}
|
||||
|
||||
static JSValue js_os_dylib_symbol(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
||||
return JS_ThrowInternalError(js, "dylib_symbol: not supported on Emscripten");
|
||||
return JS_RaiseDisrupt(js, "dylib_symbol: not supported on Emscripten");
|
||||
}
|
||||
|
||||
static JSValue js_os_dylib_has_symbol(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
||||
|
||||
@@ -94,11 +94,11 @@ JSC_CCALL(os_exit,
|
||||
|
||||
// dylib functions - not supported on Playdate
|
||||
static JSValue js_os_dylib_open(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
||||
return JS_ThrowInternalError(js, "dylib_open: not supported on Playdate");
|
||||
return JS_RaiseDisrupt(js, "dylib_open: not supported on Playdate");
|
||||
}
|
||||
|
||||
static JSValue js_os_dylib_symbol(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
||||
return JS_ThrowInternalError(js, "dylib_symbol: not supported on Playdate");
|
||||
return JS_RaiseDisrupt(js, "dylib_symbol: not supported on Playdate");
|
||||
}
|
||||
|
||||
static JSValue js_os_dylib_has_symbol(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
||||
|
||||
Reference in New Issue
Block a user