Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Impressum 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 in Prozent
C=92 H=93 G=92

¤ 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.0.10Bemerkung:  (vorverarbeitet am  2026-06-06) ¤

*Bot Zugriff






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik