javascript 0.3.0

A JavaScript engine implementation in Rust
Documentation
"use strict";

function assert(condition, message) {
    if (!condition) {
        throw new Error(message || "Assertion failed");
    }
}

/*
// Non-strict mode test for arguments.callee

function testCallee() {
    console.log("In testCallee, arguments.callee =", arguments.callee);
    if (arguments.callee !== testCallee) {
        throw new Error("arguments.callee is not the function itself");
    }
    return "ok";
}

console.log("=== Testing arguments.callee property ===");
{
    // Normal call
    let v = testCallee();
    console.log("Normal call: pass", v);

    // Call via .call
    testCallee.call(null);
    console.log("Call via .call: pass");

    // Call via .apply
    testCallee.apply(null, []);
    console.log("Call via .apply: pass");

    // Closure call
    var f = function() {
        if (arguments.callee !== f) {
            throw new Error("arguments.callee (closure) is not the function itself");
        }
        console.log("In closure f, arguments.callee =", arguments.callee);
    };
    f();
    console.log("Closure call: pass");
    f.call({});
    console.log("Closure .call: pass");
    f.apply({}, []);
    console.log("Closure .apply: pass");
}
// */

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;