"use strict";
function assert(condition, message) {
if (!condition) {
throw new Error(message || "Assertion failed");
}
}
console.log("=== Checking existence of Function.prototype.call, apply, bind: ===");
try {
console.log("Function.prototype.call: " + Function.prototype.call);
console.log("Function.prototype.apply: " + Function.prototype.apply);
console.log("Function.prototype.bind: " + Function.prototype.bind);
var f = function() {};
console.log("f.call: " + f.call);
console.log("f.apply: " + f.apply);
} catch (e) {
console.log("Error: " + e);
}
{
console.log("=== Testing that accessing arguments.callee throws TypeError in strict mode (inside function) ===");
(function() {
"use strict";
try {
arguments.callee;
throw new Error("Accessing arguments.callee did not throw");
} catch (e) {
console.log(e);
if (!(e instanceof TypeError)) {
throw new Error('Expected a TypeError, but got: ' + e);
}
}
})();
console.log("=== Testing that arguments is not defined at global scope ===");
try {
arguments;
throw new Error("arguments should not be defined at global scope");
} catch (e) {
console.log(e);
if (!(e instanceof ReferenceError)) {
throw new Error('Expected a ReferenceError, but got: ' + e);
}
}
}
{
console.log("=== Testing that arguments.length is writable ===");
let str = "something different";
function f1(){
arguments.length = str;
return arguments;
}
try{
if(f1().length !== str){
throw new Error("#1: A property length have attribute { ReadOnly }");
}
}
catch(e){
console.log(e);
throw new Error("#1: arguments object don't exists");
}
}
{
console.log("=== Test arguments.callee property descriptor ===");
function testcase() {
var desc = Object.getOwnPropertyDescriptor(arguments,"callee");
assert(desc.configurable === false, 'desc.configurable');
assert(desc.enumerable === false, 'desc.enumerable');
assert(desc.hasOwnProperty('value') === false, 'desc.hasOwnProperty("value")');
assert(desc.hasOwnProperty('writable') === false, 'desc.hasOwnProperty("writable")');
assert(desc.hasOwnProperty('get') === true, 'desc.hasOwnProperty("get")');
assert(desc.hasOwnProperty('set') === true, 'desc.hasOwnProperty("set")');
}
testcase();
}
true;