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

Quelle  object-keys-02.js   Sprache: JAVA

 

// This test case check some code frequently used in the wild, with some object
// (proxy) for which the optimization we have deployed do not work, as the
// assumption the Object.keys(...) can be elided without having noticeable
// side-effects.

// Similar functions are part of popular framework such as React and Angular.
function shallowEqual(o1, o2) {
    var k1 = Object.keys(o1);
    var k2 = Object.keys(o2);
    if (k1.length != k2.length) {
        return false;
    }
    for (var k = 0; k < k1.length; k++) {
        if (!Object.hasOwnProperty.call(o2, k1[k]) || !Object.is(o1[k1[k]], o2[k1[k]])) {
            return false;
        }
    }
    return true;
}

let sideEffectCounter = 0;
const payload = {x: 5, a: 1, b: 2, c: 3, d: 4};
const handler = {
    ownKeys(target) {
        // side-effect that should not be removed.
        sideEffectCounter++;
        // answer returned.
        return Reflect.ownKeys(target);
    },
};
const proxy = new Proxy(payload, handler);

let objs = [
    {x:0, a: 1, b: 2},
    {x:1, b: 1, c: 2},
    {x:2, c: 1, d: 2},
    {x:3, a: 1, b: 2, c: 3},
    {x:4, b: 1, c: 2, d: 3},
    proxy
];

with({}) {}
let iterMax = 1000;
for (let i = 0; i < iterMax; i++) {
    for (let o1 of objs) {
        for (let o2 of objs) {
            assertEq(shallowEqual(o1, o2), Object.is(o1, o2));
        }
    }
}

let expectedSideEffects = 2 * objs.length * iterMax;
assertEq(sideEffectCounter, expectedSideEffects);

Messung V0.5
C=95 H=78 G=86

¤ Dauer der Verarbeitung: 0.13 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.