Initial commit

This commit is contained in:
2025-10-04 16:25:50 +02:00
commit 436dbdfb01
38 changed files with 78719 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
*.pdf filter=lfs diff=lfs merge=lfs -text

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.zig-cache

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"files.exclude":{
"**/.zig-cache": true,
},
}

156
build.zig Normal file
View File

@@ -0,0 +1,156 @@
const std = @import("std");
// Although this function looks imperative, it does not perform the build
// directly and instead it mutates the build graph (`b`) that will be then
// executed by an external runner. The functions in `std.Build` implement a DSL
// for defining build steps and express dependencies between them, allowing the
// build runner to parallelize the build automatically (and the cache system to
// know when a step doesn't need to be re-run).
pub fn build(b: *std.Build) void {
// Standard target options allow the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
// It's also possible to define more custom flags to toggle optional features
// of this build script using `b.option()`. All defined flags (including
// target and optimize options) will be listed when running `zig build --help`
// in this directory.
// This creates a module, which represents a collection of source files alongside
// some compilation options, such as optimization mode and linked system libraries.
// Zig modules are the preferred way of making Zig code available to consumers.
// addModule defines a module that we intend to make available for importing
// to our consumers. We must give it a name because a Zig package can expose
// multiple modules and consumers will need to be able to specify which
// module they want to access.
const mod = b.addModule("castle", .{
// The root source file is the "entry point" of this module. Users of
// this module will only be able to access public declarations contained
// in this file, which means that if you have declarations that you
// intend to expose to consumers that were defined in other files part
// of this module, you will have to make sure to re-export them from
// the root file.
.root_source_file = b.path("src/root.zig"),
// Later on we'll use this module as the root module of a test executable
// which requires us to specify a target.
.target = target,
});
// Here we define an executable. An executable needs to have a root module
// which needs to expose a `main` function. While we could add a main function
// to the module defined above, it's sometimes preferable to split business
// business logic and the CLI into two separate modules.
//
// If your goal is to create a Zig library for others to use, consider if
// it might benefit from also exposing a CLI tool. A parser library for a
// data serialization format could also bundle a CLI syntax checker, for example.
//
// If instead your goal is to create an executable, consider if users might
// be interested in also being able to embed the core functionality of your
// program in their own executable in order to avoid the overhead involved in
// subprocessing your CLI tool.
//
// If neither case applies to you, feel free to delete the declaration you
// don't need and to put everything under a single module.
const exe = b.addExecutable(.{
.name = "castle",
.root_module = b.createModule(.{
// b.createModule defines a new module just like b.addModule but,
// unlike b.addModule, it does not expose the module to consumers of
// this package, which is why in this case we don't have to give it a name.
.root_source_file = b.path("src/main.zig"),
// Target and optimization levels must be explicitly wired in when
// defining an executable or library (in the root module), and you
// can also hardcode a specific target for an executable or library
// definition if desireable (e.g. firmware for embedded devices).
.target = target,
.optimize = optimize,
// List of modules available for import in source files part of the
// root module.
.imports = &.{
// Here "castle" is the name you will use in your source code to
// import this module (e.g. `@import("castle")`). The name is
// repeated because you are allowed to rename your imports, which
// can be extremely useful in case of collisions (which can happen
// importing modules from different packages).
.{ .name = "castle", .module = mod },
},
}),
});
// This declares intent for the executable to be installed into the
// install prefix when running `zig build` (i.e. when executing the default
// step). By default the install prefix is `zig-out/` but can be overridden
// by passing `--prefix` or `-p`.
b.installArtifact(exe);
// This creates a top level step. Top level steps have a name and can be
// invoked by name when running `zig build` (e.g. `zig build run`).
// This will evaluate the `run` step rather than the default step.
// For a top level step to actually do something, it must depend on other
// steps (e.g. a Run step, as we will see in a moment).
const run_step = b.step("run", "Run the app");
// This creates a RunArtifact step in the build graph. A RunArtifact step
// invokes an executable compiled by Zig. Steps will only be executed by the
// runner if invoked directly by the user (in the case of top level steps)
// or if another step depends on it, so it's up to you to define when and
// how this Run step will be executed. In our case we want to run it when
// the user runs `zig build run`, so we create a dependency link.
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
// By making the run step depend on the default step, it will be run from the
// installation directory rather than directly from within the cache directory.
run_cmd.step.dependOn(b.getInstallStep());
// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}
// Creates an executable that will run `test` blocks from the provided module.
// Here `mod` needs to define a target, which is why earlier we made sure to
// set the releative field.
const mod_tests = b.addTest(.{
.root_module = mod,
});
// A run step that will run the test executable.
const run_mod_tests = b.addRunArtifact(mod_tests);
// Creates an executable that will run `test` blocks from the executable's
// root module. Note that test executables only test one module at a time,
// hence why we have to create two separate ones.
const exe_tests = b.addTest(.{
.root_module = exe.root_module,
});
// A run step that will run the second test executable.
const run_exe_tests = b.addRunArtifact(exe_tests);
// A top level step for running all tests. dependOn can be called multiple
// times and since the two run steps do not depend on one another, this will
// make the two of them run in parallel.
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
test_step.dependOn(&run_exe_tests.step);
// Just like flags, top level steps are also listed in the `--help` menu.
//
// The Zig build system is entirely implemented in userland, which means
// that it cannot hook into private compiler APIs. All compilation work
// orchestrated by the build system will result in other Zig compiler
// subcommands being invoked with the right flags defined. You can observe
// these invocations when one fails (or you pass a flag to increase
// verbosity) to validate assumptions and diagnose problems.
//
// Lastly, the Zig build system is relatively simple and self-contained,
// and reading its source code will allow you to master it.
}

81
build.zig.zon Normal file
View File

@@ -0,0 +1,81 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = .castle,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
// Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the
// package is first created, and then *never changes*. This allows
// unambiguous detection of one package being an updated version of
// another.
//
// When forking a Zig project, this id should be regenerated (delete the
// field and run `zig build`) if the upstream project is still maintained.
// Otherwise, the fork is *hostile*, attempting to take control over the
// original project's identity. Thus it is recommended to leave the comment
// on the following line intact, so that it shows up in code reviews that
// modify the field.
.fingerprint = 0x4512fc283391a69a, // Changing this has security and trust implications.
// Tracks the earliest Zig version that the package considers to be a
// supported use case.
.minimum_zig_version = "0.15.1",
// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
//.example = .{
// // When updating this field to a new URL, be sure to delete the corresponding
// // `hash`, otherwise you are communicating that you expect to find the old hash at
// // the new URL. If the contents of a URL change this will result in a hash mismatch
// // which will prevent zig from using it.
// .url = "https://example.com/foo.tar.gz",
//
// // This is computed from the file contents of the directory of files that is
// // obtained after fetching `url` and applying the inclusion rules given by
// // `paths`.
// //
// // This field is the source of truth; packages do not come from a `url`; they
// // come from a `hash`. `url` is just one of many possible mirrors for how to
// // obtain a package matching this `hash`.
// //
// // Uses the [multihash](https://multiformats.io/multihash/) format.
// .hash = "...",
//
// // When this is provided, the package is found in a directory relative to the
// // build root. In this case the package's hash is irrelevant and therefore not
// // computed. This field and `url` are mutually exclusive.
// .path = "foo",
//
// // When this is set to `true`, a package is declared to be lazily
// // fetched. This makes the dependency only get fetched if it is
// // actually used.
// .lazy = false,
//},
},
// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package. Only files listed here will remain on disk
// when using the zig package manager. As a rule of thumb, one should list
// files required for compilation plus any license(s).
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
"build.zig",
"build.zig.zon",
"src",
// For example...
//"LICENSE",
//"README.md",
},
}

66
packages/js/build.zig Normal file
View File

@@ -0,0 +1,66 @@
const std = @import("std");
const version_file = @embedFile("vendor/VERSION");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const version_string = b.fmt("\"{s}\"", .{std.mem.trim(u8, version_file, " \n\t")});
// --- QuickJS module ---
const mod = b.addModule("js", .{
.root_source_file = b.path("src/root.zig"),
.link_libc = true,
.target = target,
});
mod.addCSourceFiles(.{
.files = &.{
"vendor/cutils.c",
"vendor/dtoa.c",
"vendor/libregexp.c",
"vendor/libunicode.c",
"vendor/quickjs-libc.c",
"vendor/quickjs.c",
},
.flags = &.{
"-Wall",
"-Wextra",
"-Wno-sign-compare",
"-Wno-missing-field-initializers",
"-Wundef",
"-Wuninitialized",
"-Wunused",
"-Wno-unused-parameter",
"-Wwrite-strings",
"-Wchar-subscripts",
"-funsigned-char",
"-fwrapv",
},
});
mod.addCMacro("_GNU_SOURCE", "");
mod.addCMacro("CONFIG_VERSION", version_string);
if (target.result.os.tag == .windows) {
mod.addCMacro("__USE_MINGW_ANSI_STDIO", "");
}
mod.linkSystemLibrary("m", .{});
mod.linkSystemLibrary("pthread", .{});
if (target.result.os.tag != .windows) {
mod.linkSystemLibrary("dl", .{});
}
// --- Tests ---
const mod_tests = b.addTest(.{
.root_module = mod,
});
const run_mod_tests = b.addRunArtifact(mod_tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
}

12
packages/js/build.zig.zon Normal file
View File

@@ -0,0 +1,12 @@
.{
.name = .js,
.version = "0.0.0",
.minimum_zig_version = "0.15.1",
.paths = .{
"src",
"vendor",
"build.zig",
"build.zig.zon",
},
.fingerprint = 0x17c7b154d3f3d26d,
}

890
packages/js/src/quickjs.zig Normal file
View File

@@ -0,0 +1,890 @@
pub extern fn strlen(str: [*:0]const u8) usize;
pub const struct_JSRuntime = opaque {};
pub const JSRuntime = struct_JSRuntime;
pub const struct_JSContext = opaque {};
pub const JSContext = struct_JSContext;
pub const struct_JSClass = opaque {};
pub const JSClass = struct_JSClass;
pub const JSClassID = u32;
pub const JSAtom = u32;
pub const JS_TAG_FIRST: c_int = -9;
pub const JS_TAG_BIG_INT: c_int = -9;
pub const JS_TAG_SYMBOL: c_int = -8;
pub const JS_TAG_STRING: c_int = -7;
pub const JS_TAG_STRING_ROPE: c_int = -6;
pub const JS_TAG_MODULE: c_int = -3;
pub const JS_TAG_FUNCTION_BYTECODE: c_int = -2;
pub const JS_TAG_OBJECT: c_int = -1;
pub const JS_TAG_INT: c_int = 0;
pub const JS_TAG_BOOL: c_int = 1;
pub const JS_TAG_NULL: c_int = 2;
pub const JS_TAG_UNDEFINED: c_int = 3;
pub const JS_TAG_UNINITIALIZED: c_int = 4;
pub const JS_TAG_CATCH_OFFSET: c_int = 5;
pub const JS_TAG_EXCEPTION: c_int = 6;
pub const JS_TAG_SHORT_BIG_INT: c_int = 7;
pub const JS_TAG_FLOAT64: c_int = 8;
const enum_unnamed_4 = c_int;
pub const struct_JSRefCountHeader = extern struct {
ref_count: c_int = @import("std").mem.zeroes(c_int),
};
pub const JSRefCountHeader = struct_JSRefCountHeader;
pub const union_JSValueUnion = extern union {
int32: i32,
float64: f64,
ptr: ?*anyopaque,
short_big_int: i64,
};
pub const JSValueUnion = union_JSValueUnion;
pub const struct_JSValue = extern struct {
u: JSValueUnion = @import("std").mem.zeroes(JSValueUnion),
tag: i64 = @import("std").mem.zeroes(i64),
};
pub const JSValue = struct_JSValue;
pub fn __JS_NewFloat64(arg_ctx: ?*JSContext, arg_d: f64) callconv(.c) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var d = arg_d;
_ = &d;
var v: JSValue = undefined;
_ = &v;
v.tag = @as(i64, @bitCast(@as(c_long, JS_TAG_FLOAT64)));
v.u.float64 = d;
return v;
}
pub fn JS_VALUE_IS_NAN(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
const union_unnamed_5 = extern union {
d: f64,
u64: u64,
};
_ = &union_unnamed_5;
var u: union_unnamed_5 = undefined;
_ = &u;
if (v.tag != @as(i64, @bitCast(@as(c_long, JS_TAG_FLOAT64)))) return 0;
u.d = v.u.float64;
return @intFromBool((u.u64 & @as(u64, @bitCast(@as(c_long, 9223372036854775807)))) > @as(u64, @bitCast(@as(c_long, 9218868437227405312))));
}
pub fn __JS_NewShortBigInt(arg_ctx: ?*JSContext, arg_d: i64) callconv(.c) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var d = arg_d;
_ = &d;
var v: JSValue = undefined;
_ = &v;
v.tag = @as(i64, @bitCast(@as(c_long, JS_TAG_SHORT_BIG_INT)));
v.u.short_big_int = d;
return v;
}
pub const JSCFunction = fn (?*JSContext, JSValue, c_int, [*c]JSValue) callconv(.c) JSValue;
pub const JSCFunctionMagic = fn (?*JSContext, JSValue, c_int, [*c]JSValue, c_int) callconv(.c) JSValue;
pub const JSCFunctionData = fn (?*JSContext, JSValue, c_int, [*c]JSValue, c_int, [*c]JSValue) callconv(.c) JSValue;
pub const struct_JSMallocState = extern struct {
malloc_count: usize = @import("std").mem.zeroes(usize),
malloc_size: usize = @import("std").mem.zeroes(usize),
malloc_limit: usize = @import("std").mem.zeroes(usize),
@"opaque": ?*anyopaque = @import("std").mem.zeroes(?*anyopaque),
};
pub const JSMallocState = struct_JSMallocState;
pub const struct_JSMallocFunctions = extern struct {
js_malloc: ?*const fn ([*c]JSMallocState, usize) callconv(.c) ?*anyopaque = @import("std").mem.zeroes(?*const fn ([*c]JSMallocState, usize) callconv(.c) ?*anyopaque),
js_free: ?*const fn ([*c]JSMallocState, ?*anyopaque) callconv(.c) void = @import("std").mem.zeroes(?*const fn ([*c]JSMallocState, ?*anyopaque) callconv(.c) void),
js_realloc: ?*const fn ([*c]JSMallocState, ?*anyopaque, usize) callconv(.c) ?*anyopaque = @import("std").mem.zeroes(?*const fn ([*c]JSMallocState, ?*anyopaque, usize) callconv(.c) ?*anyopaque),
js_malloc_usable_size: ?*const fn (?*const anyopaque) callconv(.c) usize = @import("std").mem.zeroes(?*const fn (?*const anyopaque) callconv(.c) usize),
};
pub const JSMallocFunctions = struct_JSMallocFunctions;
pub const struct_JSGCObjectHeader = opaque {};
pub const JSGCObjectHeader = struct_JSGCObjectHeader;
pub extern fn JS_NewRuntime() ?*JSRuntime;
pub extern fn JS_SetRuntimeInfo(rt: ?*JSRuntime, info: [*c]const u8) void;
pub extern fn JS_SetMemoryLimit(rt: ?*JSRuntime, limit: usize) void;
pub extern fn JS_SetGCThreshold(rt: ?*JSRuntime, gc_threshold: usize) void;
pub extern fn JS_SetMaxStackSize(rt: ?*JSRuntime, stack_size: usize) void;
pub extern fn JS_UpdateStackTop(rt: ?*JSRuntime) void;
pub extern fn JS_NewRuntime2(mf: [*c]const JSMallocFunctions, @"opaque": ?*anyopaque) ?*JSRuntime;
pub extern fn JS_FreeRuntime(rt: ?*JSRuntime) void;
pub extern fn JS_GetRuntimeOpaque(rt: ?*JSRuntime) ?*anyopaque;
pub extern fn JS_SetRuntimeOpaque(rt: ?*JSRuntime, @"opaque": ?*anyopaque) void;
pub const JS_MarkFunc = fn (?*JSRuntime, ?*JSGCObjectHeader) callconv(.c) void;
pub extern fn JS_MarkValue(rt: ?*JSRuntime, val: JSValue, mark_func: ?*const JS_MarkFunc) void;
pub extern fn JS_RunGC(rt: ?*JSRuntime) void;
pub extern fn JS_IsLiveObject(rt: ?*JSRuntime, obj: JSValue) c_int;
pub extern fn JS_NewContext(rt: ?*JSRuntime) ?*JSContext;
pub extern fn JS_FreeContext(s: ?*JSContext) void;
pub extern fn JS_DupContext(ctx: ?*JSContext) ?*JSContext;
pub extern fn JS_GetContextOpaque(ctx: ?*JSContext) ?*anyopaque;
pub extern fn JS_SetContextOpaque(ctx: ?*JSContext, @"opaque": ?*anyopaque) void;
pub extern fn JS_GetRuntime(ctx: ?*JSContext) ?*JSRuntime;
pub extern fn JS_SetClassProto(ctx: ?*JSContext, class_id: JSClassID, obj: JSValue) void;
pub extern fn JS_GetClassProto(ctx: ?*JSContext, class_id: JSClassID) JSValue;
pub extern fn JS_NewContextRaw(rt: ?*JSRuntime) ?*JSContext;
pub extern fn JS_AddIntrinsicBaseObjects(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicDate(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicEval(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicStringNormalize(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicRegExpCompiler(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicRegExp(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicJSON(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicProxy(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicMapSet(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicTypedArrays(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicPromise(ctx: ?*JSContext) void;
pub extern fn JS_AddIntrinsicWeakRef(ctx: ?*JSContext) void;
pub extern fn js_string_codePointRange(ctx: ?*JSContext, this_val: JSValue, argc: c_int, argv: [*c]JSValue) JSValue;
pub extern fn js_malloc_rt(rt: ?*JSRuntime, size: usize) ?*anyopaque;
pub extern fn js_free_rt(rt: ?*JSRuntime, ptr: ?*anyopaque) void;
pub extern fn js_realloc_rt(rt: ?*JSRuntime, ptr: ?*anyopaque, size: usize) ?*anyopaque;
pub extern fn js_malloc_usable_size_rt(rt: ?*JSRuntime, ptr: ?*const anyopaque) usize;
pub extern fn js_mallocz_rt(rt: ?*JSRuntime, size: usize) ?*anyopaque;
pub extern fn js_malloc(ctx: ?*JSContext, size: usize) ?*anyopaque;
pub extern fn js_free(ctx: ?*JSContext, ptr: ?*anyopaque) void;
pub extern fn js_realloc(ctx: ?*JSContext, ptr: ?*anyopaque, size: usize) ?*anyopaque;
pub extern fn js_malloc_usable_size(ctx: ?*JSContext, ptr: ?*const anyopaque) usize;
pub extern fn js_realloc2(ctx: ?*JSContext, ptr: ?*anyopaque, size: usize, pslack: [*c]usize) ?*anyopaque;
pub extern fn js_mallocz(ctx: ?*JSContext, size: usize) ?*anyopaque;
pub extern fn js_strdup(ctx: ?*JSContext, str: [*c]const u8) [*c]u8;
pub extern fn js_strndup(ctx: ?*JSContext, s: [*c]const u8, n: usize) [*c]u8;
pub const struct_JSMemoryUsage = extern struct {
malloc_size: i64 = @import("std").mem.zeroes(i64),
malloc_limit: i64 = @import("std").mem.zeroes(i64),
memory_used_size: i64 = @import("std").mem.zeroes(i64),
malloc_count: i64 = @import("std").mem.zeroes(i64),
memory_used_count: i64 = @import("std").mem.zeroes(i64),
atom_count: i64 = @import("std").mem.zeroes(i64),
atom_size: i64 = @import("std").mem.zeroes(i64),
str_count: i64 = @import("std").mem.zeroes(i64),
str_size: i64 = @import("std").mem.zeroes(i64),
obj_count: i64 = @import("std").mem.zeroes(i64),
obj_size: i64 = @import("std").mem.zeroes(i64),
prop_count: i64 = @import("std").mem.zeroes(i64),
prop_size: i64 = @import("std").mem.zeroes(i64),
shape_count: i64 = @import("std").mem.zeroes(i64),
shape_size: i64 = @import("std").mem.zeroes(i64),
js_func_count: i64 = @import("std").mem.zeroes(i64),
js_func_size: i64 = @import("std").mem.zeroes(i64),
js_func_code_size: i64 = @import("std").mem.zeroes(i64),
js_func_pc2line_count: i64 = @import("std").mem.zeroes(i64),
js_func_pc2line_size: i64 = @import("std").mem.zeroes(i64),
c_func_count: i64 = @import("std").mem.zeroes(i64),
array_count: i64 = @import("std").mem.zeroes(i64),
fast_array_count: i64 = @import("std").mem.zeroes(i64),
fast_array_elements: i64 = @import("std").mem.zeroes(i64),
binary_object_count: i64 = @import("std").mem.zeroes(i64),
binary_object_size: i64 = @import("std").mem.zeroes(i64),
};
pub const JSMemoryUsage = struct_JSMemoryUsage;
pub extern fn JS_ComputeMemoryUsage(rt: ?*JSRuntime, s: [*c]JSMemoryUsage) void;
pub extern fn JS_DumpMemoryUsage(fp: [*c]@import("std").c.FILE, s: [*c]const JSMemoryUsage, rt: ?*JSRuntime) void;
pub extern fn JS_NewAtomLen(ctx: ?*JSContext, str: [*c]const u8, len: usize) JSAtom;
pub extern fn JS_NewAtom(ctx: ?*JSContext, str: [*c]const u8) JSAtom;
pub extern fn JS_NewAtomUInt32(ctx: ?*JSContext, n: u32) JSAtom;
pub extern fn JS_DupAtom(ctx: ?*JSContext, v: JSAtom) JSAtom;
pub extern fn JS_FreeAtom(ctx: ?*JSContext, v: JSAtom) void;
pub extern fn JS_FreeAtomRT(rt: ?*JSRuntime, v: JSAtom) void;
pub extern fn JS_AtomToValue(ctx: ?*JSContext, atom: JSAtom) JSValue;
pub extern fn JS_AtomToString(ctx: ?*JSContext, atom: JSAtom) JSValue;
pub extern fn JS_AtomToCStringLen(ctx: ?*JSContext, plen: [*c]usize, atom: JSAtom) [*c]const u8;
pub fn JS_AtomToCString(arg_ctx: ?*JSContext, arg_atom: JSAtom) callconv(.c) [*c]const u8 {
var ctx = arg_ctx;
_ = &ctx;
var atom = arg_atom;
_ = &atom;
return JS_AtomToCStringLen(ctx, null, atom);
}
pub extern fn JS_ValueToAtom(ctx: ?*JSContext, val: JSValue) JSAtom;
pub const struct_JSPropertyEnum = extern struct {
is_enumerable: c_int = @import("std").mem.zeroes(c_int),
atom: JSAtom = @import("std").mem.zeroes(JSAtom),
};
pub const JSPropertyEnum = struct_JSPropertyEnum;
pub const struct_JSPropertyDescriptor = extern struct {
flags: c_int = @import("std").mem.zeroes(c_int),
value: JSValue = @import("std").mem.zeroes(JSValue),
getter: JSValue = @import("std").mem.zeroes(JSValue),
setter: JSValue = @import("std").mem.zeroes(JSValue),
};
pub const JSPropertyDescriptor = struct_JSPropertyDescriptor;
pub const struct_JSClassExoticMethods = extern struct {
get_own_property: ?*const fn (?*JSContext, [*c]JSPropertyDescriptor, JSValue, JSAtom) callconv(.c) c_int = @import("std").mem.zeroes(?*const fn (?*JSContext, [*c]JSPropertyDescriptor, JSValue, JSAtom) callconv(.c) c_int),
get_own_property_names: ?*const fn (?*JSContext, [*c][*c]JSPropertyEnum, [*c]u32, JSValue) callconv(.c) c_int = @import("std").mem.zeroes(?*const fn (?*JSContext, [*c][*c]JSPropertyEnum, [*c]u32, JSValue) callconv(.c) c_int),
delete_property: ?*const fn (?*JSContext, JSValue, JSAtom) callconv(.c) c_int = @import("std").mem.zeroes(?*const fn (?*JSContext, JSValue, JSAtom) callconv(.c) c_int),
define_own_property: ?*const fn (?*JSContext, JSValue, JSAtom, JSValue, JSValue, JSValue, c_int) callconv(.c) c_int = @import("std").mem.zeroes(?*const fn (?*JSContext, JSValue, JSAtom, JSValue, JSValue, JSValue, c_int) callconv(.c) c_int),
has_property: ?*const fn (?*JSContext, JSValue, JSAtom) callconv(.c) c_int = @import("std").mem.zeroes(?*const fn (?*JSContext, JSValue, JSAtom) callconv(.c) c_int),
get_property: ?*const fn (?*JSContext, JSValue, JSAtom, JSValue) callconv(.c) JSValue = @import("std").mem.zeroes(?*const fn (?*JSContext, JSValue, JSAtom, JSValue) callconv(.c) JSValue),
set_property: ?*const fn (?*JSContext, JSValue, JSAtom, JSValue, JSValue, c_int) callconv(.c) c_int = @import("std").mem.zeroes(?*const fn (?*JSContext, JSValue, JSAtom, JSValue, JSValue, c_int) callconv(.c) c_int),
get_prototype: ?*const fn (?*JSContext, JSValue) callconv(.c) JSValue = @import("std").mem.zeroes(?*const fn (?*JSContext, JSValue) callconv(.c) JSValue),
set_prototype: ?*const fn (?*JSContext, JSValue, JSValue) callconv(.c) c_int = @import("std").mem.zeroes(?*const fn (?*JSContext, JSValue, JSValue) callconv(.c) c_int),
is_extensible: ?*const fn (?*JSContext, JSValue) callconv(.c) c_int = @import("std").mem.zeroes(?*const fn (?*JSContext, JSValue) callconv(.c) c_int),
prevent_extensions: ?*const fn (?*JSContext, JSValue) callconv(.c) c_int = @import("std").mem.zeroes(?*const fn (?*JSContext, JSValue) callconv(.c) c_int),
};
pub const JSClassExoticMethods = struct_JSClassExoticMethods;
pub const JSClassFinalizer = fn (?*JSRuntime, JSValue) callconv(.c) void;
pub const JSClassGCMark = fn (?*JSRuntime, JSValue, ?*const JS_MarkFunc) callconv(.c) void;
pub const JSClassCall = fn (?*JSContext, JSValue, JSValue, c_int, [*c]JSValue, c_int) callconv(.c) JSValue;
pub const struct_JSClassDef = extern struct {
class_name: [*c]const u8 = @import("std").mem.zeroes([*c]const u8),
finalizer: ?*const JSClassFinalizer = @import("std").mem.zeroes(?*const JSClassFinalizer),
gc_mark: ?*const JSClassGCMark = @import("std").mem.zeroes(?*const JSClassGCMark),
call: ?*const JSClassCall = @import("std").mem.zeroes(?*const JSClassCall),
exotic: [*c]JSClassExoticMethods = @import("std").mem.zeroes([*c]JSClassExoticMethods),
};
pub const JSClassDef = struct_JSClassDef;
pub extern fn JS_NewClassID(pclass_id: [*c]JSClassID) JSClassID;
pub extern fn JS_GetClassID(v: JSValue) JSClassID;
pub extern fn JS_NewClass(rt: ?*JSRuntime, class_id: JSClassID, class_def: [*c]const JSClassDef) c_int;
pub extern fn JS_IsRegisteredClass(rt: ?*JSRuntime, class_id: JSClassID) c_int;
pub inline fn JS_NewBool(arg_ctx: ?*JSContext, arg_val: c_int) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var val = arg_val;
_ = &val;
return JSValue{
.u = JSValueUnion{
.int32 = val != @as(c_int, 0),
},
.tag = @as(i64, @bitCast(@as(c_long, JS_TAG_BOOL))),
};
}
pub inline fn JS_NewInt32(arg_ctx: ?*JSContext, arg_val: i32) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var val = arg_val;
_ = &val;
return JSValue{
.u = JSValueUnion{
.int32 = val,
},
.tag = @as(i64, @bitCast(@as(c_long, JS_TAG_INT))),
};
}
pub inline fn JS_NewCatchOffset(arg_ctx: ?*JSContext, arg_val: i32) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var val = arg_val;
_ = &val;
return JSValue{
.u = JSValueUnion{
.int32 = val,
},
.tag = @as(i64, @bitCast(@as(c_long, JS_TAG_CATCH_OFFSET))),
};
}
pub inline fn JS_NewInt64(arg_ctx: ?*JSContext, arg_val: i64) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var val = arg_val;
_ = &val;
var v: JSValue = undefined;
_ = &v;
if (val == @as(i64, @bitCast(@as(c_long, @as(i32, @bitCast(@as(c_int, @truncate(val)))))))) {
v = JS_NewInt32(ctx, @as(i32, @bitCast(@as(c_int, @truncate(val)))));
} else {
v = __JS_NewFloat64(ctx, @as(f64, @floatFromInt(val)));
}
return v;
}
pub inline fn JS_NewUint32(arg_ctx: ?*JSContext, arg_val: u32) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var val = arg_val;
_ = &val;
var v: JSValue = undefined;
_ = &v;
if (val <= @as(u32, @bitCast(@as(c_int, 2147483647)))) {
v = JS_NewInt32(ctx, @as(i32, @bitCast(val)));
} else {
v = __JS_NewFloat64(ctx, @as(f64, @floatFromInt(val)));
}
return v;
}
pub extern fn JS_NewBigInt64(ctx: ?*JSContext, v: i64) JSValue;
pub extern fn JS_NewBigUint64(ctx: ?*JSContext, v: u64) JSValue;
pub inline fn JS_NewFloat64(arg_ctx: ?*JSContext, arg_d: f64) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var d = arg_d;
_ = &d;
var val: i32 = undefined;
_ = &val;
const union_unnamed_6 = extern union {
d: f64,
u: u64,
};
_ = &union_unnamed_6;
var u: union_unnamed_6 = undefined;
_ = &u;
var t: union_unnamed_6 = undefined;
_ = &t;
if ((d >= @as(f64, @floatFromInt(-@as(c_int, 2147483647) - @as(c_int, 1)))) and (d <= @as(f64, @floatFromInt(@as(c_int, 2147483647))))) {
u.d = d;
val = @as(i32, @intFromFloat(d));
t.d = @as(f64, @floatFromInt(val));
if (u.u == t.u) return JSValue{
.u = JSValueUnion{
.int32 = val,
},
.tag = @as(i64, @bitCast(@as(c_long, JS_TAG_INT))),
};
}
return __JS_NewFloat64(ctx, d);
}
pub fn JS_IsNumber(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
var tag: c_int = @as(i32, @bitCast(@as(c_int, @truncate(v.tag))));
_ = &tag;
return @intFromBool((tag == JS_TAG_INT) or (@as(c_uint, @bitCast(tag)) == @as(c_uint, @bitCast(JS_TAG_FLOAT64))));
}
pub fn JS_IsBigInt(arg_ctx: ?*JSContext, arg_v: JSValue) callconv(.c) c_int {
var ctx = arg_ctx;
_ = &ctx;
var v = arg_v;
_ = &v;
var tag: c_int = @as(i32, @bitCast(@as(c_int, @truncate(v.tag))));
_ = &tag;
return @intFromBool((tag == JS_TAG_BIG_INT) or (tag == JS_TAG_SHORT_BIG_INT));
}
pub fn JS_IsBool(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
return @intFromBool(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))) == JS_TAG_BOOL);
}
pub fn JS_IsNull(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
return @intFromBool(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))) == JS_TAG_NULL);
}
pub fn JS_IsUndefined(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
return @intFromBool(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))) == JS_TAG_UNDEFINED);
}
pub fn JS_IsException(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
return @as(c_int, @bitCast(@as(c_int, @truncate(@import("std").zig.c_builtins.__builtin_expect(@as(c_long, @intFromBool(!!(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))) == JS_TAG_EXCEPTION))), @as(c_long, @bitCast(@as(c_long, @as(c_int, 0)))))))));
}
pub fn JS_IsUninitialized(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
return @as(c_int, @bitCast(@as(c_int, @truncate(@import("std").zig.c_builtins.__builtin_expect(@as(c_long, @intFromBool(!!(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))) == JS_TAG_UNINITIALIZED))), @as(c_long, @bitCast(@as(c_long, @as(c_int, 0)))))))));
}
pub fn JS_IsString(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
return @intFromBool((@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))) == JS_TAG_STRING) or (@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))) == JS_TAG_STRING_ROPE));
}
pub fn JS_IsSymbol(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
return @intFromBool(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))) == JS_TAG_SYMBOL);
}
pub fn JS_IsObject(arg_v: JSValue) callconv(.c) c_int {
var v = arg_v;
_ = &v;
return @intFromBool(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))) == JS_TAG_OBJECT);
}
pub extern fn JS_Throw(ctx: ?*JSContext, obj: JSValue) JSValue;
pub extern fn JS_SetUncatchableException(ctx: ?*JSContext, flag: c_int) void;
pub extern fn JS_GetException(ctx: ?*JSContext) JSValue;
pub extern fn JS_HasException(ctx: ?*JSContext) c_int;
pub extern fn JS_IsError(ctx: ?*JSContext, val: JSValue) c_int;
pub extern fn JS_NewError(ctx: ?*JSContext) JSValue;
pub extern fn JS_ThrowSyntaxError(ctx: ?*JSContext, fmt: [*c]const u8, ...) JSValue;
pub extern fn JS_ThrowTypeError(ctx: ?*JSContext, fmt: [*c]const u8, ...) JSValue;
pub extern fn JS_ThrowReferenceError(ctx: ?*JSContext, fmt: [*c]const u8, ...) JSValue;
pub extern fn JS_ThrowRangeError(ctx: ?*JSContext, fmt: [*c]const u8, ...) JSValue;
pub extern fn JS_ThrowInternalError(ctx: ?*JSContext, fmt: [*c]const u8, ...) JSValue;
pub extern fn JS_ThrowOutOfMemory(ctx: ?*JSContext) JSValue;
pub extern fn __JS_FreeValue(ctx: ?*JSContext, v: JSValue) void;
pub fn JS_FreeValue(arg_ctx: ?*JSContext, arg_v: JSValue) callconv(.c) void {
var ctx = arg_ctx;
_ = &ctx;
var v = arg_v;
_ = &v;
if (@as(c_uint, @bitCast(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))))) >= @as(c_uint, @bitCast(JS_TAG_FIRST))) {
var p: [*c]JSRefCountHeader = @as([*c]JSRefCountHeader, @ptrCast(@alignCast(v.u.ptr)));
_ = &p;
if ((blk: {
const ref = &p.*.ref_count;
ref.* -= 1;
break :blk ref.*;
}) <= @as(c_int, 0)) {
__JS_FreeValue(ctx, v);
}
}
}
pub extern fn __JS_FreeValueRT(rt: ?*JSRuntime, v: JSValue) void;
pub fn JS_FreeValueRT(arg_rt: ?*JSRuntime, arg_v: JSValue) callconv(.c) void {
var rt = arg_rt;
_ = &rt;
var v = arg_v;
_ = &v;
if (@as(c_uint, @bitCast(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))))) >= @as(c_uint, @bitCast(JS_TAG_FIRST))) {
var p: [*c]JSRefCountHeader = @as([*c]JSRefCountHeader, @ptrCast(@alignCast(v.u.ptr)));
_ = &p;
if ((blk: {
const ref = &p.*.ref_count;
ref.* -= 1;
break :blk ref.*;
}) <= @as(c_int, 0)) {
__JS_FreeValueRT(rt, v);
}
}
}
pub fn JS_DupValue(arg_ctx: ?*JSContext, arg_v: JSValue) callconv(.c) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var v = arg_v;
_ = &v;
if (@as(c_uint, @bitCast(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))))) >= @as(c_uint, @bitCast(JS_TAG_FIRST))) {
var p: [*c]JSRefCountHeader = @as([*c]JSRefCountHeader, @ptrCast(@alignCast(v.u.ptr)));
_ = &p;
p.*.ref_count += 1;
}
return v;
}
pub fn JS_DupValueRT(arg_rt: ?*JSRuntime, arg_v: JSValue) callconv(.c) JSValue {
var rt = arg_rt;
_ = &rt;
var v = arg_v;
_ = &v;
if (@as(c_uint, @bitCast(@as(i32, @bitCast(@as(c_int, @truncate(v.tag)))))) >= @as(c_uint, @bitCast(JS_TAG_FIRST))) {
var p: [*c]JSRefCountHeader = @as([*c]JSRefCountHeader, @ptrCast(@alignCast(v.u.ptr)));
_ = &p;
p.*.ref_count += 1;
}
return v;
}
pub extern fn JS_StrictEq(ctx: ?*JSContext, op1: JSValue, op2: JSValue) c_int;
pub extern fn JS_SameValue(ctx: ?*JSContext, op1: JSValue, op2: JSValue) c_int;
pub extern fn JS_SameValueZero(ctx: ?*JSContext, op1: JSValue, op2: JSValue) c_int;
pub extern fn JS_ToBool(ctx: ?*JSContext, val: JSValue) c_int;
pub extern fn JS_ToInt32(ctx: ?*JSContext, pres: [*c]i32, val: JSValue) c_int;
pub fn JS_ToUint32(arg_ctx: ?*JSContext, arg_pres: [*c]u32, arg_val: JSValue) callconv(.c) c_int {
var ctx = arg_ctx;
_ = &ctx;
var pres = arg_pres;
_ = &pres;
var val = arg_val;
_ = &val;
return JS_ToInt32(ctx, @as([*c]i32, @ptrCast(@alignCast(pres))), val);
}
pub extern fn JS_ToInt64(ctx: ?*JSContext, pres: [*c]i64, val: JSValue) c_int;
pub extern fn JS_ToIndex(ctx: ?*JSContext, plen: [*c]u64, val: JSValue) c_int;
pub extern fn JS_ToFloat64(ctx: ?*JSContext, pres: [*c]f64, val: JSValue) c_int;
pub extern fn JS_ToBigInt64(ctx: ?*JSContext, pres: [*c]i64, val: JSValue) c_int;
pub extern fn JS_ToInt64Ext(ctx: ?*JSContext, pres: [*c]i64, val: JSValue) c_int;
pub extern fn JS_NewStringLen(ctx: ?*JSContext, str1: [*c]const u8, len1: usize) JSValue;
pub fn JS_NewString(arg_ctx: ?*JSContext, arg_str: [*c]const u8) callconv(.c) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var str = arg_str;
_ = &str;
return JS_NewStringLen(ctx, str, strlen(str));
}
pub extern fn JS_NewAtomString(ctx: ?*JSContext, str: [*c]const u8) JSValue;
pub extern fn JS_ToString(ctx: ?*JSContext, val: JSValue) JSValue;
pub extern fn JS_ToPropertyKey(ctx: ?*JSContext, val: JSValue) JSValue;
pub extern fn JS_ToCStringLen2(ctx: ?*JSContext, plen: [*c]usize, val1: JSValue, cesu8: c_int) [*c]const u8;
pub fn JS_ToCStringLen(arg_ctx: ?*JSContext, arg_plen: [*c]usize, arg_val1: JSValue) callconv(.c) [*c]const u8 {
var ctx = arg_ctx;
_ = &ctx;
var plen = arg_plen;
_ = &plen;
var val1 = arg_val1;
_ = &val1;
return JS_ToCStringLen2(ctx, plen, val1, @as(c_int, 0));
}
pub fn JS_ToCString(arg_ctx: ?*JSContext, arg_val1: JSValue) callconv(.c) [*c]const u8 {
var ctx = arg_ctx;
_ = &ctx;
var val1 = arg_val1;
_ = &val1;
return JS_ToCStringLen2(ctx, null, val1, @as(c_int, 0));
}
pub extern fn JS_FreeCString(ctx: ?*JSContext, ptr: [*c]const u8) void;
pub extern fn JS_NewObjectProtoClass(ctx: ?*JSContext, proto: JSValue, class_id: JSClassID) JSValue;
pub extern fn JS_NewObjectClass(ctx: ?*JSContext, class_id: c_int) JSValue;
pub extern fn JS_NewObjectProto(ctx: ?*JSContext, proto: JSValue) JSValue;
pub extern fn JS_NewObject(ctx: ?*JSContext) JSValue;
pub extern fn JS_IsFunction(ctx: ?*JSContext, val: JSValue) c_int;
pub extern fn JS_IsConstructor(ctx: ?*JSContext, val: JSValue) c_int;
pub extern fn JS_SetConstructorBit(ctx: ?*JSContext, func_obj: JSValue, val: c_int) c_int;
pub extern fn JS_NewArray(ctx: ?*JSContext) JSValue;
pub extern fn JS_IsArray(ctx: ?*JSContext, val: JSValue) c_int;
pub extern fn JS_NewDate(ctx: ?*JSContext, epoch_ms: f64) JSValue;
pub extern fn JS_GetPropertyInternal(ctx: ?*JSContext, obj: JSValue, prop: JSAtom, receiver: JSValue, throw_ref_error: c_int) JSValue;
pub inline fn JS_GetProperty(arg_ctx: ?*JSContext, arg_this_obj: JSValue, arg_prop: JSAtom) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var this_obj = arg_this_obj;
_ = &this_obj;
var prop = arg_prop;
_ = &prop;
return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, @as(c_int, 0));
}
pub extern fn JS_GetPropertyStr(ctx: ?*JSContext, this_obj: JSValue, prop: [*c]const u8) JSValue;
pub extern fn JS_GetPropertyUint32(ctx: ?*JSContext, this_obj: JSValue, idx: u32) JSValue;
pub extern fn JS_SetPropertyInternal(ctx: ?*JSContext, obj: JSValue, prop: JSAtom, val: JSValue, this_obj: JSValue, flags: c_int) c_int;
pub fn JS_SetProperty(arg_ctx: ?*JSContext, arg_this_obj: JSValue, arg_prop: JSAtom, arg_val: JSValue) callconv(.c) c_int {
var ctx = arg_ctx;
_ = &ctx;
var this_obj = arg_this_obj;
_ = &this_obj;
var prop = arg_prop;
_ = &prop;
var val = arg_val;
_ = &val;
return JS_SetPropertyInternal(ctx, this_obj, prop, val, this_obj, @as(c_int, 1) << @intCast(14));
}
pub extern fn JS_SetPropertyUint32(ctx: ?*JSContext, this_obj: JSValue, idx: u32, val: JSValue) c_int;
pub extern fn JS_SetPropertyInt64(ctx: ?*JSContext, this_obj: JSValue, idx: i64, val: JSValue) c_int;
pub extern fn JS_SetPropertyStr(ctx: ?*JSContext, this_obj: JSValue, prop: [*c]const u8, val: JSValue) c_int;
pub extern fn JS_HasProperty(ctx: ?*JSContext, this_obj: JSValue, prop: JSAtom) c_int;
pub extern fn JS_IsExtensible(ctx: ?*JSContext, obj: JSValue) c_int;
pub extern fn JS_PreventExtensions(ctx: ?*JSContext, obj: JSValue) c_int;
pub extern fn JS_DeleteProperty(ctx: ?*JSContext, obj: JSValue, prop: JSAtom, flags: c_int) c_int;
pub extern fn JS_SetPrototype(ctx: ?*JSContext, obj: JSValue, proto_val: JSValue) c_int;
pub extern fn JS_GetPrototype(ctx: ?*JSContext, val: JSValue) JSValue;
pub extern fn JS_GetOwnPropertyNames(ctx: ?*JSContext, ptab: [*c][*c]JSPropertyEnum, plen: [*c]u32, obj: JSValue, flags: c_int) c_int;
pub extern fn JS_FreePropertyEnum(ctx: ?*JSContext, tab: [*c]JSPropertyEnum, len: u32) void;
pub extern fn JS_GetOwnProperty(ctx: ?*JSContext, desc: [*c]JSPropertyDescriptor, obj: JSValue, prop: JSAtom) c_int;
pub extern fn JS_Call(ctx: ?*JSContext, func_obj: JSValue, this_obj: JSValue, argc: c_int, argv: [*c]JSValue) JSValue;
pub extern fn JS_Invoke(ctx: ?*JSContext, this_val: JSValue, atom: JSAtom, argc: c_int, argv: [*c]JSValue) JSValue;
pub extern fn JS_CallConstructor(ctx: ?*JSContext, func_obj: JSValue, argc: c_int, argv: [*c]JSValue) JSValue;
pub extern fn JS_CallConstructor2(ctx: ?*JSContext, func_obj: JSValue, new_target: JSValue, argc: c_int, argv: [*c]JSValue) JSValue;
pub extern fn JS_DetectModule(input: [*c]const u8, input_len: usize) c_int;
pub extern fn JS_Eval(ctx: ?*JSContext, input: [*c]const u8, input_len: usize, filename: [*c]const u8, eval_flags: c_int) JSValue;
pub extern fn JS_EvalThis(ctx: ?*JSContext, this_obj: JSValue, input: [*c]const u8, input_len: usize, filename: [*c]const u8, eval_flags: c_int) JSValue;
pub extern fn JS_GetGlobalObject(ctx: ?*JSContext) JSValue;
pub extern fn JS_IsInstanceOf(ctx: ?*JSContext, val: JSValue, obj: JSValue) c_int;
pub extern fn JS_DefineProperty(ctx: ?*JSContext, this_obj: JSValue, prop: JSAtom, val: JSValue, getter: JSValue, setter: JSValue, flags: c_int) c_int;
pub extern fn JS_DefinePropertyValue(ctx: ?*JSContext, this_obj: JSValue, prop: JSAtom, val: JSValue, flags: c_int) c_int;
pub extern fn JS_DefinePropertyValueUint32(ctx: ?*JSContext, this_obj: JSValue, idx: u32, val: JSValue, flags: c_int) c_int;
pub extern fn JS_DefinePropertyValueStr(ctx: ?*JSContext, this_obj: JSValue, prop: [*c]const u8, val: JSValue, flags: c_int) c_int;
pub extern fn JS_DefinePropertyGetSet(ctx: ?*JSContext, this_obj: JSValue, prop: JSAtom, getter: JSValue, setter: JSValue, flags: c_int) c_int;
pub extern fn JS_SetOpaque(obj: JSValue, @"opaque": ?*anyopaque) void;
pub extern fn JS_GetOpaque(obj: JSValue, class_id: JSClassID) ?*anyopaque;
pub extern fn JS_GetOpaque2(ctx: ?*JSContext, obj: JSValue, class_id: JSClassID) ?*anyopaque;
pub extern fn JS_GetAnyOpaque(obj: JSValue, class_id: [*c]JSClassID) ?*anyopaque;
pub extern fn JS_ParseJSON(ctx: ?*JSContext, buf: [*c]const u8, buf_len: usize, filename: [*c]const u8) JSValue;
pub extern fn JS_ParseJSON2(ctx: ?*JSContext, buf: [*c]const u8, buf_len: usize, filename: [*c]const u8, flags: c_int) JSValue;
pub extern fn JS_JSONStringify(ctx: ?*JSContext, obj: JSValue, replacer: JSValue, space0: JSValue) JSValue;
pub const JSFreeArrayBufferDataFunc = fn (?*JSRuntime, ?*anyopaque, ?*anyopaque) callconv(.c) void;
pub extern fn JS_NewArrayBuffer(ctx: ?*JSContext, buf: [*c]u8, len: usize, free_func: ?*const JSFreeArrayBufferDataFunc, @"opaque": ?*anyopaque, is_shared: c_int) JSValue;
pub extern fn JS_NewArrayBufferCopy(ctx: ?*JSContext, buf: [*c]const u8, len: usize) JSValue;
pub extern fn JS_DetachArrayBuffer(ctx: ?*JSContext, obj: JSValue) void;
pub extern fn JS_GetArrayBuffer(ctx: ?*JSContext, psize: [*c]usize, obj: JSValue) [*c]u8;
pub const JS_TYPED_ARRAY_UINT8C: c_int = 0;
pub const JS_TYPED_ARRAY_INT8: c_int = 1;
pub const JS_TYPED_ARRAY_UINT8: c_int = 2;
pub const JS_TYPED_ARRAY_INT16: c_int = 3;
pub const JS_TYPED_ARRAY_UINT16: c_int = 4;
pub const JS_TYPED_ARRAY_INT32: c_int = 5;
pub const JS_TYPED_ARRAY_UINT32: c_int = 6;
pub const JS_TYPED_ARRAY_BIG_INT64: c_int = 7;
pub const JS_TYPED_ARRAY_BIG_UINT64: c_int = 8;
pub const JS_TYPED_ARRAY_FLOAT16: c_int = 9;
pub const JS_TYPED_ARRAY_FLOAT32: c_int = 10;
pub const JS_TYPED_ARRAY_FLOAT64: c_int = 11;
pub const enum_JSTypedArrayEnum = c_uint;
pub const JSTypedArrayEnum = enum_JSTypedArrayEnum;
pub extern fn JS_NewTypedArray(ctx: ?*JSContext, argc: c_int, argv: [*c]JSValue, array_type: JSTypedArrayEnum) JSValue;
pub extern fn JS_GetTypedArrayBuffer(ctx: ?*JSContext, obj: JSValue, pbyte_offset: [*c]usize, pbyte_length: [*c]usize, pbytes_per_element: [*c]usize) JSValue;
pub const JSSharedArrayBufferFunctions = extern struct {
sab_alloc: ?*const fn (?*anyopaque, usize) callconv(.c) ?*anyopaque = @import("std").mem.zeroes(?*const fn (?*anyopaque, usize) callconv(.c) ?*anyopaque),
sab_free: ?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void = @import("std").mem.zeroes(?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void),
sab_dup: ?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void = @import("std").mem.zeroes(?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void),
sab_opaque: ?*anyopaque = @import("std").mem.zeroes(?*anyopaque),
};
pub extern fn JS_SetSharedArrayBufferFunctions(rt: ?*JSRuntime, sf: [*c]const JSSharedArrayBufferFunctions) void;
pub const JS_PROMISE_PENDING: c_int = 0;
pub const JS_PROMISE_FULFILLED: c_int = 1;
pub const JS_PROMISE_REJECTED: c_int = 2;
pub const enum_JSPromiseStateEnum = c_uint;
pub const JSPromiseStateEnum = enum_JSPromiseStateEnum;
pub extern fn JS_NewPromiseCapability(ctx: ?*JSContext, resolving_funcs: [*c]JSValue) JSValue;
pub extern fn JS_PromiseState(ctx: ?*JSContext, promise: JSValue) JSPromiseStateEnum;
pub extern fn JS_PromiseResult(ctx: ?*JSContext, promise: JSValue) JSValue;
pub const JSHostPromiseRejectionTracker = fn (?*JSContext, JSValue, JSValue, c_int, ?*anyopaque) callconv(.c) void;
pub extern fn JS_SetHostPromiseRejectionTracker(rt: ?*JSRuntime, cb: ?*const JSHostPromiseRejectionTracker, @"opaque": ?*anyopaque) void;
pub const JSInterruptHandler = fn (?*JSRuntime, ?*anyopaque) callconv(.c) c_int;
pub extern fn JS_SetInterruptHandler(rt: ?*JSRuntime, cb: ?*const JSInterruptHandler, @"opaque": ?*anyopaque) void;
pub extern fn JS_SetCanBlock(rt: ?*JSRuntime, can_block: c_int) void;
pub extern fn JS_SetStripInfo(rt: ?*JSRuntime, flags: c_int) void;
pub extern fn JS_GetStripInfo(rt: ?*JSRuntime) c_int;
pub extern fn JS_SetIsHTMLDDA(ctx: ?*JSContext, obj: JSValue) void;
pub const struct_JSModuleDef = opaque {};
pub const JSModuleDef = struct_JSModuleDef;
pub const JSModuleNormalizeFunc = fn (?*JSContext, [*c]const u8, [*c]const u8, ?*anyopaque) callconv(.c) [*c]u8;
pub const JSModuleLoaderFunc = fn (?*JSContext, [*c]const u8, ?*anyopaque) callconv(.c) ?*JSModuleDef;
pub const JSModuleLoaderFunc2 = fn (?*JSContext, [*c]const u8, ?*anyopaque, JSValue) callconv(.c) ?*JSModuleDef;
pub const JSModuleCheckSupportedImportAttributes = fn (?*JSContext, ?*anyopaque, JSValue) callconv(.c) c_int;
pub extern fn JS_SetModuleLoaderFunc(rt: ?*JSRuntime, module_normalize: ?*const JSModuleNormalizeFunc, module_loader: ?*const JSModuleLoaderFunc, @"opaque": ?*anyopaque) void;
pub extern fn JS_SetModuleLoaderFunc2(rt: ?*JSRuntime, module_normalize: ?*const JSModuleNormalizeFunc, module_loader: ?*const JSModuleLoaderFunc2, module_check_attrs: ?*const JSModuleCheckSupportedImportAttributes, @"opaque": ?*anyopaque) void;
pub extern fn JS_GetImportMeta(ctx: ?*JSContext, m: ?*JSModuleDef) JSValue;
pub extern fn JS_GetModuleName(ctx: ?*JSContext, m: ?*JSModuleDef) JSAtom;
pub extern fn JS_GetModuleNamespace(ctx: ?*JSContext, m: ?*JSModuleDef) JSValue;
pub const JSJobFunc = fn (?*JSContext, c_int, [*c]JSValue) callconv(.c) JSValue;
pub extern fn JS_EnqueueJob(ctx: ?*JSContext, job_func: ?*const JSJobFunc, argc: c_int, argv: [*c]JSValue) c_int;
pub extern fn JS_IsJobPending(rt: ?*JSRuntime) c_int;
pub extern fn JS_ExecutePendingJob(rt: ?*JSRuntime, pctx: [*c]?*JSContext) c_int;
pub extern fn JS_WriteObject(ctx: ?*JSContext, psize: [*c]usize, obj: JSValue, flags: c_int) [*c]u8;
pub extern fn JS_WriteObject2(ctx: ?*JSContext, psize: [*c]usize, obj: JSValue, flags: c_int, psab_tab: [*c][*c][*c]u8, psab_tab_len: [*c]usize) [*c]u8;
pub extern fn JS_ReadObject(ctx: ?*JSContext, buf: [*c]const u8, buf_len: usize, flags: c_int) JSValue;
pub extern fn JS_EvalFunction(ctx: ?*JSContext, fun_obj: JSValue) JSValue;
pub extern fn JS_ResolveModule(ctx: ?*JSContext, obj: JSValue) c_int;
pub extern fn JS_GetScriptOrModuleName(ctx: ?*JSContext, n_stack_levels: c_int) JSAtom;
pub extern fn JS_LoadModule(ctx: ?*JSContext, basename: [*c]const u8, filename: [*c]const u8) JSValue;
pub const JS_CFUNC_generic: c_int = 0;
pub const JS_CFUNC_generic_magic: c_int = 1;
pub const JS_CFUNC_constructor: c_int = 2;
pub const JS_CFUNC_constructor_magic: c_int = 3;
pub const JS_CFUNC_constructor_or_func: c_int = 4;
pub const JS_CFUNC_constructor_or_func_magic: c_int = 5;
pub const JS_CFUNC_f_f: c_int = 6;
pub const JS_CFUNC_f_f_f: c_int = 7;
pub const JS_CFUNC_getter: c_int = 8;
pub const JS_CFUNC_setter: c_int = 9;
pub const JS_CFUNC_getter_magic: c_int = 10;
pub const JS_CFUNC_setter_magic: c_int = 11;
pub const JS_CFUNC_iterator_next: c_int = 12;
pub const enum_JSCFunctionEnum = c_uint;
pub const JSCFunctionEnum = enum_JSCFunctionEnum;
pub const union_JSCFunctionType = extern union {
generic: ?*const JSCFunction,
generic_magic: ?*const fn (?*JSContext, JSValue, c_int, [*c]JSValue, c_int) callconv(.c) JSValue,
constructor: ?*const JSCFunction,
constructor_magic: ?*const fn (?*JSContext, JSValue, c_int, [*c]JSValue, c_int) callconv(.c) JSValue,
constructor_or_func: ?*const JSCFunction,
f_f: ?*const fn (f64) callconv(.c) f64,
f_f_f: ?*const fn (f64, f64) callconv(.c) f64,
getter: ?*const fn (?*JSContext, JSValue) callconv(.c) JSValue,
setter: ?*const fn (?*JSContext, JSValue, JSValue) callconv(.c) JSValue,
getter_magic: ?*const fn (?*JSContext, JSValue, c_int) callconv(.c) JSValue,
setter_magic: ?*const fn (?*JSContext, JSValue, JSValue, c_int) callconv(.c) JSValue,
iterator_next: ?*const fn (?*JSContext, JSValue, c_int, [*c]JSValue, [*c]c_int, c_int) callconv(.c) JSValue,
};
pub const JSCFunctionType = union_JSCFunctionType;
pub extern fn JS_NewCFunction2(ctx: ?*JSContext, func: ?*const JSCFunction, name: [*c]const u8, length: c_int, cproto: JSCFunctionEnum, magic: c_int) JSValue;
pub extern fn JS_NewCFunctionData(ctx: ?*JSContext, func: ?*const JSCFunctionData, length: c_int, magic: c_int, data_len: c_int, data: [*c]JSValue) JSValue;
pub fn JS_NewCFunction(arg_ctx: ?*JSContext, arg_func: ?*const JSCFunction, arg_name: [*c]const u8, arg_length: c_int) callconv(.c) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var func = arg_func;
_ = &func;
var name = arg_name;
_ = &name;
var length = arg_length;
_ = &length;
return JS_NewCFunction2(ctx, func, name, length, @as(c_uint, @bitCast(JS_CFUNC_generic)), @as(c_int, 0));
}
pub fn JS_NewCFunctionMagic(arg_ctx: ?*JSContext, arg_func: ?*const JSCFunctionMagic, arg_name: [*c]const u8, arg_length: c_int, arg_cproto: JSCFunctionEnum, arg_magic: c_int) callconv(.c) JSValue {
var ctx = arg_ctx;
_ = &ctx;
var func = arg_func;
_ = &func;
var name = arg_name;
_ = &name;
var length = arg_length;
_ = &length;
var cproto = arg_cproto;
_ = &cproto;
var magic = arg_magic;
_ = &magic;
var ft: JSCFunctionType = JSCFunctionType{
.generic_magic = func,
};
_ = &ft;
return JS_NewCFunction2(ctx, ft.generic, name, length, cproto, magic);
}
pub extern fn JS_SetConstructor(ctx: ?*JSContext, func_obj: JSValue, proto: JSValue) void;
const struct_unnamed_8 = extern struct {
length: u8 = @import("std").mem.zeroes(u8),
cproto: u8 = @import("std").mem.zeroes(u8),
cfunc: JSCFunctionType = @import("std").mem.zeroes(JSCFunctionType),
};
const struct_unnamed_9 = extern struct {
get: JSCFunctionType = @import("std").mem.zeroes(JSCFunctionType),
set: JSCFunctionType = @import("std").mem.zeroes(JSCFunctionType),
};
const struct_unnamed_10 = extern struct {
name: [*c]const u8 = @import("std").mem.zeroes([*c]const u8),
base: c_int = @import("std").mem.zeroes(c_int),
};
const struct_unnamed_11 = extern struct {
tab: [*c]const struct_JSCFunctionListEntry = @import("std").mem.zeroes([*c]const struct_JSCFunctionListEntry),
len: c_int = @import("std").mem.zeroes(c_int),
};
const union_unnamed_7 = extern union {
func: struct_unnamed_8,
getset: struct_unnamed_9,
alias: struct_unnamed_10,
prop_list: struct_unnamed_11,
str: [*c]const u8,
i32: i32,
i64: i64,
f64: f64,
};
pub const struct_JSCFunctionListEntry = extern struct {
name: [*c]const u8 = @import("std").mem.zeroes([*c]const u8),
prop_flags: u8 = @import("std").mem.zeroes(u8),
def_type: u8 = @import("std").mem.zeroes(u8),
magic: i16 = @import("std").mem.zeroes(i16),
u: union_unnamed_7 = @import("std").mem.zeroes(union_unnamed_7),
};
pub const JSCFunctionListEntry = struct_JSCFunctionListEntry;
pub extern fn JS_SetPropertyFunctionList(ctx: ?*JSContext, obj: JSValue, tab: [*c]const JSCFunctionListEntry, len: c_int) c_int;
pub const JSModuleInitFunc = fn (?*JSContext, ?*JSModuleDef) callconv(.c) c_int;
pub extern fn JS_NewCModule(ctx: ?*JSContext, name_str: [*c]const u8, func: ?*const JSModuleInitFunc) ?*JSModuleDef;
pub extern fn JS_AddModuleExport(ctx: ?*JSContext, m: ?*JSModuleDef, name_str: [*c]const u8) c_int;
pub extern fn JS_AddModuleExportList(ctx: ?*JSContext, m: ?*JSModuleDef, tab: [*c]const JSCFunctionListEntry, len: c_int) c_int;
pub extern fn JS_SetModuleExport(ctx: ?*JSContext, m: ?*JSModuleDef, export_name: [*c]const u8, val: JSValue) c_int;
pub extern fn JS_SetModuleExportList(ctx: ?*JSContext, m: ?*JSModuleDef, tab: [*c]const JSCFunctionListEntry, len: c_int) c_int;
pub extern fn JS_SetModulePrivateValue(ctx: ?*JSContext, m: ?*JSModuleDef, val: JSValue) c_int;
pub extern fn JS_GetModulePrivateValue(ctx: ?*JSContext, m: ?*JSModuleDef) JSValue;
// vendor/quickjs.h:1144:13: warning: struct demoted to opaque type - has bitfield
pub const JSPrintValueOptions = opaque {};
pub const JSPrintValueWrite = fn (?*anyopaque, [*c]const u8, usize) callconv(.c) void;
pub extern fn JS_PrintValueSetDefaultOptions(options: ?*JSPrintValueOptions) void;
pub extern fn JS_PrintValueRT(rt: ?*JSRuntime, write_func: ?*const JSPrintValueWrite, write_opaque: ?*anyopaque, val: JSValue, options: ?*const JSPrintValueOptions) void;
pub extern fn JS_PrintValue(ctx: ?*JSContext, write_func: ?*const JSPrintValueWrite, write_opaque: ?*anyopaque, val: JSValue, options: ?*const JSPrintValueOptions) void;
pub const JS_BOOL = c_int;
pub const JS_PTR64 = "";
pub inline fn JS_PTR64_DEF(a: anytype) @TypeOf(a) {
_ = &a;
return a;
}
pub const JS_LIMB_BITS = @as(c_int, 64);
pub const JS_SHORT_BIG_INT_BITS = JS_LIMB_BITS;
pub const JS_FLOAT64_NAN = @compileError("unable to translate macro: undefined identifier `NAN`");
pub const JSValueConst = JSValue;
pub inline fn JS_VALUE_GET_TAG(v: anytype) i32 {
_ = &v;
return @import("std").zig.c_translation.cast(i32, v.tag);
}
pub inline fn JS_VALUE_GET_NORM_TAG(v: anytype) @TypeOf(JS_VALUE_GET_TAG(v)) {
_ = &v;
return JS_VALUE_GET_TAG(v);
}
pub inline fn JS_VALUE_GET_INT(v: anytype) @TypeOf(v.u.int32) {
_ = &v;
return v.u.int32;
}
pub inline fn JS_VALUE_GET_BOOL(v: anytype) @TypeOf(v.u.int32) {
_ = &v;
return v.u.int32;
}
pub inline fn JS_VALUE_GET_FLOAT64(v: anytype) @TypeOf(v.u.float64) {
_ = &v;
return v.u.float64;
}
pub inline fn JS_VALUE_GET_SHORT_BIG_INT(v: anytype) @TypeOf(v.u.short_big_int) {
_ = &v;
return v.u.short_big_int;
}
pub inline fn JS_VALUE_GET_PTR(v: anytype) @TypeOf(v.u.ptr) {
_ = &v;
return v.u.ptr;
}
pub inline fn JS_MKVAL(tag: anytype, val: anytype) JSValue {
_ = &tag;
_ = &val;
return @import("std").mem.zeroInit(JSValue, .{ @import("std").mem.zeroInit(JSValueUnion, .{
.int32 = val,
}), tag });
}
pub inline fn JS_MKPTR(tag: anytype, p: anytype) JSValue {
_ = &tag;
_ = &p;
return @import("std").mem.zeroInit(JSValue, .{ @import("std").mem.zeroInit(JSValueUnion, .{
.ptr = p,
}), tag });
}
pub inline fn JS_TAG_IS_FLOAT64(tag: anytype) @TypeOf(@import("std").zig.c_translation.cast(c_uint, tag) == JS_TAG_FLOAT64) {
_ = &tag;
return @import("std").zig.c_translation.cast(c_uint, tag) == JS_TAG_FLOAT64;
}
pub const JS_NAN = @compileError("unable to translate C expr: expected '=' instead got '.'");
pub inline fn JS_VALUE_IS_BOTH_INT(v1: anytype, v2: anytype) @TypeOf((JS_VALUE_GET_TAG(v1) | JS_VALUE_GET_TAG(v2)) == @as(c_int, 0)) {
_ = &v1;
_ = &v2;
return (JS_VALUE_GET_TAG(v1) | JS_VALUE_GET_TAG(v2)) == @as(c_int, 0);
}
pub inline fn JS_VALUE_IS_BOTH_FLOAT(v1: anytype, v2: anytype) @TypeOf((JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v1)) != 0) and (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v2)) != 0)) {
_ = &v1;
_ = &v2;
return (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v1)) != 0) and (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v2)) != 0);
}
pub inline fn JS_VALUE_HAS_REF_COUNT(v: anytype) @TypeOf(@import("std").zig.c_translation.cast(c_uint, JS_VALUE_GET_TAG(v)) >= @import("std").zig.c_translation.cast(c_uint, JS_TAG_FIRST)) {
_ = &v;
return @import("std").zig.c_translation.cast(c_uint, JS_VALUE_GET_TAG(v)) >= @import("std").zig.c_translation.cast(c_uint, JS_TAG_FIRST);
}
pub const JS_NULL = JS_MKVAL(JS_TAG_NULL, @as(c_int, 0));
pub const JS_UNDEFINED = JS_MKVAL(JS_TAG_UNDEFINED, @as(c_int, 0));
pub const JS_FALSE = JS_MKVAL(JS_TAG_BOOL, @as(c_int, 0));
pub const JS_TRUE = JS_MKVAL(JS_TAG_BOOL, @as(c_int, 1));
pub const JS_EXCEPTION = JS_MKVAL(JS_TAG_EXCEPTION, @as(c_int, 0));
pub const JS_UNINITIALIZED = JS_MKVAL(JS_TAG_UNINITIALIZED, @as(c_int, 0));
pub const JS_PROP_CONFIGURABLE = @as(c_int, 1) << @as(c_int, 0);
pub const JS_PROP_WRITABLE = @as(c_int, 1) << @as(c_int, 1);
pub const JS_PROP_ENUMERABLE = @as(c_int, 1) << @as(c_int, 2);
pub const JS_PROP_C_W_E = (JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE) | JS_PROP_ENUMERABLE;
pub const JS_PROP_LENGTH = @as(c_int, 1) << @as(c_int, 3);
pub const JS_PROP_TMASK = @as(c_int, 3) << @as(c_int, 4);
pub const JS_PROP_NORMAL = @as(c_int, 0) << @as(c_int, 4);
pub const JS_PROP_GETSET = @as(c_int, 1) << @as(c_int, 4);
pub const JS_PROP_VARREF = @as(c_int, 2) << @as(c_int, 4);
pub const JS_PROP_AUTOINIT = @as(c_int, 3) << @as(c_int, 4);
pub const JS_PROP_HAS_SHIFT = @as(c_int, 8);
pub const JS_PROP_HAS_CONFIGURABLE = @as(c_int, 1) << @as(c_int, 8);
pub const JS_PROP_HAS_WRITABLE = @as(c_int, 1) << @as(c_int, 9);
pub const JS_PROP_HAS_ENUMERABLE = @as(c_int, 1) << @as(c_int, 10);
pub const JS_PROP_HAS_GET = @as(c_int, 1) << @as(c_int, 11);
pub const JS_PROP_HAS_SET = @as(c_int, 1) << @as(c_int, 12);
pub const JS_PROP_HAS_VALUE = @as(c_int, 1) << @as(c_int, 13);
pub const JS_PROP_THROW = @as(c_int, 1) << @as(c_int, 14);
pub const JS_PROP_THROW_STRICT = @as(c_int, 1) << @as(c_int, 15);
pub const JS_PROP_NO_ADD = @as(c_int, 1) << @as(c_int, 16);
pub const JS_PROP_NO_EXOTIC = @as(c_int, 1) << @as(c_int, 17);
pub const JS_DEFAULT_STACK_SIZE = @as(c_int, 1024) * @as(c_int, 1024);
pub const JS_EVAL_TYPE_GLOBAL = @as(c_int, 0) << @as(c_int, 0);
pub const JS_EVAL_TYPE_MODULE = @as(c_int, 1) << @as(c_int, 0);
pub const JS_EVAL_TYPE_DIRECT = @as(c_int, 2) << @as(c_int, 0);
pub const JS_EVAL_TYPE_INDIRECT = @as(c_int, 3) << @as(c_int, 0);
pub const JS_EVAL_TYPE_MASK = @as(c_int, 3) << @as(c_int, 0);
pub const JS_EVAL_FLAG_STRICT = @as(c_int, 1) << @as(c_int, 3);
pub const JS_EVAL_FLAG_COMPILE_ONLY = @as(c_int, 1) << @as(c_int, 5);
pub const JS_EVAL_FLAG_BACKTRACE_BARRIER = @as(c_int, 1) << @as(c_int, 6);
pub const JS_EVAL_FLAG_ASYNC = @as(c_int, 1) << @as(c_int, 7);
pub const JS_ATOM_NULL = @as(c_int, 0);
pub const JS_CALL_FLAG_CONSTRUCTOR = @as(c_int, 1) << @as(c_int, 0);
pub const JS_INVALID_CLASS_ID = @as(c_int, 0);
pub const JS_GPN_STRING_MASK = @as(c_int, 1) << @as(c_int, 0);
pub const JS_GPN_SYMBOL_MASK = @as(c_int, 1) << @as(c_int, 1);
pub const JS_GPN_PRIVATE_MASK = @as(c_int, 1) << @as(c_int, 2);
pub const JS_GPN_ENUM_ONLY = @as(c_int, 1) << @as(c_int, 4);
pub const JS_GPN_SET_ENUM = @as(c_int, 1) << @as(c_int, 5);
pub const JS_PARSE_JSON_EXT = @as(c_int, 1) << @as(c_int, 0);
pub const JS_STRIP_SOURCE = @as(c_int, 1) << @as(c_int, 0);
pub const JS_STRIP_DEBUG = @as(c_int, 1) << @as(c_int, 1);
pub const JS_WRITE_OBJ_BYTECODE = @as(c_int, 1) << @as(c_int, 0);
pub const JS_WRITE_OBJ_BSWAP = @as(c_int, 1) << @as(c_int, 1);
pub const JS_WRITE_OBJ_SAB = @as(c_int, 1) << @as(c_int, 2);
pub const JS_WRITE_OBJ_REFERENCE = @as(c_int, 1) << @as(c_int, 3);
pub const JS_READ_OBJ_BYTECODE = @as(c_int, 1) << @as(c_int, 0);
pub const JS_READ_OBJ_ROM_DATA = @as(c_int, 1) << @as(c_int, 1);
pub const JS_READ_OBJ_SAB = @as(c_int, 1) << @as(c_int, 2);
pub const JS_READ_OBJ_REFERENCE = @as(c_int, 1) << @as(c_int, 3);
pub const JS_DEF_CFUNC = @as(c_int, 0);
pub const JS_DEF_CGETSET = @as(c_int, 1);
pub const JS_DEF_CGETSET_MAGIC = @as(c_int, 2);
pub const JS_DEF_PROP_STRING = @as(c_int, 3);
pub const JS_DEF_PROP_INT32 = @as(c_int, 4);
pub const JS_DEF_PROP_INT64 = @as(c_int, 5);
pub const JS_DEF_PROP_DOUBLE = @as(c_int, 6);
pub const JS_DEF_PROP_UNDEFINED = @as(c_int, 7);
pub const JS_DEF_OBJECT = @as(c_int, 8);
pub const JS_DEF_ALIAS = @as(c_int, 9);

1218
packages/js/src/root.zig Normal file

File diff suppressed because it is too large Load Diff

22
packages/js/vendor/LICENSE vendored Normal file
View File

@@ -0,0 +1,22 @@
QuickJS Javascript Engine
Copyright (c) 2017-2021 Fabrice Bellard
Copyright (c) 2017-2021 Charlie Gordon
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

1
packages/js/vendor/VERSION vendored Normal file
View File

@@ -0,0 +1 @@
2025-09-13

633
packages/js/vendor/cutils.c vendored Normal file
View File

@@ -0,0 +1,633 @@
/*
* C utilities
*
* Copyright (c) 2017 Fabrice Bellard
* Copyright (c) 2018 Charlie Gordon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "cutils.h"
void pstrcpy(char *buf, int buf_size, const char *str)
{
int c;
char *q = buf;
if (buf_size <= 0)
return;
for(;;) {
c = *str++;
if (c == 0 || q >= buf + buf_size - 1)
break;
*q++ = c;
}
*q = '\0';
}
/* strcat and truncate. */
char *pstrcat(char *buf, int buf_size, const char *s)
{
int len;
len = strlen(buf);
if (len < buf_size)
pstrcpy(buf + len, buf_size - len, s);
return buf;
}
int strstart(const char *str, const char *val, const char **ptr)
{
const char *p, *q;
p = str;
q = val;
while (*q != '\0') {
if (*p != *q)
return 0;
p++;
q++;
}
if (ptr)
*ptr = p;
return 1;
}
int has_suffix(const char *str, const char *suffix)
{
size_t len = strlen(str);
size_t slen = strlen(suffix);
return (len >= slen && !memcmp(str + len - slen, suffix, slen));
}
/* Dynamic buffer package */
static void *dbuf_default_realloc(void *opaque, void *ptr, size_t size)
{
return realloc(ptr, size);
}
void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func)
{
memset(s, 0, sizeof(*s));
if (!realloc_func)
realloc_func = dbuf_default_realloc;
s->opaque = opaque;
s->realloc_func = realloc_func;
}
void dbuf_init(DynBuf *s)
{
dbuf_init2(s, NULL, NULL);
}
/* return < 0 if error */
int dbuf_realloc(DynBuf *s, size_t new_size)
{
size_t size;
uint8_t *new_buf;
if (new_size > s->allocated_size) {
if (s->error)
return -1;
size = s->allocated_size * 3 / 2;
if (size > new_size)
new_size = size;
new_buf = s->realloc_func(s->opaque, s->buf, new_size);
if (!new_buf) {
s->error = TRUE;
return -1;
}
s->buf = new_buf;
s->allocated_size = new_size;
}
return 0;
}
int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len)
{
size_t end;
end = offset + len;
if (dbuf_realloc(s, end))
return -1;
memcpy(s->buf + offset, data, len);
if (end > s->size)
s->size = end;
return 0;
}
int dbuf_put(DynBuf *s, const uint8_t *data, size_t len)
{
if (unlikely((s->size + len) > s->allocated_size)) {
if (dbuf_realloc(s, s->size + len))
return -1;
}
memcpy_no_ub(s->buf + s->size, data, len);
s->size += len;
return 0;
}
int dbuf_put_self(DynBuf *s, size_t offset, size_t len)
{
if (unlikely((s->size + len) > s->allocated_size)) {
if (dbuf_realloc(s, s->size + len))
return -1;
}
memcpy(s->buf + s->size, s->buf + offset, len);
s->size += len;
return 0;
}
int dbuf_putc(DynBuf *s, uint8_t c)
{
return dbuf_put(s, &c, 1);
}
int dbuf_putstr(DynBuf *s, const char *str)
{
return dbuf_put(s, (const uint8_t *)str, strlen(str));
}
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
const char *fmt, ...)
{
va_list ap;
char buf[128];
int len;
va_start(ap, fmt);
len = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (len < 0)
return -1;
if (len < sizeof(buf)) {
/* fast case */
return dbuf_put(s, (uint8_t *)buf, len);
} else {
if (dbuf_realloc(s, s->size + len + 1))
return -1;
va_start(ap, fmt);
vsnprintf((char *)(s->buf + s->size), s->allocated_size - s->size,
fmt, ap);
va_end(ap);
s->size += len;
}
return 0;
}
void dbuf_free(DynBuf *s)
{
/* we test s->buf as a fail safe to avoid crashing if dbuf_free()
is called twice */
if (s->buf) {
s->realloc_func(s->opaque, s->buf, 0);
}
memset(s, 0, sizeof(*s));
}
/* Note: at most 31 bits are encoded. At most UTF8_CHAR_LEN_MAX bytes
are output. */
int unicode_to_utf8(uint8_t *buf, unsigned int c)
{
uint8_t *q = buf;
if (c < 0x80) {
*q++ = c;
} else {
if (c < 0x800) {
*q++ = (c >> 6) | 0xc0;
} else {
if (c < 0x10000) {
*q++ = (c >> 12) | 0xe0;
} else {
if (c < 0x00200000) {
*q++ = (c >> 18) | 0xf0;
} else {
if (c < 0x04000000) {
*q++ = (c >> 24) | 0xf8;
} else if (c < 0x80000000) {
*q++ = (c >> 30) | 0xfc;
*q++ = ((c >> 24) & 0x3f) | 0x80;
} else {
return 0;
}
*q++ = ((c >> 18) & 0x3f) | 0x80;
}
*q++ = ((c >> 12) & 0x3f) | 0x80;
}
*q++ = ((c >> 6) & 0x3f) | 0x80;
}
*q++ = (c & 0x3f) | 0x80;
}
return q - buf;
}
static const unsigned int utf8_min_code[5] = {
0x80, 0x800, 0x10000, 0x00200000, 0x04000000,
};
static const unsigned char utf8_first_code_mask[5] = {
0x1f, 0xf, 0x7, 0x3, 0x1,
};
/* return -1 if error. *pp is not updated in this case. max_len must
be >= 1. The maximum length for a UTF8 byte sequence is 6 bytes. */
int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp)
{
int l, c, b, i;
c = *p++;
if (c < 0x80) {
*pp = p;
return c;
}
switch(c) {
case 0xc0: case 0xc1: case 0xc2: case 0xc3:
case 0xc4: case 0xc5: case 0xc6: case 0xc7:
case 0xc8: case 0xc9: case 0xca: case 0xcb:
case 0xcc: case 0xcd: case 0xce: case 0xcf:
case 0xd0: case 0xd1: case 0xd2: case 0xd3:
case 0xd4: case 0xd5: case 0xd6: case 0xd7:
case 0xd8: case 0xd9: case 0xda: case 0xdb:
case 0xdc: case 0xdd: case 0xde: case 0xdf:
l = 1;
break;
case 0xe0: case 0xe1: case 0xe2: case 0xe3:
case 0xe4: case 0xe5: case 0xe6: case 0xe7:
case 0xe8: case 0xe9: case 0xea: case 0xeb:
case 0xec: case 0xed: case 0xee: case 0xef:
l = 2;
break;
case 0xf0: case 0xf1: case 0xf2: case 0xf3:
case 0xf4: case 0xf5: case 0xf6: case 0xf7:
l = 3;
break;
case 0xf8: case 0xf9: case 0xfa: case 0xfb:
l = 4;
break;
case 0xfc: case 0xfd:
l = 5;
break;
default:
return -1;
}
/* check that we have enough characters */
if (l > (max_len - 1))
return -1;
c &= utf8_first_code_mask[l - 1];
for(i = 0; i < l; i++) {
b = *p++;
if (b < 0x80 || b >= 0xc0)
return -1;
c = (c << 6) | (b & 0x3f);
}
if (c < utf8_min_code[l - 1])
return -1;
*pp = p;
return c;
}
#if 0
#if defined(EMSCRIPTEN) || defined(__ANDROID__)
static void *rqsort_arg;
static int (*rqsort_cmp)(const void *, const void *, void *);
static int rqsort_cmp2(const void *p1, const void *p2)
{
return rqsort_cmp(p1, p2, rqsort_arg);
}
/* not reentrant, but not needed with emscripten */
void rqsort(void *base, size_t nmemb, size_t size,
int (*cmp)(const void *, const void *, void *),
void *arg)
{
rqsort_arg = arg;
rqsort_cmp = cmp;
qsort(base, nmemb, size, rqsort_cmp2);
}
#endif
#else
typedef void (*exchange_f)(void *a, void *b, size_t size);
typedef int (*cmp_f)(const void *, const void *, void *opaque);
static void exchange_bytes(void *a, void *b, size_t size) {
uint8_t *ap = (uint8_t *)a;
uint8_t *bp = (uint8_t *)b;
while (size-- != 0) {
uint8_t t = *ap;
*ap++ = *bp;
*bp++ = t;
}
}
static void exchange_one_byte(void *a, void *b, size_t size) {
uint8_t *ap = (uint8_t *)a;
uint8_t *bp = (uint8_t *)b;
uint8_t t = *ap;
*ap = *bp;
*bp = t;
}
static void exchange_int16s(void *a, void *b, size_t size) {
uint16_t *ap = (uint16_t *)a;
uint16_t *bp = (uint16_t *)b;
for (size /= sizeof(uint16_t); size-- != 0;) {
uint16_t t = *ap;
*ap++ = *bp;
*bp++ = t;
}
}
static void exchange_one_int16(void *a, void *b, size_t size) {
uint16_t *ap = (uint16_t *)a;
uint16_t *bp = (uint16_t *)b;
uint16_t t = *ap;
*ap = *bp;
*bp = t;
}
static void exchange_int32s(void *a, void *b, size_t size) {
uint32_t *ap = (uint32_t *)a;
uint32_t *bp = (uint32_t *)b;
for (size /= sizeof(uint32_t); size-- != 0;) {
uint32_t t = *ap;
*ap++ = *bp;
*bp++ = t;
}
}
static void exchange_one_int32(void *a, void *b, size_t size) {
uint32_t *ap = (uint32_t *)a;
uint32_t *bp = (uint32_t *)b;
uint32_t t = *ap;
*ap = *bp;
*bp = t;
}
static void exchange_int64s(void *a, void *b, size_t size) {
uint64_t *ap = (uint64_t *)a;
uint64_t *bp = (uint64_t *)b;
for (size /= sizeof(uint64_t); size-- != 0;) {
uint64_t t = *ap;
*ap++ = *bp;
*bp++ = t;
}
}
static void exchange_one_int64(void *a, void *b, size_t size) {
uint64_t *ap = (uint64_t *)a;
uint64_t *bp = (uint64_t *)b;
uint64_t t = *ap;
*ap = *bp;
*bp = t;
}
static void exchange_int128s(void *a, void *b, size_t size) {
uint64_t *ap = (uint64_t *)a;
uint64_t *bp = (uint64_t *)b;
for (size /= sizeof(uint64_t) * 2; size-- != 0; ap += 2, bp += 2) {
uint64_t t = ap[0];
uint64_t u = ap[1];
ap[0] = bp[0];
ap[1] = bp[1];
bp[0] = t;
bp[1] = u;
}
}
static void exchange_one_int128(void *a, void *b, size_t size) {
uint64_t *ap = (uint64_t *)a;
uint64_t *bp = (uint64_t *)b;
uint64_t t = ap[0];
uint64_t u = ap[1];
ap[0] = bp[0];
ap[1] = bp[1];
bp[0] = t;
bp[1] = u;
}
static inline exchange_f exchange_func(const void *base, size_t size) {
switch (((uintptr_t)base | (uintptr_t)size) & 15) {
case 0:
if (size == sizeof(uint64_t) * 2)
return exchange_one_int128;
else
return exchange_int128s;
case 8:
if (size == sizeof(uint64_t))
return exchange_one_int64;
else
return exchange_int64s;
case 4:
case 12:
if (size == sizeof(uint32_t))
return exchange_one_int32;
else
return exchange_int32s;
case 2:
case 6:
case 10:
case 14:
if (size == sizeof(uint16_t))
return exchange_one_int16;
else
return exchange_int16s;
default:
if (size == 1)
return exchange_one_byte;
else
return exchange_bytes;
}
}
static void heapsortx(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)
{
uint8_t *basep = (uint8_t *)base;
size_t i, n, c, r;
exchange_f swap = exchange_func(base, size);
if (nmemb > 1) {
i = (nmemb / 2) * size;
n = nmemb * size;
while (i > 0) {
i -= size;
for (r = i; (c = r * 2 + size) < n; r = c) {
if (c < n - size && cmp(basep + c, basep + c + size, opaque) <= 0)
c += size;
if (cmp(basep + r, basep + c, opaque) > 0)
break;
swap(basep + r, basep + c, size);
}
}
for (i = n - size; i > 0; i -= size) {
swap(basep, basep + i, size);
for (r = 0; (c = r * 2 + size) < i; r = c) {
if (c < i - size && cmp(basep + c, basep + c + size, opaque) <= 0)
c += size;
if (cmp(basep + r, basep + c, opaque) > 0)
break;
swap(basep + r, basep + c, size);
}
}
}
}
static inline void *med3(void *a, void *b, void *c, cmp_f cmp, void *opaque)
{
return cmp(a, b, opaque) < 0 ?
(cmp(b, c, opaque) < 0 ? b : (cmp(a, c, opaque) < 0 ? c : a )) :
(cmp(b, c, opaque) > 0 ? b : (cmp(a, c, opaque) < 0 ? a : c ));
}
/* pointer based version with local stack and insertion sort threshhold */
void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)
{
struct { uint8_t *base; size_t count; int depth; } stack[50], *sp = stack;
uint8_t *ptr, *pi, *pj, *plt, *pgt, *top, *m;
size_t m4, i, lt, gt, span, span2;
int c, depth;
exchange_f swap = exchange_func(base, size);
exchange_f swap_block = exchange_func(base, size | 128);
if (nmemb < 2 || size <= 0)
return;
sp->base = (uint8_t *)base;
sp->count = nmemb;
sp->depth = 0;
sp++;
while (sp > stack) {
sp--;
ptr = sp->base;
nmemb = sp->count;
depth = sp->depth;
while (nmemb > 6) {
if (++depth > 50) {
/* depth check to ensure worst case logarithmic time */
heapsortx(ptr, nmemb, size, cmp, opaque);
nmemb = 0;
break;
}
/* select median of 3 from 1/4, 1/2, 3/4 positions */
/* should use median of 5 or 9? */
m4 = (nmemb >> 2) * size;
m = med3(ptr + m4, ptr + 2 * m4, ptr + 3 * m4, cmp, opaque);
swap(ptr, m, size); /* move the pivot to the start or the array */
i = lt = 1;
pi = plt = ptr + size;
gt = nmemb;
pj = pgt = top = ptr + nmemb * size;
for (;;) {
while (pi < pj && (c = cmp(ptr, pi, opaque)) >= 0) {
if (c == 0) {
swap(plt, pi, size);
lt++;
plt += size;
}
i++;
pi += size;
}
while (pi < (pj -= size) && (c = cmp(ptr, pj, opaque)) <= 0) {
if (c == 0) {
gt--;
pgt -= size;
swap(pgt, pj, size);
}
}
if (pi >= pj)
break;
swap(pi, pj, size);
i++;
pi += size;
}
/* array has 4 parts:
* from 0 to lt excluded: elements identical to pivot
* from lt to pi excluded: elements smaller than pivot
* from pi to gt excluded: elements greater than pivot
* from gt to n excluded: elements identical to pivot
*/
/* move elements identical to pivot in the middle of the array: */
/* swap values in ranges [0..lt[ and [i-lt..i[
swapping the smallest span between lt and i-lt is sufficient
*/
span = plt - ptr;
span2 = pi - plt;
lt = i - lt;
if (span > span2)
span = span2;
swap_block(ptr, pi - span, span);
/* swap values in ranges [gt..top[ and [i..top-(top-gt)[
swapping the smallest span between top-gt and gt-i is sufficient
*/
span = top - pgt;
span2 = pgt - pi;
pgt = top - span2;
gt = nmemb - (gt - i);
if (span > span2)
span = span2;
swap_block(pi, top - span, span);
/* now array has 3 parts:
* from 0 to lt excluded: elements smaller than pivot
* from lt to gt excluded: elements identical to pivot
* from gt to n excluded: elements greater than pivot
*/
/* stack the larger segment and keep processing the smaller one
to minimize stack use for pathological distributions */
if (lt > nmemb - gt) {
sp->base = ptr;
sp->count = lt;
sp->depth = depth;
sp++;
ptr = pgt;
nmemb -= gt;
} else {
sp->base = pgt;
sp->count = nmemb - gt;
sp->depth = depth;
sp++;
nmemb = lt;
}
}
/* Use insertion sort for small fragments */
for (pi = ptr + size, top = ptr + nmemb * size; pi < top; pi += size) {
for (pj = pi; pj > ptr && cmp(pj - size, pj, opaque) > 0; pj -= size)
swap(pj, pj - size, size);
}
}
}
#endif

423
packages/js/vendor/cutils.h vendored Normal file
View File

@@ -0,0 +1,423 @@
/*
* C utilities
*
* Copyright (c) 2017 Fabrice Bellard
* Copyright (c) 2018 Charlie Gordon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef CUTILS_H
#define CUTILS_H
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define force_inline inline __attribute__((always_inline))
#define no_inline __attribute__((noinline))
#define __maybe_unused __attribute__((unused))
#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)
#define stringify(s) tostring(s)
#define tostring(s) #s
#ifndef offsetof
#define offsetof(type, field) ((size_t) &((type *)0)->field)
#endif
#ifndef countof
#define countof(x) (sizeof(x) / sizeof((x)[0]))
#endif
#ifndef container_of
/* return the pointer of type 'type *' containing 'ptr' as field 'member' */
#define container_of(ptr, type, member) ((type *)((uint8_t *)(ptr) - offsetof(type, member)))
#endif
#if !defined(_MSC_VER) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define minimum_length(n) static n
#else
#define minimum_length(n) n
#endif
typedef int BOOL;
#ifndef FALSE
enum {
FALSE = 0,
TRUE = 1,
};
#endif
void pstrcpy(char *buf, int buf_size, const char *str);
char *pstrcat(char *buf, int buf_size, const char *s);
int strstart(const char *str, const char *val, const char **ptr);
int has_suffix(const char *str, const char *suffix);
/* Prevent UB when n == 0 and (src == NULL or dest == NULL) */
static inline void memcpy_no_ub(void *dest, const void *src, size_t n) {
if (n)
memcpy(dest, src, n);
}
static inline int max_int(int a, int b)
{
if (a > b)
return a;
else
return b;
}
static inline int min_int(int a, int b)
{
if (a < b)
return a;
else
return b;
}
static inline uint32_t max_uint32(uint32_t a, uint32_t b)
{
if (a > b)
return a;
else
return b;
}
static inline uint32_t min_uint32(uint32_t a, uint32_t b)
{
if (a < b)
return a;
else
return b;
}
static inline int64_t max_int64(int64_t a, int64_t b)
{
if (a > b)
return a;
else
return b;
}
static inline int64_t min_int64(int64_t a, int64_t b)
{
if (a < b)
return a;
else
return b;
}
/* WARNING: undefined if a = 0 */
static inline int clz32(unsigned int a)
{
return __builtin_clz(a);
}
/* WARNING: undefined if a = 0 */
static inline int clz64(uint64_t a)
{
return __builtin_clzll(a);
}
/* WARNING: undefined if a = 0 */
static inline int ctz32(unsigned int a)
{
return __builtin_ctz(a);
}
/* WARNING: undefined if a = 0 */
static inline int ctz64(uint64_t a)
{
return __builtin_ctzll(a);
}
struct __attribute__((packed)) packed_u64 {
uint64_t v;
};
struct __attribute__((packed)) packed_u32 {
uint32_t v;
};
struct __attribute__((packed)) packed_u16 {
uint16_t v;
};
static inline uint64_t get_u64(const uint8_t *tab)
{
return ((const struct packed_u64 *)tab)->v;
}
static inline int64_t get_i64(const uint8_t *tab)
{
return (int64_t)((const struct packed_u64 *)tab)->v;
}
static inline void put_u64(uint8_t *tab, uint64_t val)
{
((struct packed_u64 *)tab)->v = val;
}
static inline uint32_t get_u32(const uint8_t *tab)
{
return ((const struct packed_u32 *)tab)->v;
}
static inline int32_t get_i32(const uint8_t *tab)
{
return (int32_t)((const struct packed_u32 *)tab)->v;
}
static inline void put_u32(uint8_t *tab, uint32_t val)
{
((struct packed_u32 *)tab)->v = val;
}
static inline uint32_t get_u16(const uint8_t *tab)
{
return ((const struct packed_u16 *)tab)->v;
}
static inline int32_t get_i16(const uint8_t *tab)
{
return (int16_t)((const struct packed_u16 *)tab)->v;
}
static inline void put_u16(uint8_t *tab, uint16_t val)
{
((struct packed_u16 *)tab)->v = val;
}
static inline uint32_t get_u8(const uint8_t *tab)
{
return *tab;
}
static inline int32_t get_i8(const uint8_t *tab)
{
return (int8_t)*tab;
}
static inline void put_u8(uint8_t *tab, uint8_t val)
{
*tab = val;
}
#ifndef bswap16
static inline uint16_t bswap16(uint16_t x)
{
return (x >> 8) | (x << 8);
}
#endif
#ifndef bswap32
static inline uint32_t bswap32(uint32_t v)
{
return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) |
((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24);
}
#endif
#ifndef bswap64
static inline uint64_t bswap64(uint64_t v)
{
return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) |
((v & ((uint64_t)0xff << (6 * 8))) >> (5 * 8)) |
((v & ((uint64_t)0xff << (5 * 8))) >> (3 * 8)) |
((v & ((uint64_t)0xff << (4 * 8))) >> (1 * 8)) |
((v & ((uint64_t)0xff << (3 * 8))) << (1 * 8)) |
((v & ((uint64_t)0xff << (2 * 8))) << (3 * 8)) |
((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) |
((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8));
}
#endif
/* XXX: should take an extra argument to pass slack information to the caller */
typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size);
typedef struct DynBuf {
uint8_t *buf;
size_t size;
size_t allocated_size;
BOOL error; /* true if a memory allocation error occurred */
DynBufReallocFunc *realloc_func;
void *opaque; /* for realloc_func */
} DynBuf;
void dbuf_init(DynBuf *s);
void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func);
int dbuf_realloc(DynBuf *s, size_t new_size);
int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len);
int dbuf_put(DynBuf *s, const uint8_t *data, size_t len);
int dbuf_put_self(DynBuf *s, size_t offset, size_t len);
int dbuf_putc(DynBuf *s, uint8_t c);
int dbuf_putstr(DynBuf *s, const char *str);
static inline int dbuf_put_u16(DynBuf *s, uint16_t val)
{
return dbuf_put(s, (uint8_t *)&val, 2);
}
static inline int dbuf_put_u32(DynBuf *s, uint32_t val)
{
return dbuf_put(s, (uint8_t *)&val, 4);
}
static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
{
return dbuf_put(s, (uint8_t *)&val, 8);
}
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
const char *fmt, ...);
void dbuf_free(DynBuf *s);
static inline BOOL dbuf_error(DynBuf *s) {
return s->error;
}
static inline void dbuf_set_error(DynBuf *s)
{
s->error = TRUE;
}
#define UTF8_CHAR_LEN_MAX 6
int unicode_to_utf8(uint8_t *buf, unsigned int c);
int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp);
static inline BOOL is_surrogate(uint32_t c)
{
return (c >> 11) == (0xD800 >> 11); // 0xD800-0xDFFF
}
static inline BOOL is_hi_surrogate(uint32_t c)
{
return (c >> 10) == (0xD800 >> 10); // 0xD800-0xDBFF
}
static inline BOOL is_lo_surrogate(uint32_t c)
{
return (c >> 10) == (0xDC00 >> 10); // 0xDC00-0xDFFF
}
static inline uint32_t get_hi_surrogate(uint32_t c)
{
return (c >> 10) - (0x10000 >> 10) + 0xD800;
}
static inline uint32_t get_lo_surrogate(uint32_t c)
{
return (c & 0x3FF) | 0xDC00;
}
static inline uint32_t from_surrogate(uint32_t hi, uint32_t lo)
{
return 0x10000 + 0x400 * (hi - 0xD800) + (lo - 0xDC00);
}
static inline int from_hex(int c)
{
if (c >= '0' && c <= '9')
return c - '0';
else if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
else if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
else
return -1;
}
void rqsort(void *base, size_t nmemb, size_t size,
int (*cmp)(const void *, const void *, void *),
void *arg);
static inline uint64_t float64_as_uint64(double d)
{
union {
double d;
uint64_t u64;
} u;
u.d = d;
return u.u64;
}
static inline double uint64_as_float64(uint64_t u64)
{
union {
double d;
uint64_t u64;
} u;
u.u64 = u64;
return u.d;
}
static inline double fromfp16(uint16_t v)
{
double d;
uint32_t v1;
v1 = v & 0x7fff;
if (unlikely(v1 >= 0x7c00))
v1 += 0x1f8000; /* NaN or infinity */
d = uint64_as_float64(((uint64_t)(v >> 15) << 63) | ((uint64_t)v1 << (52 - 10)));
return d * 0x1p1008;
}
static inline uint16_t tofp16(double d)
{
uint64_t a, addend;
uint32_t v, sgn;
int shift;
a = float64_as_uint64(d);
sgn = a >> 63;
a = a & 0x7fffffffffffffff;
if (unlikely(a > 0x7ff0000000000000)) {
/* nan */
v = 0x7c01;
} else if (a < 0x3f10000000000000) { /* 0x1p-14 */
/* subnormal f16 number or zero */
if (a <= 0x3e60000000000000) { /* 0x1p-25 */
v = 0x0000; /* zero */
} else {
shift = 1051 - (a >> 52);
a = ((uint64_t)1 << 52) | (a & (((uint64_t)1 << 52) - 1));
addend = ((a >> shift) & 1) + (((uint64_t)1 << (shift - 1)) - 1);
v = (a + addend) >> shift;
}
} else {
/* normal number or infinity */
a -= 0x3f00000000000000; /* adjust the exponent */
/* round */
addend = ((a >> (52 - 10)) & 1) + (((uint64_t)1 << (52 - 11)) - 1);
v = (a + addend) >> (52 - 10);
/* overflow ? */
if (unlikely(v > 0x7c00))
v = 0x7c00;
}
return v | (sgn << 15);
}
static inline int isfp16nan(uint16_t v)
{
return (v & 0x7FFF) > 0x7C00;
}
static inline int isfp16zero(uint16_t v)
{
return (v & 0x7FFF) == 0;
}
#endif /* CUTILS_H */

1620
packages/js/vendor/dtoa.c vendored Normal file

File diff suppressed because it is too large Load Diff

83
packages/js/vendor/dtoa.h vendored Normal file
View File

@@ -0,0 +1,83 @@
/*
* Tiny float64 printing and parsing library
*
* Copyright (c) 2024 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
//#define JS_DTOA_DUMP_STATS
/* maximum number of digits for fixed and frac formats */
#define JS_DTOA_MAX_DIGITS 101
/* radix != 10 is only supported with flags = JS_DTOA_FORMAT_FREE */
/* use as many digits as necessary */
#define JS_DTOA_FORMAT_FREE (0 << 0)
/* use n_digits significant digits (1 <= n_digits <= JS_DTOA_MAX_DIGITS) */
#define JS_DTOA_FORMAT_FIXED (1 << 0)
/* force fractional format: [-]dd.dd with n_digits fractional digits.
0 <= n_digits <= JS_DTOA_MAX_DIGITS */
#define JS_DTOA_FORMAT_FRAC (2 << 0)
#define JS_DTOA_FORMAT_MASK (3 << 0)
/* select exponential notation either in fixed or free format */
#define JS_DTOA_EXP_AUTO (0 << 2)
#define JS_DTOA_EXP_ENABLED (1 << 2)
#define JS_DTOA_EXP_DISABLED (2 << 2)
#define JS_DTOA_EXP_MASK (3 << 2)
#define JS_DTOA_MINUS_ZERO (1 << 4) /* show the minus sign for -0 */
/* only accepts integers (no dot, no exponent) */
#define JS_ATOD_INT_ONLY (1 << 0)
/* accept Oo and Ob prefixes in addition to 0x prefix if radix = 0 */
#define JS_ATOD_ACCEPT_BIN_OCT (1 << 1)
/* accept O prefix as octal if radix == 0 and properly formed (Annex B) */
#define JS_ATOD_ACCEPT_LEGACY_OCTAL (1 << 2)
/* accept _ between digits as a digit separator */
#define JS_ATOD_ACCEPT_UNDERSCORES (1 << 3)
typedef struct {
uint64_t mem[37];
} JSDTOATempMem;
typedef struct {
uint64_t mem[27];
} JSATODTempMem;
/* return a maximum bound of the string length */
int js_dtoa_max_len(double d, int radix, int n_digits, int flags);
/* return the string length */
int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
JSDTOATempMem *tmp_mem);
double js_atod(const char *str, const char **pnext, int radix, int flags,
JSATODTempMem *tmp_mem);
#ifdef JS_DTOA_DUMP_STATS
void js_dtoa_dump_stats(void);
#endif
/* additional exported functions */
size_t u32toa(char *buf, uint32_t n);
size_t i32toa(char *buf, int32_t n);
size_t u64toa(char *buf, uint64_t n);
size_t i64toa(char *buf, int64_t n);
size_t u64toa_radix(char *buf, uint64_t n, unsigned int radix);
size_t i64toa_radix(char *buf, int64_t n, unsigned int radix);

67
packages/js/vendor/libregexp-opcode.h vendored Normal file
View File

@@ -0,0 +1,67 @@
/*
* Regular Expression Engine
*
* Copyright (c) 2017-2018 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifdef DEF
DEF(invalid, 1) /* never used */
DEF(char, 3)
DEF(char_i, 3)
DEF(char32, 5)
DEF(char32_i, 5)
DEF(dot, 1)
DEF(any, 1) /* same as dot but match any character including line terminator */
DEF(line_start, 1)
DEF(line_start_m, 1)
DEF(line_end, 1)
DEF(line_end_m, 1)
DEF(goto, 5)
DEF(split_goto_first, 5)
DEF(split_next_first, 5)
DEF(match, 1)
DEF(save_start, 2) /* save start position */
DEF(save_end, 2) /* save end position, must come after saved_start */
DEF(save_reset, 3) /* reset save positions */
DEF(loop, 5) /* decrement the top the stack and goto if != 0 */
DEF(push_i32, 5) /* push integer on the stack */
DEF(drop, 1)
DEF(word_boundary, 1)
DEF(word_boundary_i, 1)
DEF(not_word_boundary, 1)
DEF(not_word_boundary_i, 1)
DEF(back_reference, 2)
DEF(back_reference_i, 2) /* must come after */
DEF(backward_back_reference, 2) /* must come after */
DEF(backward_back_reference_i, 2) /* must come after */
DEF(range, 3) /* variable length */
DEF(range_i, 3) /* variable length */
DEF(range32, 3) /* variable length */
DEF(range32_i, 3) /* variable length */
DEF(lookahead, 5)
DEF(negative_lookahead, 5)
DEF(push_char_pos, 1) /* push the character position on the stack */
DEF(check_advance, 1) /* pop one stack element and check that it is different from the character position */
DEF(prev, 1) /* go to the previous char */
DEF(simple_greedy_quant, 17)
#endif /* DEF */

3280
packages/js/vendor/libregexp.c vendored Normal file

File diff suppressed because it is too large Load Diff

61
packages/js/vendor/libregexp.h vendored Normal file
View File

@@ -0,0 +1,61 @@
/*
* Regular Expression Engine
*
* Copyright (c) 2017-2018 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef LIBREGEXP_H
#define LIBREGEXP_H
#include <stddef.h>
#include <stdint.h>
#define LRE_FLAG_GLOBAL (1 << 0)
#define LRE_FLAG_IGNORECASE (1 << 1)
#define LRE_FLAG_MULTILINE (1 << 2)
#define LRE_FLAG_DOTALL (1 << 3)
#define LRE_FLAG_UNICODE (1 << 4)
#define LRE_FLAG_STICKY (1 << 5)
#define LRE_FLAG_INDICES (1 << 6) /* Unused by libregexp, just recorded. */
#define LRE_FLAG_NAMED_GROUPS (1 << 7) /* named groups are present in the regexp */
#define LRE_FLAG_UNICODE_SETS (1 << 8)
#define LRE_RET_MEMORY_ERROR (-1)
#define LRE_RET_TIMEOUT (-2)
uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,
const char *buf, size_t buf_len, int re_flags,
void *opaque);
int lre_get_capture_count(const uint8_t *bc_buf);
int lre_get_flags(const uint8_t *bc_buf);
const char *lre_get_groupnames(const uint8_t *bc_buf);
int lre_exec(uint8_t **capture,
const uint8_t *bc_buf, const uint8_t *cbuf, int cindex, int clen,
int cbuf_type, void *opaque);
int lre_parse_escape(const uint8_t **pp, int allow_utf16);
/* must be provided by the user, return non zero if overflow */
int lre_check_stack_overflow(void *opaque, size_t alloca_size);
/* must be provided by the user, return non zero if time out */
int lre_check_timeout(void *opaque);
void *lre_realloc(void *opaque, void *ptr, size_t size);
#endif /* LIBREGEXP_H */

5149
packages/js/vendor/libunicode-table.h vendored Normal file

File diff suppressed because it is too large Load Diff

2123
packages/js/vendor/libunicode.c vendored Normal file

File diff suppressed because it is too large Load Diff

186
packages/js/vendor/libunicode.h vendored Normal file
View File

@@ -0,0 +1,186 @@
/*
* Unicode utilities
*
* Copyright (c) 2017-2018 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef LIBUNICODE_H
#define LIBUNICODE_H
#include <stdint.h>
/* define it to include all the unicode tables (40KB larger) */
#define CONFIG_ALL_UNICODE
#define LRE_CC_RES_LEN_MAX 3
/* char ranges */
typedef struct {
int len; /* in points, always even */
int size;
uint32_t *points; /* points sorted by increasing value */
void *mem_opaque;
void *(*realloc_func)(void *opaque, void *ptr, size_t size);
} CharRange;
typedef enum {
CR_OP_UNION,
CR_OP_INTER,
CR_OP_XOR,
CR_OP_SUB,
} CharRangeOpEnum;
void cr_init(CharRange *cr, void *mem_opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size));
void cr_free(CharRange *cr);
int cr_realloc(CharRange *cr, int size);
int cr_copy(CharRange *cr, const CharRange *cr1);
static inline int cr_add_point(CharRange *cr, uint32_t v)
{
if (cr->len >= cr->size) {
if (cr_realloc(cr, cr->len + 1))
return -1;
}
cr->points[cr->len++] = v;
return 0;
}
static inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2)
{
if ((cr->len + 2) > cr->size) {
if (cr_realloc(cr, cr->len + 2))
return -1;
}
cr->points[cr->len++] = c1;
cr->points[cr->len++] = c2;
return 0;
}
int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
const uint32_t *b_pt, int b_len, int op);
int cr_op1(CharRange *cr, const uint32_t *b_pt, int b_len, int op);
static inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t c2)
{
uint32_t b_pt[2];
b_pt[0] = c1;
b_pt[1] = c2 + 1;
return cr_op1(cr, b_pt, 2, CR_OP_UNION);
}
int cr_invert(CharRange *cr);
int cr_regexp_canonicalize(CharRange *cr, int is_unicode);
typedef enum {
UNICODE_NFC,
UNICODE_NFD,
UNICODE_NFKC,
UNICODE_NFKD,
} UnicodeNormalizationEnum;
int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,
UnicodeNormalizationEnum n_type,
void *opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size));
/* Unicode character range functions */
int unicode_script(CharRange *cr, const char *script_name, int is_ext);
int unicode_general_category(CharRange *cr, const char *gc_name);
int unicode_prop(CharRange *cr, const char *prop_name);
typedef void UnicodeSequencePropCB(void *opaque, const uint32_t *buf, int len);
int unicode_sequence_prop(const char *prop_name, UnicodeSequencePropCB *cb, void *opaque,
CharRange *cr);
int lre_case_conv(uint32_t *res, uint32_t c, int conv_type);
int lre_canonicalize(uint32_t c, int is_unicode);
/* Code point type categories */
enum {
UNICODE_C_SPACE = (1 << 0),
UNICODE_C_DIGIT = (1 << 1),
UNICODE_C_UPPER = (1 << 2),
UNICODE_C_LOWER = (1 << 3),
UNICODE_C_UNDER = (1 << 4),
UNICODE_C_DOLLAR = (1 << 5),
UNICODE_C_XDIGIT = (1 << 6),
};
extern uint8_t const lre_ctype_bits[256];
/* zero or non-zero return value */
int lre_is_cased(uint32_t c);
int lre_is_case_ignorable(uint32_t c);
int lre_is_id_start(uint32_t c);
int lre_is_id_continue(uint32_t c);
static inline int lre_is_space_byte(uint8_t c) {
return lre_ctype_bits[c] & UNICODE_C_SPACE;
}
static inline int lre_is_id_start_byte(uint8_t c) {
return lre_ctype_bits[c] & (UNICODE_C_UPPER | UNICODE_C_LOWER |
UNICODE_C_UNDER | UNICODE_C_DOLLAR);
}
static inline int lre_is_id_continue_byte(uint8_t c) {
return lre_ctype_bits[c] & (UNICODE_C_UPPER | UNICODE_C_LOWER |
UNICODE_C_UNDER | UNICODE_C_DOLLAR |
UNICODE_C_DIGIT);
}
int lre_is_space_non_ascii(uint32_t c);
static inline int lre_is_space(uint32_t c) {
if (c < 256)
return lre_is_space_byte(c);
else
return lre_is_space_non_ascii(c);
}
static inline int lre_js_is_ident_first(uint32_t c) {
if (c < 128) {
return lre_is_id_start_byte(c);
} else {
#ifdef CONFIG_ALL_UNICODE
return lre_is_id_start(c);
#else
return !lre_is_space_non_ascii(c);
#endif
}
}
static inline int lre_js_is_ident_next(uint32_t c) {
if (c < 128) {
return lre_is_id_continue_byte(c);
} else {
/* ZWNJ and ZWJ are accepted in identifiers */
if (c >= 0x200C && c <= 0x200D)
return TRUE;
#ifdef CONFIG_ALL_UNICODE
return lre_is_id_continue(c);
#else
return !lre_is_space_non_ascii(c);
#endif
}
}
#endif /* LIBUNICODE_H */

99
packages/js/vendor/list.h vendored Normal file
View File

@@ -0,0 +1,99 @@
/*
* Linux klist like system
*
* Copyright (c) 2016-2017 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef LIST_H
#define LIST_H
#ifndef NULL
#include <stddef.h>
#endif
struct list_head {
struct list_head *prev;
struct list_head *next;
};
#define LIST_HEAD_INIT(el) { &(el), &(el) }
/* return the pointer of type 'type *' containing 'el' as field 'member' */
#define list_entry(el, type, member) container_of(el, type, member)
static inline void init_list_head(struct list_head *head)
{
head->prev = head;
head->next = head;
}
/* insert 'el' between 'prev' and 'next' */
static inline void __list_add(struct list_head *el,
struct list_head *prev, struct list_head *next)
{
prev->next = el;
el->prev = prev;
el->next = next;
next->prev = el;
}
/* add 'el' at the head of the list 'head' (= after element head) */
static inline void list_add(struct list_head *el, struct list_head *head)
{
__list_add(el, head, head->next);
}
/* add 'el' at the end of the list 'head' (= before element head) */
static inline void list_add_tail(struct list_head *el, struct list_head *head)
{
__list_add(el, head->prev, head);
}
static inline void list_del(struct list_head *el)
{
struct list_head *prev, *next;
prev = el->prev;
next = el->next;
prev->next = next;
next->prev = prev;
el->prev = NULL; /* fail safe */
el->next = NULL; /* fail safe */
}
static inline int list_empty(struct list_head *el)
{
return el->next == el;
}
#define list_for_each(el, head) \
for(el = (head)->next; el != (head); el = el->next)
#define list_for_each_safe(el, el1, head) \
for(el = (head)->next, el1 = el->next; el != (head); \
el = el1, el1 = el->next)
#define list_for_each_prev(el, head) \
for(el = (head)->prev; el != (head); el = el->prev)
#define list_for_each_prev_safe(el, el1, head) \
for(el = (head)->prev, el1 = el->prev; el != (head); \
el = el1, el1 = el->prev)
#endif /* LIST_H */

270
packages/js/vendor/quickjs-atom.h vendored Normal file
View File

@@ -0,0 +1,270 @@
/*
* QuickJS atom definitions
*
* Copyright (c) 2017-2018 Fabrice Bellard
* Copyright (c) 2017-2018 Charlie Gordon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifdef DEF
/* Note: first atoms are considered as keywords in the parser */
DEF(null, "null") /* must be first */
DEF(false, "false")
DEF(true, "true")
DEF(if, "if")
DEF(else, "else")
DEF(return, "return")
DEF(var, "var")
DEF(this, "this")
DEF(delete, "delete")
DEF(void, "void")
DEF(typeof, "typeof")
DEF(new, "new")
DEF(in, "in")
DEF(instanceof, "instanceof")
DEF(do, "do")
DEF(while, "while")
DEF(for, "for")
DEF(break, "break")
DEF(continue, "continue")
DEF(switch, "switch")
DEF(case, "case")
DEF(default, "default")
DEF(throw, "throw")
DEF(try, "try")
DEF(catch, "catch")
DEF(finally, "finally")
DEF(function, "function")
DEF(debugger, "debugger")
DEF(with, "with")
/* FutureReservedWord */
DEF(class, "class")
DEF(const, "const")
DEF(enum, "enum")
DEF(export, "export")
DEF(extends, "extends")
DEF(import, "import")
DEF(super, "super")
/* FutureReservedWords when parsing strict mode code */
DEF(implements, "implements")
DEF(interface, "interface")
DEF(let, "let")
DEF(package, "package")
DEF(private, "private")
DEF(protected, "protected")
DEF(public, "public")
DEF(static, "static")
DEF(yield, "yield")
DEF(await, "await")
/* empty string */
DEF(empty_string, "")
/* identifiers */
DEF(length, "length")
DEF(fileName, "fileName")
DEF(lineNumber, "lineNumber")
DEF(columnNumber, "columnNumber")
DEF(message, "message")
DEF(cause, "cause")
DEF(errors, "errors")
DEF(stack, "stack")
DEF(name, "name")
DEF(toString, "toString")
DEF(toLocaleString, "toLocaleString")
DEF(valueOf, "valueOf")
DEF(eval, "eval")
DEF(prototype, "prototype")
DEF(constructor, "constructor")
DEF(configurable, "configurable")
DEF(writable, "writable")
DEF(enumerable, "enumerable")
DEF(value, "value")
DEF(get, "get")
DEF(set, "set")
DEF(of, "of")
DEF(__proto__, "__proto__")
DEF(undefined, "undefined")
DEF(number, "number")
DEF(boolean, "boolean")
DEF(string, "string")
DEF(object, "object")
DEF(symbol, "symbol")
DEF(integer, "integer")
DEF(unknown, "unknown")
DEF(arguments, "arguments")
DEF(callee, "callee")
DEF(caller, "caller")
DEF(_eval_, "<eval>")
DEF(_ret_, "<ret>")
DEF(_var_, "<var>")
DEF(_arg_var_, "<arg_var>")
DEF(_with_, "<with>")
DEF(lastIndex, "lastIndex")
DEF(target, "target")
DEF(index, "index")
DEF(input, "input")
DEF(defineProperties, "defineProperties")
DEF(apply, "apply")
DEF(join, "join")
DEF(concat, "concat")
DEF(split, "split")
DEF(construct, "construct")
DEF(getPrototypeOf, "getPrototypeOf")
DEF(setPrototypeOf, "setPrototypeOf")
DEF(isExtensible, "isExtensible")
DEF(preventExtensions, "preventExtensions")
DEF(has, "has")
DEF(deleteProperty, "deleteProperty")
DEF(defineProperty, "defineProperty")
DEF(getOwnPropertyDescriptor, "getOwnPropertyDescriptor")
DEF(ownKeys, "ownKeys")
DEF(add, "add")
DEF(done, "done")
DEF(next, "next")
DEF(values, "values")
DEF(source, "source")
DEF(flags, "flags")
DEF(global, "global")
DEF(unicode, "unicode")
DEF(raw, "raw")
DEF(new_target, "new.target")
DEF(this_active_func, "this.active_func")
DEF(home_object, "<home_object>")
DEF(computed_field, "<computed_field>")
DEF(static_computed_field, "<static_computed_field>") /* must come after computed_fields */
DEF(class_fields_init, "<class_fields_init>")
DEF(brand, "<brand>")
DEF(hash_constructor, "#constructor")
DEF(as, "as")
DEF(from, "from")
DEF(meta, "meta")
DEF(_default_, "*default*")
DEF(_star_, "*")
DEF(Module, "Module")
DEF(then, "then")
DEF(resolve, "resolve")
DEF(reject, "reject")
DEF(promise, "promise")
DEF(proxy, "proxy")
DEF(revoke, "revoke")
DEF(async, "async")
DEF(exec, "exec")
DEF(groups, "groups")
DEF(indices, "indices")
DEF(status, "status")
DEF(reason, "reason")
DEF(globalThis, "globalThis")
DEF(bigint, "bigint")
DEF(minus_zero, "-0")
DEF(Infinity, "Infinity")
DEF(minus_Infinity, "-Infinity")
DEF(NaN, "NaN")
DEF(hasIndices, "hasIndices")
DEF(ignoreCase, "ignoreCase")
DEF(multiline, "multiline")
DEF(dotAll, "dotAll")
DEF(sticky, "sticky")
DEF(unicodeSets, "unicodeSets")
/* the following 3 atoms are only used with CONFIG_ATOMICS */
DEF(not_equal, "not-equal")
DEF(timed_out, "timed-out")
DEF(ok, "ok")
/* */
DEF(toJSON, "toJSON")
/* class names */
DEF(Object, "Object")
DEF(Array, "Array")
DEF(Error, "Error")
DEF(Number, "Number")
DEF(String, "String")
DEF(Boolean, "Boolean")
DEF(Symbol, "Symbol")
DEF(Arguments, "Arguments")
DEF(Math, "Math")
DEF(JSON, "JSON")
DEF(Date, "Date")
DEF(Function, "Function")
DEF(GeneratorFunction, "GeneratorFunction")
DEF(ForInIterator, "ForInIterator")
DEF(RegExp, "RegExp")
DEF(ArrayBuffer, "ArrayBuffer")
DEF(SharedArrayBuffer, "SharedArrayBuffer")
/* must keep same order as class IDs for typed arrays */
DEF(Uint8ClampedArray, "Uint8ClampedArray")
DEF(Int8Array, "Int8Array")
DEF(Uint8Array, "Uint8Array")
DEF(Int16Array, "Int16Array")
DEF(Uint16Array, "Uint16Array")
DEF(Int32Array, "Int32Array")
DEF(Uint32Array, "Uint32Array")
DEF(BigInt64Array, "BigInt64Array")
DEF(BigUint64Array, "BigUint64Array")
DEF(Float16Array, "Float16Array")
DEF(Float32Array, "Float32Array")
DEF(Float64Array, "Float64Array")
DEF(DataView, "DataView")
DEF(BigInt, "BigInt")
DEF(WeakRef, "WeakRef")
DEF(FinalizationRegistry, "FinalizationRegistry")
DEF(Map, "Map")
DEF(Set, "Set") /* Map + 1 */
DEF(WeakMap, "WeakMap") /* Map + 2 */
DEF(WeakSet, "WeakSet") /* Map + 3 */
DEF(Map_Iterator, "Map Iterator")
DEF(Set_Iterator, "Set Iterator")
DEF(Array_Iterator, "Array Iterator")
DEF(String_Iterator, "String Iterator")
DEF(RegExp_String_Iterator, "RegExp String Iterator")
DEF(Generator, "Generator")
DEF(Proxy, "Proxy")
DEF(Promise, "Promise")
DEF(PromiseResolveFunction, "PromiseResolveFunction")
DEF(PromiseRejectFunction, "PromiseRejectFunction")
DEF(AsyncFunction, "AsyncFunction")
DEF(AsyncFunctionResolve, "AsyncFunctionResolve")
DEF(AsyncFunctionReject, "AsyncFunctionReject")
DEF(AsyncGeneratorFunction, "AsyncGeneratorFunction")
DEF(AsyncGenerator, "AsyncGenerator")
DEF(EvalError, "EvalError")
DEF(RangeError, "RangeError")
DEF(ReferenceError, "ReferenceError")
DEF(SyntaxError, "SyntaxError")
DEF(TypeError, "TypeError")
DEF(URIError, "URIError")
DEF(InternalError, "InternalError")
/* private symbols */
DEF(Private_brand, "<brand>")
/* symbols */
DEF(Symbol_toPrimitive, "Symbol.toPrimitive")
DEF(Symbol_iterator, "Symbol.iterator")
DEF(Symbol_match, "Symbol.match")
DEF(Symbol_matchAll, "Symbol.matchAll")
DEF(Symbol_replace, "Symbol.replace")
DEF(Symbol_search, "Symbol.search")
DEF(Symbol_split, "Symbol.split")
DEF(Symbol_toStringTag, "Symbol.toStringTag")
DEF(Symbol_isConcatSpreadable, "Symbol.isConcatSpreadable")
DEF(Symbol_hasInstance, "Symbol.hasInstance")
DEF(Symbol_species, "Symbol.species")
DEF(Symbol_unscopables, "Symbol.unscopables")
DEF(Symbol_asyncIterator, "Symbol.asyncIterator")
#endif /* DEF */

4342
packages/js/vendor/quickjs-libc.c vendored Normal file

File diff suppressed because it is too large Load Diff

66
packages/js/vendor/quickjs-libc.h vendored Normal file
View File

@@ -0,0 +1,66 @@
/*
* QuickJS C library
*
* Copyright (c) 2017-2018 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef QUICKJS_LIBC_H
#define QUICKJS_LIBC_H
#include <stdio.h>
#include <stdlib.h>
#include "quickjs.h"
#ifdef __cplusplus
extern "C" {
#endif
JSModuleDef *js_init_module_std(JSContext *ctx, const char *module_name);
JSModuleDef *js_init_module_os(JSContext *ctx, const char *module_name);
void js_std_add_helpers(JSContext *ctx, int argc, char **argv);
void js_std_loop(JSContext *ctx);
JSValue js_std_await(JSContext *ctx, JSValue obj);
void js_std_init_handlers(JSRuntime *rt);
void js_std_free_handlers(JSRuntime *rt);
void js_std_dump_error(JSContext *ctx);
uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename);
int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
JS_BOOL use_realpath, JS_BOOL is_main);
int js_module_test_json(JSContext *ctx, JSValueConst attributes);
int js_module_check_attributes(JSContext *ctx, void *opaque, JSValueConst attributes);
JSModuleDef *js_module_loader(JSContext *ctx,
const char *module_name, void *opaque,
JSValueConst attributes);
void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len,
int flags);
void js_std_eval_binary_json_module(JSContext *ctx,
const uint8_t *buf, size_t buf_len,
const char *module_name);
void js_std_promise_rejection_tracker(JSContext *ctx, JSValueConst promise,
JSValueConst reason,
JS_BOOL is_handled, void *opaque);
void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt));
#ifdef __cplusplus
} /* extern "C" { */
#endif
#endif /* QUICKJS_LIBC_H */

370
packages/js/vendor/quickjs-opcode.h vendored Normal file
View File

@@ -0,0 +1,370 @@
/*
* QuickJS opcode definitions
*
* Copyright (c) 2017-2018 Fabrice Bellard
* Copyright (c) 2017-2018 Charlie Gordon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifdef FMT
FMT(none)
FMT(none_int)
FMT(none_loc)
FMT(none_arg)
FMT(none_var_ref)
FMT(u8)
FMT(i8)
FMT(loc8)
FMT(const8)
FMT(label8)
FMT(u16)
FMT(i16)
FMT(label16)
FMT(npop)
FMT(npopx)
FMT(npop_u16)
FMT(loc)
FMT(arg)
FMT(var_ref)
FMT(u32)
FMT(i32)
FMT(const)
FMT(label)
FMT(atom)
FMT(atom_u8)
FMT(atom_u16)
FMT(atom_label_u8)
FMT(atom_label_u16)
FMT(label_u16)
#undef FMT
#endif /* FMT */
#ifdef DEF
#ifndef def
#define def(id, size, n_pop, n_push, f) DEF(id, size, n_pop, n_push, f)
#endif
DEF(invalid, 1, 0, 0, none) /* never emitted */
/* push values */
DEF( push_i32, 5, 0, 1, i32)
DEF( push_const, 5, 0, 1, const)
DEF( fclosure, 5, 0, 1, const) /* must follow push_const */
DEF(push_atom_value, 5, 0, 1, atom)
DEF( private_symbol, 5, 0, 1, atom)
DEF( undefined, 1, 0, 1, none)
DEF( null, 1, 0, 1, none)
DEF( push_this, 1, 0, 1, none) /* only used at the start of a function */
DEF( push_false, 1, 0, 1, none)
DEF( push_true, 1, 0, 1, none)
DEF( object, 1, 0, 1, none)
DEF( special_object, 2, 0, 1, u8) /* only used at the start of a function */
DEF( rest, 3, 0, 1, u16) /* only used at the start of a function */
DEF( drop, 1, 1, 0, none) /* a -> */
DEF( nip, 1, 2, 1, none) /* a b -> b */
DEF( nip1, 1, 3, 2, none) /* a b c -> b c */
DEF( dup, 1, 1, 2, none) /* a -> a a */
DEF( dup1, 1, 2, 3, none) /* a b -> a a b */
DEF( dup2, 1, 2, 4, none) /* a b -> a b a b */
DEF( dup3, 1, 3, 6, none) /* a b c -> a b c a b c */
DEF( insert2, 1, 2, 3, none) /* obj a -> a obj a (dup_x1) */
DEF( insert3, 1, 3, 4, none) /* obj prop a -> a obj prop a (dup_x2) */
DEF( insert4, 1, 4, 5, none) /* this obj prop a -> a this obj prop a */
DEF( perm3, 1, 3, 3, none) /* obj a b -> a obj b */
DEF( perm4, 1, 4, 4, none) /* obj prop a b -> a obj prop b */
DEF( perm5, 1, 5, 5, none) /* this obj prop a b -> a this obj prop b */
DEF( swap, 1, 2, 2, none) /* a b -> b a */
DEF( swap2, 1, 4, 4, none) /* a b c d -> c d a b */
DEF( rot3l, 1, 3, 3, none) /* x a b -> a b x */
DEF( rot3r, 1, 3, 3, none) /* a b x -> x a b */
DEF( rot4l, 1, 4, 4, none) /* x a b c -> a b c x */
DEF( rot5l, 1, 5, 5, none) /* x a b c d -> a b c d x */
DEF(call_constructor, 3, 2, 1, npop) /* func new.target args -> ret. arguments are not counted in n_pop */
DEF( call, 3, 1, 1, npop) /* arguments are not counted in n_pop */
DEF( tail_call, 3, 1, 0, npop) /* arguments are not counted in n_pop */
DEF( call_method, 3, 2, 1, npop) /* arguments are not counted in n_pop */
DEF(tail_call_method, 3, 2, 0, npop) /* arguments are not counted in n_pop */
DEF( array_from, 3, 0, 1, npop) /* arguments are not counted in n_pop */
DEF( apply, 3, 3, 1, u16)
DEF( return, 1, 1, 0, none)
DEF( return_undef, 1, 0, 0, none)
DEF(check_ctor_return, 1, 1, 2, none)
DEF( check_ctor, 1, 0, 0, none)
DEF( init_ctor, 1, 0, 1, none)
DEF( check_brand, 1, 2, 2, none) /* this_obj func -> this_obj func */
DEF( add_brand, 1, 2, 0, none) /* this_obj home_obj -> */
DEF( return_async, 1, 1, 0, none)
DEF( throw, 1, 1, 0, none)
DEF( throw_error, 6, 0, 0, atom_u8)
DEF( eval, 5, 1, 1, npop_u16) /* func args... -> ret_val */
DEF( apply_eval, 3, 2, 1, u16) /* func array -> ret_eval */
DEF( regexp, 1, 2, 1, none) /* create a RegExp object from the pattern and a
bytecode string */
DEF( get_super, 1, 1, 1, none)
DEF( import, 1, 2, 1, none) /* dynamic module import */
DEF( check_var, 5, 0, 1, atom) /* check if a variable exists */
DEF( get_var_undef, 5, 0, 1, atom) /* push undefined if the variable does not exist */
DEF( get_var, 5, 0, 1, atom) /* throw an exception if the variable does not exist */
DEF( put_var, 5, 1, 0, atom) /* must come after get_var */
DEF( put_var_init, 5, 1, 0, atom) /* must come after put_var. Used to initialize a global lexical variable */
DEF( put_var_strict, 5, 2, 0, atom) /* for strict mode variable write */
DEF( get_ref_value, 1, 2, 3, none)
DEF( put_ref_value, 1, 3, 0, none)
DEF( define_var, 6, 0, 0, atom_u8)
DEF(check_define_var, 6, 0, 0, atom_u8)
DEF( define_func, 6, 1, 0, atom_u8)
DEF( get_field, 5, 1, 1, atom)
DEF( get_field2, 5, 1, 2, atom)
DEF( put_field, 5, 2, 0, atom)
DEF( get_private_field, 1, 2, 1, none) /* obj prop -> value */
DEF( put_private_field, 1, 3, 0, none) /* obj value prop -> */
DEF(define_private_field, 1, 3, 1, none) /* obj prop value -> obj */
DEF( get_array_el, 1, 2, 1, none)
DEF( get_array_el2, 1, 2, 2, none) /* obj prop -> obj value */
DEF( get_array_el3, 1, 2, 3, none) /* obj prop -> obj prop1 value */
DEF( put_array_el, 1, 3, 0, none)
DEF(get_super_value, 1, 3, 1, none) /* this obj prop -> value */
DEF(put_super_value, 1, 4, 0, none) /* this obj prop value -> */
DEF( define_field, 5, 2, 1, atom)
DEF( set_name, 5, 1, 1, atom)
DEF(set_name_computed, 1, 2, 2, none)
DEF( set_proto, 1, 2, 1, none)
DEF(set_home_object, 1, 2, 2, none)
DEF(define_array_el, 1, 3, 2, none)
DEF( append, 1, 3, 2, none) /* append enumerated object, update length */
DEF(copy_data_properties, 2, 3, 3, u8)
DEF( define_method, 6, 2, 1, atom_u8)
DEF(define_method_computed, 2, 3, 1, u8) /* must come after define_method */
DEF( define_class, 6, 2, 2, atom_u8) /* parent ctor -> ctor proto */
DEF( define_class_computed, 6, 3, 3, atom_u8) /* field_name parent ctor -> field_name ctor proto (class with computed name) */
DEF( get_loc, 3, 0, 1, loc)
DEF( put_loc, 3, 1, 0, loc) /* must come after get_loc */
DEF( set_loc, 3, 1, 1, loc) /* must come after put_loc */
DEF( get_arg, 3, 0, 1, arg)
DEF( put_arg, 3, 1, 0, arg) /* must come after get_arg */
DEF( set_arg, 3, 1, 1, arg) /* must come after put_arg */
DEF( get_var_ref, 3, 0, 1, var_ref)
DEF( put_var_ref, 3, 1, 0, var_ref) /* must come after get_var_ref */
DEF( set_var_ref, 3, 1, 1, var_ref) /* must come after put_var_ref */
DEF(set_loc_uninitialized, 3, 0, 0, loc)
DEF( get_loc_check, 3, 0, 1, loc)
DEF( put_loc_check, 3, 1, 0, loc) /* must come after get_loc_check */
DEF( put_loc_check_init, 3, 1, 0, loc)
DEF(get_loc_checkthis, 3, 0, 1, loc)
DEF(get_var_ref_check, 3, 0, 1, var_ref)
DEF(put_var_ref_check, 3, 1, 0, var_ref) /* must come after get_var_ref_check */
DEF(put_var_ref_check_init, 3, 1, 0, var_ref)
DEF( close_loc, 3, 0, 0, loc)
DEF( if_false, 5, 1, 0, label)
DEF( if_true, 5, 1, 0, label) /* must come after if_false */
DEF( goto, 5, 0, 0, label) /* must come after if_true */
DEF( catch, 5, 0, 1, label)
DEF( gosub, 5, 0, 0, label) /* used to execute the finally block */
DEF( ret, 1, 1, 0, none) /* used to return from the finally block */
DEF( nip_catch, 1, 2, 1, none) /* catch ... a -> a */
DEF( to_object, 1, 1, 1, none)
//DEF( to_string, 1, 1, 1, none)
DEF( to_propkey, 1, 1, 1, none)
DEF( with_get_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
DEF( with_put_var, 10, 2, 1, atom_label_u8) /* must be in the same order as scope_xxx */
DEF(with_delete_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
DEF( with_make_ref, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
DEF( with_get_ref, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */
DEF( make_loc_ref, 7, 0, 2, atom_u16)
DEF( make_arg_ref, 7, 0, 2, atom_u16)
DEF(make_var_ref_ref, 7, 0, 2, atom_u16)
DEF( make_var_ref, 5, 0, 2, atom)
DEF( for_in_start, 1, 1, 1, none)
DEF( for_of_start, 1, 1, 3, none)
DEF(for_await_of_start, 1, 1, 3, none)
DEF( for_in_next, 1, 1, 3, none)
DEF( for_of_next, 2, 3, 5, u8)
DEF(for_await_of_next, 1, 3, 4, none) /* iter next catch_offset -> iter next catch_offset obj */
DEF(iterator_check_object, 1, 1, 1, none)
DEF(iterator_get_value_done, 1, 2, 3, none) /* catch_offset obj -> catch_offset value done */
DEF( iterator_close, 1, 3, 0, none)
DEF( iterator_next, 1, 4, 4, none)
DEF( iterator_call, 2, 4, 5, u8)
DEF( initial_yield, 1, 0, 0, none)
DEF( yield, 1, 1, 2, none)
DEF( yield_star, 1, 1, 2, none)
DEF(async_yield_star, 1, 1, 2, none)
DEF( await, 1, 1, 1, none)
/* arithmetic/logic operations */
DEF( neg, 1, 1, 1, none)
DEF( plus, 1, 1, 1, none)
DEF( dec, 1, 1, 1, none)
DEF( inc, 1, 1, 1, none)
DEF( post_dec, 1, 1, 2, none)
DEF( post_inc, 1, 1, 2, none)
DEF( dec_loc, 2, 0, 0, loc8)
DEF( inc_loc, 2, 0, 0, loc8)
DEF( add_loc, 2, 1, 0, loc8)
DEF( not, 1, 1, 1, none)
DEF( lnot, 1, 1, 1, none)
DEF( typeof, 1, 1, 1, none)
DEF( delete, 1, 2, 1, none)
DEF( delete_var, 5, 0, 1, atom)
DEF( mul, 1, 2, 1, none)
DEF( div, 1, 2, 1, none)
DEF( mod, 1, 2, 1, none)
DEF( add, 1, 2, 1, none)
DEF( sub, 1, 2, 1, none)
DEF( pow, 1, 2, 1, none)
DEF( shl, 1, 2, 1, none)
DEF( sar, 1, 2, 1, none)
DEF( shr, 1, 2, 1, none)
DEF( lt, 1, 2, 1, none)
DEF( lte, 1, 2, 1, none)
DEF( gt, 1, 2, 1, none)
DEF( gte, 1, 2, 1, none)
DEF( instanceof, 1, 2, 1, none)
DEF( in, 1, 2, 1, none)
DEF( eq, 1, 2, 1, none)
DEF( neq, 1, 2, 1, none)
DEF( strict_eq, 1, 2, 1, none)
DEF( strict_neq, 1, 2, 1, none)
DEF( and, 1, 2, 1, none)
DEF( xor, 1, 2, 1, none)
DEF( or, 1, 2, 1, none)
DEF(is_undefined_or_null, 1, 1, 1, none)
DEF( private_in, 1, 2, 1, none)
DEF(push_bigint_i32, 5, 0, 1, i32)
/* must be the last non short and non temporary opcode */
DEF( nop, 1, 0, 0, none)
/* temporary opcodes: never emitted in the final bytecode */
def( enter_scope, 3, 0, 0, u16) /* emitted in phase 1, removed in phase 2 */
def( leave_scope, 3, 0, 0, u16) /* emitted in phase 1, removed in phase 2 */
def( label, 5, 0, 0, label) /* emitted in phase 1, removed in phase 3 */
/* the following opcodes must be in the same order as the 'with_x' and
get_var_undef, get_var and put_var opcodes */
def(scope_get_var_undef, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */
def( scope_get_var, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */
def( scope_put_var, 7, 1, 0, atom_u16) /* emitted in phase 1, removed in phase 2 */
def(scope_delete_var, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */
def( scope_make_ref, 11, 0, 2, atom_label_u16) /* emitted in phase 1, removed in phase 2 */
def( scope_get_ref, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */
def(scope_put_var_init, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */
def(scope_get_var_checkthis, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2, only used to return 'this' in derived class constructors */
def(scope_get_private_field, 7, 1, 1, atom_u16) /* obj -> value, emitted in phase 1, removed in phase 2 */
def(scope_get_private_field2, 7, 1, 2, atom_u16) /* obj -> obj value, emitted in phase 1, removed in phase 2 */
def(scope_put_private_field, 7, 2, 0, atom_u16) /* obj value ->, emitted in phase 1, removed in phase 2 */
def(scope_in_private_field, 7, 1, 1, atom_u16) /* obj -> res emitted in phase 1, removed in phase 2 */
def(get_field_opt_chain, 5, 1, 1, atom) /* emitted in phase 1, removed in phase 2 */
def(get_array_el_opt_chain, 1, 2, 1, none) /* emitted in phase 1, removed in phase 2 */
def( set_class_name, 5, 1, 1, u32) /* emitted in phase 1, removed in phase 2 */
def( line_num, 5, 0, 0, u32) /* emitted in phase 1, removed in phase 3 */
#if SHORT_OPCODES
DEF( push_minus1, 1, 0, 1, none_int)
DEF( push_0, 1, 0, 1, none_int)
DEF( push_1, 1, 0, 1, none_int)
DEF( push_2, 1, 0, 1, none_int)
DEF( push_3, 1, 0, 1, none_int)
DEF( push_4, 1, 0, 1, none_int)
DEF( push_5, 1, 0, 1, none_int)
DEF( push_6, 1, 0, 1, none_int)
DEF( push_7, 1, 0, 1, none_int)
DEF( push_i8, 2, 0, 1, i8)
DEF( push_i16, 3, 0, 1, i16)
DEF( push_const8, 2, 0, 1, const8)
DEF( fclosure8, 2, 0, 1, const8) /* must follow push_const8 */
DEF(push_empty_string, 1, 0, 1, none)
DEF( get_loc8, 2, 0, 1, loc8)
DEF( put_loc8, 2, 1, 0, loc8)
DEF( set_loc8, 2, 1, 1, loc8)
DEF( get_loc0, 1, 0, 1, none_loc)
DEF( get_loc1, 1, 0, 1, none_loc)
DEF( get_loc2, 1, 0, 1, none_loc)
DEF( get_loc3, 1, 0, 1, none_loc)
DEF( put_loc0, 1, 1, 0, none_loc)
DEF( put_loc1, 1, 1, 0, none_loc)
DEF( put_loc2, 1, 1, 0, none_loc)
DEF( put_loc3, 1, 1, 0, none_loc)
DEF( set_loc0, 1, 1, 1, none_loc)
DEF( set_loc1, 1, 1, 1, none_loc)
DEF( set_loc2, 1, 1, 1, none_loc)
DEF( set_loc3, 1, 1, 1, none_loc)
DEF( get_arg0, 1, 0, 1, none_arg)
DEF( get_arg1, 1, 0, 1, none_arg)
DEF( get_arg2, 1, 0, 1, none_arg)
DEF( get_arg3, 1, 0, 1, none_arg)
DEF( put_arg0, 1, 1, 0, none_arg)
DEF( put_arg1, 1, 1, 0, none_arg)
DEF( put_arg2, 1, 1, 0, none_arg)
DEF( put_arg3, 1, 1, 0, none_arg)
DEF( set_arg0, 1, 1, 1, none_arg)
DEF( set_arg1, 1, 1, 1, none_arg)
DEF( set_arg2, 1, 1, 1, none_arg)
DEF( set_arg3, 1, 1, 1, none_arg)
DEF( get_var_ref0, 1, 0, 1, none_var_ref)
DEF( get_var_ref1, 1, 0, 1, none_var_ref)
DEF( get_var_ref2, 1, 0, 1, none_var_ref)
DEF( get_var_ref3, 1, 0, 1, none_var_ref)
DEF( put_var_ref0, 1, 1, 0, none_var_ref)
DEF( put_var_ref1, 1, 1, 0, none_var_ref)
DEF( put_var_ref2, 1, 1, 0, none_var_ref)
DEF( put_var_ref3, 1, 1, 0, none_var_ref)
DEF( set_var_ref0, 1, 1, 1, none_var_ref)
DEF( set_var_ref1, 1, 1, 1, none_var_ref)
DEF( set_var_ref2, 1, 1, 1, none_var_ref)
DEF( set_var_ref3, 1, 1, 1, none_var_ref)
DEF( get_length, 1, 1, 1, none)
DEF( if_false8, 2, 1, 0, label8)
DEF( if_true8, 2, 1, 0, label8) /* must come after if_false8 */
DEF( goto8, 2, 0, 0, label8) /* must come after if_true8 */
DEF( goto16, 3, 0, 0, label16)
DEF( call0, 1, 1, 1, npopx)
DEF( call1, 1, 1, 1, npopx)
DEF( call2, 1, 1, 1, npopx)
DEF( call3, 1, 1, 1, npopx)
DEF( is_undefined, 1, 1, 1, none)
DEF( is_null, 1, 1, 1, none)
DEF(typeof_is_undefined, 1, 1, 1, none)
DEF( typeof_is_function, 1, 1, 1, none)
#endif
#undef DEF
#undef def
#endif /* DEF */

56029
packages/js/vendor/quickjs.c vendored Normal file

File diff suppressed because it is too large Load Diff

1168
packages/js/vendor/quickjs.h vendored Normal file

File diff suppressed because it is too large Load Diff

7
packages/media/build.zig Normal file
View File

@@ -0,0 +1,7 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
_ = b.addModule("media", .{
.root_source_file = b.path("src/root.zig"),
});
}

View File

@@ -0,0 +1,11 @@
.{
.name = .media,
.version = "0.0.0",
.minimum_zig_version = "0.15.1",
.paths = .{
"src",
"build.zig",
"build.zig.zon",
},
.fingerprint = 0x6a2ca10cfcadaa2b,
}

BIN
packages/media/qoa-specification.pdf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
packages/media/qoi-specification.pdf (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,22 @@
const std = @import("std");
pub const Static = struct {
samples: []Sample,
sample_rate: u32,
pub fn lengthInSeconds(self: Static) f32 {
const samples: f64 = @floatFromInt(self.samples);
const sample_rate: f64 = @floatFromInt(self.sample_rate);
return @floatCast(samples / sample_rate);
}
};
pub const Sample = extern struct {
left: i16,
right: i16,
};
pub const Stream = struct {
source: std.io.Reader,
sample_rate: u32,
};

View File

@@ -0,0 +1,86 @@
const std = @import("std");
pub const Color = extern struct {
vector: Vector,
pub const Vector = @Vector(4, u8);
pub const clear = Color.init(0, 0, 0, 0);
pub const black = Color.init(0, 0, 0, 255);
pub const white = Color.init(255, 255, 255, 255);
pub fn init(r: u8, g: u8, b: u8, a: u8) Color {
return .{ .vector = .{ r, g, b, a } };
}
pub fn fromFloat(color: ColorFloat) Color {
const clamped = std.math.clamp(color, @splat(0.0), @splat(1.0));
const vector = @round(clamped * @as(ColorFloat.Vector, @splat(255.0)));
return .{
.vector = .{
@intFromFloat(vector[0]),
@intFromFloat(vector[1]),
@intFromFloat(vector[2]),
@intFromFloat(vector[3]),
},
};
}
};
pub const ColorFloat = extern struct {
vector: Vector,
pub const Vector = @Vector(4, f32);
pub const clear = ColorFloat.init(0, 0, 0, 0);
pub const black = ColorFloat.init(0, 0, 0, 255);
pub const white = ColorFloat.init(255, 255, 255, 255);
pub inline fn init(r: f32, g: f32, b: f32, a: f32) ColorFloat {
return .{ .vector = .{ r, g, b, a } };
}
pub inline fn fromInteger(color: Color) ColorFloat {
return .{
.vector = .{
@as(f32, @floatFromInt(color.r)) / 255.0,
@as(f32, @floatFromInt(color.g)) / 255.0,
@as(f32, @floatFromInt(color.b)) / 255.0,
@as(f32, @floatFromInt(color.a)) / 255.0,
},
};
}
pub inline fn add(self: ColorFloat, other: ColorFloat) ColorFloat {
return .{ .vector = self.vector + other.vector };
}
pub inline fn sub(self: ColorFloat, other: ColorFloat) ColorFloat {
return .{ .vector = self.vector - other.vector };
}
pub inline fn mul(self: ColorFloat, other: ColorFloat) ColorFloat {
return .{ .vector = self.vector * other.vector };
}
pub inline fn div(self: ColorFloat, other: ColorFloat) ColorFloat {
return .{ .vector = self.vector / other.vector };
}
pub inline fn mulScalar(self: ColorFloat, scalar: f32) ColorFloat {
const vector: Vector = @splat(scalar);
return .{ .vector = self.vector * vector };
}
pub inline fn divScalar(self: ColorFloat, scalar: f32) ColorFloat {
const vector: Vector = @splat(scalar);
return .{ .vector = self.vector / vector };
}
pub inline fn lerp(self: ColorFloat, other: ColorFloat, t: f32) ColorFloat {
const s = 1.0 - t;
const t_vector: Vector = @splat(t);
const s_vector: Vector = @splat(s);
return .{ .vector = self * t_vector + other * s_vector };
}
};

View File

@@ -0,0 +1,69 @@
const std = @import("std");
const Color = @import("color.zig").Color;
pub fn Static(comptime W: u32, comptime H: u32) type {
return struct {
data: [W * H]Color,
pub const width = W;
pub const height = H;
pub fn getPixel(self: *const @This(), x: u32, y: u32) Color {
std.debug.assert(x < width and y < height);
return self.data[y * width + x];
}
pub fn setPixel(self: *@This(), x: u32, y: u32, color: Color) void {
std.debug.assert(x < width and y < height);
self.data[y * width + x] = color;
}
pub fn fill(self: *@This(), color: Color) void {
@memset(self.data, color);
}
};
}
pub const Dynamic = struct {
width: u32,
height: u32,
data: [*]Color,
pub fn initBuffer(width: u32, height: u32, buffer: []Color) @This() {
std.debug.assert(buffer.len == width * height);
return .{
.width = width,
.height = height,
.data = buffer.ptr,
};
}
pub fn initAlloc(width: u32, height: u32, allocator: std.mem.Allocator) !@This() {
const buffer = try allocator.alloc(Color, width * height);
return .{
.width = width,
.height = height,
.data = buffer.ptr,
};
}
pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void {
allocator.free(self.data[0 .. self.width * self.height]);
}
pub fn getPixel(self: *const @This(), x: u32, y: u32) Color {
std.debug.assert(x < self.width and y < self.height);
return self.data[y * self.width + x];
}
pub fn setPixel(self: *@This(), x: u32, y: u32, color: Color) void {
std.debug.assert(x < self.width and y < self.height);
self.data[y * self.width + x] = color;
}
pub fn fill(self: *@This(), color: Color) void {
@memset(self.data[0 .. self.width * self.height], color);
}
};

View File

@@ -0,0 +1,50 @@
const std = @import("std");
const Header = union(enum) {
streaming: HeaderStreaming,
static: HeaderStatic,
};
const HeaderStreaming = void;
const HeaderStatic = struct {
samples: u32,
channels: u8,
sample_rate: u24,
pub fn lengthInSeconds(self: HeaderStatic) f32 {
const samples: f64 = @floatFromInt(self.samples);
const sample_rate: f64 = @floatFromInt(self.sample_rate);
return @floatCast(samples / sample_rate);
}
};
/// The caller asserts that the buffer is at least 12 bytes long, which can
/// contain the entirety of a QOA file header and the relevant information in
/// the first frame header.
pub fn info(buffer: []const u8) ?Header {
std.debug.assert(buffer.len >= 12);
const magic = buffer[0..4];
const samples = std.mem.readInt(u32, buffer[4..8], .big);
const channels = buffer[8];
const sample_rate = std.mem.readInt(u24, buffer[9..12], .big);
if (!std.mem.eql(u8, magic, "qoaf") or channels == 0 or channels > 8 or sample_rate == 0) {
return null;
}
if (samples == 0) {
return .{
.streaming = {},
};
} else {
return .{
.static = .{
.samples = samples,
.channels = channels,
.sample_rate = sample_rate,
},
};
}
}

View File

@@ -0,0 +1,41 @@
const std = @import("std");
const Channels = enum(u8) {
rgb = 3,
rgba = 4,
};
const ColorSpace = enum(u8) {
srgb_linear_alpha = 0,
linear = 1,
};
const Header = struct {
width: u32,
height: u32,
channels: Channels,
color_space: ColorSpace,
};
/// The caller asserts that the buffer is at least 14 bytes long, which can
/// contain the entirety of a QOI header.
pub fn info(buffer: []const u8) ?Header {
std.debug.assert(buffer.len >= 14);
const magic = buffer[0..4];
const width = std.mem.readInt(u32, buffer[4..8], .big);
const height = std.mem.readInt(u32, buffer[8..12], .big);
const channels = buffer[12];
const color_space = buffer[13];
if (!std.mem.eql(u8, magic, "qoif") or width == 0 or height == 0 or channels < 3 or channels > 4 or color_space > 1) {
return null;
}
return .{
.width = width,
.height = height,
.channels = @enumFromInt(channels),
.color_space = @enumFromInt(color_space),
};
}

View File

@@ -0,0 +1,5 @@
pub const audio = @import("audio.zig");
pub const color = @import("color.zig");
pub const image = @import("image.zig");
pub const qoa = @import("qoa.zig");
pub const qoi = @import("qoi.zig");