mirror of
https://github.com/bellard/quickjs.git
synced 2025-09-30 23:07:42 +03:00
2020-11-08 release
This commit is contained in:
@@ -17,6 +17,22 @@ function assert(actual, expected, message) {
|
||||
(message ? " (" + message + ")" : ""));
|
||||
}
|
||||
|
||||
function assert_throws(expected_error, func)
|
||||
{
|
||||
var err = false;
|
||||
try {
|
||||
func();
|
||||
} catch(e) {
|
||||
err = true;
|
||||
if (!(e instanceof expected_error)) {
|
||||
throw Error("unexpected exception type");
|
||||
}
|
||||
}
|
||||
if (!err) {
|
||||
throw Error("expected exception");
|
||||
}
|
||||
}
|
||||
|
||||
// load more elaborate version of assert if available
|
||||
try { __loadScript("test_assert.js"); } catch(e) {}
|
||||
|
||||
@@ -39,7 +55,7 @@ function test_function()
|
||||
function constructor1(a) {
|
||||
this.x = a;
|
||||
}
|
||||
|
||||
|
||||
var r, g;
|
||||
|
||||
r = my_func.call(null, 1, 2);
|
||||
@@ -48,6 +64,13 @@ function test_function()
|
||||
r = my_func.apply(null, [1, 2]);
|
||||
assert(r, 3, "apply");
|
||||
|
||||
r = (function () { return 1; }).apply(null, undefined);
|
||||
assert(r, 1);
|
||||
|
||||
assert_throws(TypeError, (function() {
|
||||
Reflect.apply((function () { return 1; }), null, undefined);
|
||||
}));
|
||||
|
||||
r = new Function("a", "b", "return a + b;");
|
||||
assert(r(2,3), 5, "function");
|
||||
|
||||
|
Reference in New Issue
Block a user