Skip to content

Commit c8e4a4a

Browse files
Gottoxsaghul
authored andcommitted
qjsc: Add -P flag to disable adding default system modules
1 parent 45c3a56 commit c8e4a4a

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

qjsc.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ void help(void)
347347
"-D module_name compile a dynamically loaded module or worker\n"
348348
"-M module_name[,cname] add initialization code for an external C module\n"
349349
"-p prefix set the prefix of the generated C names\n"
350+
"-P do not add default system modules\n"
350351
"-s strip the source code, specify twice to also strip debug info\n"
351352
"-S n set the maximum stack size to 'n' bytes (default=%d)\n",
352353
JS_GetVersion(),
@@ -404,6 +405,7 @@ int main(int argc, char **argv)
404405
int module;
405406
size_t stack_size;
406407
namelist_t dynamic_module_list;
408+
bool load_system_modules = true;
407409

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

417419

418-
/* add system modules */
419-
namelist_add(&cmodule_list, "qjs:std", "std", 0);
420-
namelist_add(&cmodule_list, "qjs:os", "os", 0);
421-
namelist_add(&cmodule_list, "qjs:bjson", "bjson", 0);
422-
namelist_add(&cmodule_list, "std", "std", 0);
423-
namelist_add(&cmodule_list, "os", "os", 0);
424-
namelist_add(&cmodule_list, "bjson", "bjson", 0);
425-
426420
while (optind < argc && *argv[optind] == '-') {
427421
char *arg = argv[optind] + 1;
428422
const char *longopt = "";
@@ -519,6 +513,10 @@ int main(int argc, char **argv)
519513
namelist_add(&dynamic_module_list, optarg, NULL, 0);
520514
continue;
521515
}
516+
if (opt == 'P') {
517+
load_system_modules = false;
518+
continue;
519+
}
522520
if (opt == 's') {
523521
strip++;
524522
continue;
@@ -543,6 +541,16 @@ int main(int argc, char **argv)
543541
}
544542
}
545543

544+
if (load_system_modules) {
545+
/* add system modules */
546+
namelist_add(&cmodule_list, "qjs:std", "std", 0);
547+
namelist_add(&cmodule_list, "qjs:os", "os", 0);
548+
namelist_add(&cmodule_list, "qjs:bjson", "bjson", 0);
549+
namelist_add(&cmodule_list, "std", "std", 0);
550+
namelist_add(&cmodule_list, "os", "os", 0);
551+
namelist_add(&cmodule_list, "bjson", "bjson", 0);
552+
}
553+
546554
if (optind >= argc)
547555
help();
548556

0 commit comments

Comments
 (0)