Skip to main content

quickjs_jit_stdlib/llrt/llrt_utils/
io.rs

1// Vendored from LLRT d9fd873e793c (libs/llrt_utils/src/io.rs); module paths and
2// feature names adapted by scripts/import-stdlib.py.
3// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4// SPDX-License-Identifier: Apache-2.0
5
6macro_rules! define_extension {
7    ($base:ident, $file:ident, $ext:expr) => {
8        #[allow(dead_code)]
9        pub const $base: &str = $ext;
10        #[allow(dead_code)]
11        pub const $file: &str = concat!(".", $ext);
12    };
13}
14
15define_extension!(BYTECODE_EXT, BYTECODE_FILE_EXT, "lrt");
16
17macro_rules! define_supported_extensions {
18    // Accepts a list of supported extensions and a single additional constant extension
19    ($constant_ext:ident, $($ext:literal),*) => {
20        // Define the array of extensions as a constant
21        pub const SUPPORTED_EXTENSIONS: &[&str] = &[$($ext),*, $constant_ext];
22
23        pub const JS_EXTENSIONS: &[&str] = &[$($ext),*];
24
25        // Define the function `is_supported_ext` using a match statement
26        pub fn is_supported_ext(ext: &str) -> bool {
27            matches!(ext, $($ext)|* | $constant_ext)
28        }
29    };
30}
31
32define_supported_extensions!(BYTECODE_FILE_EXT, ".js", ".mjs", ".cjs");