Skip to content

qjsc: Add -P flag to disable adding default system modules #1051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions qjsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ void help(void)
"-D module_name compile a dynamically loaded module or worker\n"
"-M module_name[,cname] add initialization code for an external C module\n"
"-p prefix set the prefix of the generated C names\n"
"-P do not add default system modules\n"
"-s strip the source code, specify twice to also strip debug info\n"
"-S n set the maximum stack size to 'n' bytes (default=%d)\n",
JS_GetVersion(),
Expand Down Expand Up @@ -404,6 +405,7 @@ int main(int argc, char **argv)
int module;
size_t stack_size;
namelist_t dynamic_module_list;
bool load_system_modules = true;

out_filename = NULL;
script_name = NULL;
Expand All @@ -415,14 +417,6 @@ int main(int argc, char **argv)
memset(&dynamic_module_list, 0, sizeof(dynamic_module_list));


/* add system modules */
namelist_add(&cmodule_list, "qjs:std", "std", 0);
namelist_add(&cmodule_list, "qjs:os", "os", 0);
namelist_add(&cmodule_list, "qjs:bjson", "bjson", 0);
namelist_add(&cmodule_list, "std", "std", 0);
namelist_add(&cmodule_list, "os", "os", 0);
namelist_add(&cmodule_list, "bjson", "bjson", 0);

while (optind < argc && *argv[optind] == '-') {
char *arg = argv[optind] + 1;
const char *longopt = "";
Expand Down Expand Up @@ -519,6 +513,10 @@ int main(int argc, char **argv)
namelist_add(&dynamic_module_list, optarg, NULL, 0);
continue;
}
if (opt == 'P') {
load_system_modules = false;
continue;
}
if (opt == 's') {
strip++;
continue;
Expand All @@ -543,6 +541,16 @@ int main(int argc, char **argv)
}
}

if (load_system_modules) {
/* add system modules */
namelist_add(&cmodule_list, "qjs:std", "std", 0);
namelist_add(&cmodule_list, "qjs:os", "os", 0);
namelist_add(&cmodule_list, "qjs:bjson", "bjson", 0);
namelist_add(&cmodule_list, "std", "std", 0);
namelist_add(&cmodule_list, "os", "os", 0);
namelist_add(&cmodule_list, "bjson", "bjson", 0);
}

if (optind >= argc)
help();

Expand Down
Loading