quickjs-2024-01-13.tar.xz

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4765 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-01-13 13:04:19 +00:00
parent 10d438e723
commit 2b7077ca70
35 changed files with 3799 additions and 1453 deletions

View File

@ -23,6 +23,7 @@
* THE SOFTWARE.
*/
import * as std from "std";
import * as os from "os";
function pad(str, n) {
str += "";
@ -93,21 +94,12 @@ function log_line() {
console.log(s);
}
var clocks_per_sec = 1000000;
var max_iterations = 100;
var clock_threshold = 2000; /* favoring short measuring spans */
var clocks_per_sec = 1000;
var max_iterations = 10;
var clock_threshold = 100; /* favoring short measuring spans */
var min_n_argument = 1;
var get_clock;
if (typeof globalThis.__date_clock != "function") {
console.log("using fallback millisecond clock");
clocks_per_sec = 1000;
max_iterations = 10;
clock_threshold = 100;
get_clock = Date.now;
} else {
get_clock = globalThis.__date_clock;
}
//var get_clock = Date.now;
var get_clock = os.now;
function log_one(text, n, ti) {
var ref;

View File

@ -538,7 +538,17 @@ function test_regexp()
assert(/{1a}/.toString(), "/{1a}/");
a = /a{1+/.exec("a{11");
assert(a, ["a{11"] );
assert(a, ["a{11"]);
/* test zero length matches */
a = /(?:(?=(abc)))a/.exec("abc");
assert(a, ["a", "abc"]);
a = /(?:(?=(abc)))?a/.exec("abc");
assert(a, ["a", undefined]);
a = /(?:(?=(abc))){0,2}a/.exec("abc");
assert(a, ["a", undefined]);
a = /(?:|[\w])+([0-9])/.exec("123a23");
assert(a, ["123a23", "3"]);
}
function test_symbol()
@ -645,6 +655,18 @@ function test_generator()
assert(ret, "ret_val");
return 3;
}
function *f3() {
var ret;
/* test stack consistency with nip_n to handle yield return +
* finally clause */
try {
ret = 2 + (yield 1);
} catch(e) {
} finally {
ret++;
}
return ret;
}
var g, v;
g = f();
v = g.next();
@ -665,6 +687,12 @@ function test_generator()
assert(v.value === 3 && v.done === true);
v = g.next();
assert(v.value === undefined && v.done === true);
g = f3();
v = g.next();
assert(v.value === 1 && v.done === false);
v = g.next(3);
assert(v.value === 6 && v.done === true);
}
test();

View File

@ -120,6 +120,7 @@ function test_cvt()
assert((Infinity >>> 0) === 0);
assert(((-Infinity) >>> 0) === 0);
assert(((4294967296 * 3 - 4) >>> 0) === (4294967296 - 4));
assert((19686109595169230000).toString() === "19686109595169230000");
}
function test_eq()
@ -325,6 +326,15 @@ function test_class()
/* test class name scope */
var E1 = class E { static F() { return E; } };
assert(E1 === E1.F());
class S {
static x = 42;
static y = S.x;
static z = this.x;
}
assert(S.x === 42);
assert(S.y === 42);
assert(S.z === 42);
};
function test_template()
@ -526,6 +536,53 @@ function test_function_expr_name()
assert_throws(TypeError, f);
}
function test_parse_semicolon()
{
/* 'yield' or 'await' may not be considered as a token if the
previous ';' is missing */
function *f()
{
function func() {
}
yield 1;
var h = x => x + 1
yield 2;
}
async function g()
{
function func() {
}
await 1;
var h = x => x + 1
await 2;
}
}
/* optional chaining tests not present in test262 */
function test_optional_chaining()
{
var a, z;
z = null;
a = { b: { c: 2 } };
assert(delete z?.b.c, true);
assert(delete a?.b.c, true);
assert(JSON.stringify(a), '{"b":{}}', "optional chaining delete");
a = { b: { c: 2 } };
assert(delete z?.b["c"], true);
assert(delete a?.b["c"], true);
assert(JSON.stringify(a), '{"b":{}}');
a = {
b() { return this._b; },
_b: { c: 42 }
};
assert((a?.b)().c, 42);
assert((a?.["b"])().c, 42);
}
test_op1();
test_cvt();
test_eq();
@ -545,3 +602,5 @@ test_spread();
test_function_length();
test_argument_scope();
test_function_expr_name();
test_parse_semicolon();
test_optional_chaining();

View File

@ -167,6 +167,29 @@ function test_for_in2()
assert(tab.toString() == "x,y");
}
function test_for_in_proxy() {
let removed_key = "";
let target = {}
let proxy = new Proxy(target, {
ownKeys: function() {
return ["a", "b", "c"];
},
getOwnPropertyDescriptor: function(target, key) {
if (removed_key != "" && key == removed_key)
return undefined;
else
return { enumerable: true, configurable: true, value: this[key] };
}
});
let str = "";
for(let o in proxy) {
str += " " + o;
if (o == "a")
removed_key = "b";
}
assert(str == " a c");
}
function test_for_break()
{
var i, c;
@ -357,6 +380,7 @@ test_switch1();
test_switch2();
test_for_in();
test_for_in2();
test_for_in_proxy();
test_try_catch1();
test_try_catch2();

View File

@ -1,3 +1,4 @@
#! (shebang test)
import * as std from "std";
import * as os from "os";
@ -270,6 +271,26 @@ function test_timer()
os.clearTimeout(th[i]);
}
/* test closure variable handling when freeing asynchronous
function */
function test_async_gc()
{
(async function run () {
let obj = {}
let done = () => {
obj
std.gc();
}
Promise.resolve().then(done)
const p = new Promise(() => {})
await p
})();
}
test_printf();
test_file1();
test_file2();
@ -279,3 +300,5 @@ test_os();
test_os_exec();
test_timer();
test_ext_json();
test_async_gc();

View File

@ -10,6 +10,7 @@ function handle_msg(e) {
switch(ev.type) {
case "abort":
parent.postMessage({ type: "done" });
parent.onMessage = null; /* terminate the worker */
break;
case "sab":
/* modify the SharedArrayBuffer */