mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
815 B
39 lines
815 B
/*
|
|
* IsCallable() (E5 Section 9.11).
|
|
*
|
|
* IsCallable() cannot be directly tested, but Function.prototype.bind()
|
|
* provides a very easy primitive for testing it. E5 Section 15.3.4.5, step
|
|
* 2 will throw a TypeError if IsCallable(func) is false.
|
|
*/
|
|
|
|
function indirectIsCallable(x) {
|
|
Function.prototype.bind.call(x);
|
|
}
|
|
|
|
/*===
|
|
TypeError
|
|
TypeError
|
|
TypeError
|
|
TypeError
|
|
TypeError
|
|
TypeError
|
|
TypeError
|
|
TypeError
|
|
no error
|
|
no error
|
|
no error
|
|
===*/
|
|
|
|
var values = [ undefined, null, true, false, 123.0, "foo",
|
|
{}, [], function () {}, Object.prototype.toLocaleString,
|
|
Object.prototype.toLocaleString.bind('foo') ];
|
|
var i;
|
|
|
|
for (i = 0; i < values.length; i++) {
|
|
try {
|
|
indirectIsCallable(values[i]);
|
|
print('no error');
|
|
} catch (e) {
|
|
print(e.name);
|
|
}
|
|
}
|
|
|