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

Quelle  Script-isInCatchScope.js   Sprache: JAVA

 
// Test if isInCatchScope properly detects catch blocks.

let g = newGlobal({newCompartment: true});
let dbg = new Debugger(g);

function test(string, mustBeCaught) {
    let index = 0;
    dbg.onExceptionUnwind = function (frame) {
        let willBeCaught = false;
        do {
            if (frame.script.isInCatchScope(frame.offset)) {
                willBeCaught = true;
                break;
            }
            frame = frame.older;
        } while (frame != null);
        assertEq(willBeCaught, mustBeCaught[index++]);
    };

    try {
        g.eval(string);
    } catch (ex) {}
    assertEq(index, mustBeCaught.length);
}

// Should correctly detect catch blocks
test("throw new Error();", [false]);
test("try { throw new Error(); } catch (e) {}", [true]);
test("try { throw new Error(); } finally {}", [falsefalse]);
test("try { throw new Error(); } catch (e) {} finally {}", [true]);

// Source of the exception shouldn't matter
test("(null)();", [false]);
test("try { (null)(); } catch (e) {}", [true]);
test("try { (null)(); } finally {}", [falsefalse]);
test("try { (null)(); } catch (e) {} finally {}", [true]);

// Should correctly detect catch blocks in functions
test("function f() { throw new Error(); } f();", [falsefalse]);
test("function f() { try { throw new Error(); } catch (e) {} } f();", [true]);
test("function f() { try { throw new Error(); } finally {} } f();", [falsefalsefalse]);
test("function f() { try { throw new Error(); } catch (e) {} finally {} } f();"[true]);

// Should correctly detect catch blocks in evals
test("eval('throw new Error();')", [falsefalse]);
test("eval('try { throw new Error(); } catch (e) {}');", [true]);
test("eval('try { throw new Error(); } finally {}');", [falsefalsefalse]);
test("eval('try { throw new Error(); } catch (e) {} finally {}');", [true]);

// Should correctly detect rethrows
test("try { throw new Error(); } catch (e) { throw e; }", [truefalse]);
test("try { try { throw new Error(); } catch (e) { throw e; } } catch (e) {}", [truetrue]);
test("try { try { throw new Error(); } finally {} } catch (e) {}", [truetrue]);
test("function f() { try { throw new Error(); } catch (e) { throw e; } } f();", [truefalsefalse]);
test("function f() { try { try { throw new Error(); } catch (e) { throw e; } } catch (e) {} } f();", [truetrue]);
test("function f() { try { try { throw new Error(); } finally {} } catch (e) {} } f();", [truetrue]);
test("eval('try { throw new Error(); } catch (e) { throw e; }')", [truefalsefalse]);
test("eval('try { try { throw new Error(); } catch (e) { throw e; } } catch (e) {}')", [truetrue]);

// Should correctly detect catch blocks across frame boundaries
test("function f() { throw new Error(); } try { f(); } catch (e) {}", [truetrue]);
test("function f() { throw new Error(); } try { f(); } catch (e) { throw e; }", [truetruefalse]);
test("try { eval('throw new Error()'); } catch (e) {}", [truetrue]);
test("try { eval('throw new Error()'); } catch (e) { throw e; }", [truetruefalse]);

// Should correctly detect catch blocks just before and just after throws
test("throw new Error; try {} catch (e) {}", [false]);
test("try {} catch (e) {} throw new Error();", [false]);

Messung V0.5
C=90 H=97 G=93

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