Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Firefox/js/src/jit-test/tests/basic/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

Quelle  call-construct-hook.js   Sprache: JAVA

 
// Tests for invoking JSClass call/construct hooks.

function testBasic() {
    let obj = {fun: newObjectWithCallHook()};
    for (var i = 0; i < 1000; i++) {
        let res = obj.fun(1, 2, 3);
        assertEq(res.this, obj);
        assertEq(res.callee, obj.fun);
        assertEq(JSON.stringify(res.arguments), "[1,2,3]");
        assertEq(res.newTarget, undefined);

        res = new obj.fun(1, 2, 3);
        assertEq(res.this"");
        assertEq(res.callee, obj.fun);
        assertEq(JSON.stringify(res.arguments), "[1,2,3]");
        assertEq(res.newTarget, obj.fun);
    }
}
testBasic();

function testSpread() {
    let obj = {fun: newObjectWithCallHook()};
    for (var i = 0; i < 1000; i++) {
        let res = obj.fun(...[1, 2, 3]);
        assertEq(res.this, obj);
        assertEq(res.callee, obj.fun);
        assertEq(JSON.stringify(res.arguments), "[1,2,3]");
        assertEq(res.newTarget, undefined);

        res = new obj.fun(...[1, 2, 3]);
        assertEq(res.this"");
        assertEq(res.callee, obj.fun);
        assertEq(JSON.stringify(res.arguments), "[1,2,3]");
        assertEq(res.newTarget, obj.fun);
    }
}
testSpread();

function testNewTarget() {
    let obj = newObjectWithCallHook();
    let newTargetVal = function() {};
    for (var i = 0; i < 1000; i++) {
        let res = Reflect.construct(obj, [], newTargetVal);
        assertEq(res.this"");
        assertEq(res.callee, obj);
        assertEq(res.arguments.length, 0);
        assertEq(res.newTarget, newTargetVal);
    }
}
testNewTarget();

function testRealmSwitch() {
    // We currently switch to the callable's realm for class hook calls (similar to
    // JS function calls). This might change at some point, but for now assert the
    // returned object's realm matches that of the callee.

    let g = newGlobal({sameCompartmentAs: this});
    let obj = g.newObjectWithCallHook();
    assertEq(objectGlobal(obj), g);

    for (var i = 0; i < 1000; i++) {
        let res = obj(1, 2);
        assertEq(objectGlobal(res), g);
        assertEq(res.this, undefined);
        assertEq(res.callee, obj);
        assertEq(JSON.stringify(res.arguments), "[1,2]");

        res = new obj(1, 2);
        assertEq(objectGlobal(res), g);
        assertEq(res.this"");
        assertEq(res.callee, obj);
        assertEq(JSON.stringify(res.arguments), "[1,2]");
        assertEq(res.newTarget, obj);
    }
}
testRealmSwitch();

function testCrossCompartmentWrapper() {
    // Call/construct hooks can be called through cross-compartment wrappers.

    let g = newGlobal({newCompartment: true});
    let obj = g.newObjectWithCallHook();
    assertEq(isProxy(obj), true); // It's a CCW.

    for (var i = 0; i < 1000; i++) {
        let res = obj(1, 2);
        assertEq(isProxy(res), true);
        assertEq(res.this, undefined);
        assertEq(res.callee, obj);
        assertEq(JSON.stringify(res.arguments), "[1,2]");

        res = new obj(1, 2);
        assertEq(isProxy(res), true);
        assertEq(res.this"");
        assertEq(res.callee, obj);
        assertEq(JSON.stringify(res.arguments), "[1,2]");
        assertEq(res.newTarget, obj);
    }
}
testCrossCompartmentWrapper();

Messung V0.5
C=92 H=92 G=91

¤ Dauer der Verarbeitung: 0.19 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.