mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
moves repl polyfills to repl script
This commit is contained in:
parent
9658079b1a
commit
36c5ea0dae
2 changed files with 51 additions and 49 deletions
25
qjs.c
25
qjs.c
|
@ -717,31 +717,6 @@ start:
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
js_std_eval_binary(ctx, qjsc_repl, qjsc_repl_size, 0);
|
js_std_eval_binary(ctx, qjsc_repl, qjsc_repl_size, 0);
|
||||||
}
|
}
|
||||||
//POLYFILLS FOR QJS REPL BEGIN
|
|
||||||
const char *pf = "globalThis.global = globalThis;\n"
|
|
||||||
"global.console.error = console.log\n"
|
|
||||||
"global.console.warn = console.log\n"
|
|
||||||
"globalThis.breakFunction = () => { throw new Error('Function Break'); };\n"
|
|
||||||
"\n"
|
|
||||||
"if (typeof os !== 'undefined') {\n"
|
|
||||||
" globalThis.sleep = os.sleep;\n"
|
|
||||||
" async function setTimeout2(func, ms) {globalThis.clearTimeout = false; await sleep(ms); if (!clearTimeout) { func(); } }\n"
|
|
||||||
" globalThis.setTimeout = setTimeout2\n"
|
|
||||||
"} else {\n"
|
|
||||||
" console.error('os is not defined.');\n"
|
|
||||||
"}\n"
|
|
||||||
"\n"
|
|
||||||
"if (typeof std !== 'undefined') {\n"
|
|
||||||
" globalThis.urlGet = std.urlGet;\n"
|
|
||||||
" globalThis.loadFile = std.loadFile;\n"
|
|
||||||
" globalThis.printf = console.log;\n"
|
|
||||||
" globalThis.evalFile = std.loadScript;\n"
|
|
||||||
// " globalThis.require = std.loadScript;\n"
|
|
||||||
" globalThis.getURL = std.urlGet;\n"
|
|
||||||
"} else {\n"
|
|
||||||
" console.error('std is not defined.');\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
|
|
||||||
eval_buf(ctx, pf, strlen(pf), "<input>", JS_EVAL_TYPE_MODULE);
|
eval_buf(ctx, pf, strlen(pf), "<input>", JS_EVAL_TYPE_MODULE);
|
||||||
if (standalone || compile_file) {
|
if (standalone || compile_file) {
|
||||||
|
|
75
repl.js
75
repl.js
|
@ -26,6 +26,33 @@ import * as std from "qjs:std";
|
||||||
import * as os from "qjs:os";
|
import * as os from "qjs:os";
|
||||||
import * as bjson from "qjs:bjson";
|
import * as bjson from "qjs:bjson";
|
||||||
|
|
||||||
|
//REPL POLYFILLS BEGIN
|
||||||
|
globalThis.global = globalThis
|
||||||
|
global.console.error = console.log
|
||||||
|
global.console.warn = console.log
|
||||||
|
globalThis.breakFunction = () => { throw new Error('Function Break'); };
|
||||||
|
|
||||||
|
if (typeof os !== 'undefined') {
|
||||||
|
globalThis.sleep = os.sleep
|
||||||
|
async function setTimeout2(func, ms) {globalThis.clearTimeout = false; await sleep(ms); if (!clearTimeout) { func(); } }
|
||||||
|
globalThis.setTimeout = setTimeout2
|
||||||
|
} else {
|
||||||
|
console.error('os is not defined.')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof std !== 'undefined') {
|
||||||
|
globalThis.urlGet = std.urlGet
|
||||||
|
globalThis.loadFile = std.loadFile
|
||||||
|
globalThis.printf = console.log
|
||||||
|
globalThis.evalFile = std.loadScript
|
||||||
|
// " globalThis.require = std.loadScript"
|
||||||
|
globalThis.getURL = std.urlGet
|
||||||
|
} else {
|
||||||
|
console.error('std is not defined.');
|
||||||
|
}
|
||||||
|
|
||||||
(function(g) {
|
(function(g) {
|
||||||
/* add 'bjson', 'os' and 'std' bindings */
|
/* add 'bjson', 'os' and 'std' bindings */
|
||||||
g.bjson = bjson;
|
g.bjson = bjson;
|
||||||
|
@ -276,7 +303,7 @@ import * as bjson from "qjs:bjson";
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
while (delta != 0) {
|
while (delta != 0) {
|
||||||
if (term_cursor_x == (term_width - 1)) {
|
if (term_cursor_x == (term_width - 1)) {
|
||||||
std.puts("\n"); /* translated to CRLF */
|
std.puts("); /* translated to CRLF */
|
||||||
term_cursor_x = 0;
|
term_cursor_x = 0;
|
||||||
delta--;
|
delta--;
|
||||||
} else {
|
} else {
|
||||||
|
@ -418,7 +445,7 @@ import * as bjson from "qjs:bjson";
|
||||||
}
|
}
|
||||||
|
|
||||||
function accept_line() {
|
function accept_line() {
|
||||||
std.puts("\n");
|
std.puts(");
|
||||||
history_add(cmd);
|
history_add(cmd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -501,7 +528,7 @@ import * as bjson from "qjs:bjson";
|
||||||
|
|
||||||
function control_d() {
|
function control_d() {
|
||||||
if (cmd.length == 0) {
|
if (cmd.length == 0) {
|
||||||
std.puts("\n");
|
std.puts(");
|
||||||
return -3; /* exit read eval print loop */
|
return -3; /* exit read eval print loop */
|
||||||
} else {
|
} else {
|
||||||
delete_char_dir(1);
|
delete_char_dir(1);
|
||||||
|
@ -589,10 +616,10 @@ import * as bjson from "qjs:bjson";
|
||||||
|
|
||||||
function control_c() {
|
function control_c() {
|
||||||
if (last_fun === control_c) {
|
if (last_fun === control_c) {
|
||||||
std.puts("\n");
|
std.puts(");
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
std.puts("\n(Press Ctrl-C again to quit)\n");
|
std.puts("\n(Press Ctrl-C again to quit));
|
||||||
readline_print_prompt();
|
readline_print_prompt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -744,7 +771,7 @@ import * as bjson from "qjs:bjson";
|
||||||
max_width += 2;
|
max_width += 2;
|
||||||
n_cols = Math.max(1, Math.floor((term_width + 1) / max_width));
|
n_cols = Math.max(1, Math.floor((term_width + 1) / max_width));
|
||||||
n_rows = Math.ceil(tab.length / n_cols);
|
n_rows = Math.ceil(tab.length / n_cols);
|
||||||
std.puts("\n");
|
std.puts(");
|
||||||
/* display the sorted list column-wise */
|
/* display the sorted list column-wise */
|
||||||
for (row = 0; row < n_rows; row++) {
|
for (row = 0; row < n_rows; row++) {
|
||||||
for (col = 0; col < n_cols; col++) {
|
for (col = 0; col < n_cols; col++) {
|
||||||
|
@ -756,7 +783,7 @@ import * as bjson from "qjs:bjson";
|
||||||
s = s.padEnd(max_width);
|
s = s.padEnd(max_width);
|
||||||
std.puts(s);
|
std.puts(s);
|
||||||
}
|
}
|
||||||
std.puts("\n");
|
std.puts(");
|
||||||
}
|
}
|
||||||
/* show a new prompt */
|
/* show a new prompt */
|
||||||
readline_print_prompt();
|
readline_print_prompt();
|
||||||
|
@ -1399,7 +1426,7 @@ import * as bjson from "qjs:bjson";
|
||||||
output_str(sep);
|
output_str(sep);
|
||||||
sep = ",";
|
sep = ",";
|
||||||
if (col === cols - 1) {
|
if (col === cols - 1) {
|
||||||
output_spaces("\n", indent);
|
output_spaces(", indent);
|
||||||
col = 0;
|
col = 0;
|
||||||
} else {
|
} else {
|
||||||
output_spaces("", colwidth[col++] - w);
|
output_spaces("", colwidth[col++] - w);
|
||||||
|
@ -1412,10 +1439,10 @@ import * as bjson from "qjs:bjson";
|
||||||
for (i = first; i < last; i++) {
|
for (i = first; i < last; i++) {
|
||||||
output_str(sep);
|
output_str(sep);
|
||||||
sep = ",";
|
sep = ",";
|
||||||
output_spaces("\n", indent);
|
output_spaces(", indent);
|
||||||
[i, w] = output_indent(indent, i);
|
[i, w] = output_indent(indent, i);
|
||||||
}
|
}
|
||||||
output_spaces("\n", indent -= 2);
|
output_spaces(", indent -= 2);
|
||||||
output_pretty(tokens[last]);
|
output_pretty(tokens[last]);
|
||||||
return [last, breakLength];
|
return [last, breakLength];
|
||||||
}
|
}
|
||||||
|
@ -1427,7 +1454,7 @@ import * as bjson from "qjs:bjson";
|
||||||
|
|
||||||
function print(val) {
|
function print(val) {
|
||||||
std.puts(util.inspect(val, { depth: show_depth, colors: show_colors, showHidden: show_hidden }));
|
std.puts(util.inspect(val, { depth: show_depth, colors: show_colors, showHidden: show_hidden }));
|
||||||
std.puts("\n");
|
std.puts(");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return true if the string was a directive */
|
/* return true if the string was a directive */
|
||||||
|
@ -1465,19 +1492,19 @@ import * as bjson from "qjs:bjson";
|
||||||
|
|
||||||
function help() {
|
function help() {
|
||||||
var sel = (n) => n ? "*": " ";
|
var sel = (n) => n ? "*": " ";
|
||||||
std.puts(".help print this help\n" +
|
std.puts(".help print this help +
|
||||||
".x " + sel(hex_mode) + "hexadecimal number display\n" +
|
".x " + sel(hex_mode) + "hexadecimal number display +
|
||||||
".dec " + sel(!hex_mode) + "decimal number display\n" +
|
".dec " + sel(!hex_mode) + "decimal number display +
|
||||||
".time " + sel(show_time) + "toggle timing display\n" +
|
".time " + sel(show_time) + "toggle timing display +
|
||||||
".strict " + sel(use_strict) + "toggle strict mode evaluation\n" +
|
".strict " + sel(use_strict) + "toggle strict mode evaluation +
|
||||||
`.depth set object depth (current: ${show_depth})\n` +
|
`.depth set object depth (current: ${show_depth})\n` +
|
||||||
".hidden " + sel(show_hidden) + "toggle hidden properties display\n" +
|
".hidden " + sel(show_hidden) + "toggle hidden properties display +
|
||||||
".color " + sel(show_colors) + "toggle colored output\n" +
|
".color " + sel(show_colors) + "toggle colored output +
|
||||||
".dark " + sel(styles == themes.dark) + "select dark color theme\n" +
|
".dark " + sel(styles == themes.dark) + "select dark color theme +
|
||||||
".light " + sel(styles == themes.light) + "select light color theme\n" +
|
".light " + sel(styles == themes.light) + "select light color theme +
|
||||||
".clear clear the terminal\n" +
|
".clear clear the terminal +
|
||||||
".load load source code from a file\n" +
|
".load load source code from a file +
|
||||||
".quit exit\n");
|
".quit exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
function load(s) {
|
function load(s) {
|
||||||
|
@ -1516,7 +1543,7 @@ import * as bjson from "qjs:bjson";
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
function cmd_start() {
|
function cmd_start() {
|
||||||
std.puts('QuickJS-ng - Type ".help" for help\n');
|
std.puts('QuickJS-ng DoneJS Edition - Type ".help" for help\n');
|
||||||
cmd_readline_start();
|
cmd_readline_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue