Eine aufbereitete Darstellung der Quelle

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

Benutzer

Quelle  Object-apply-01.js

  Sprache: JAVA
 

// tests calling script functions via Debugger.Object.prototype.apply/call

load(libdir + "asserts.js");

var g = newGlobal({newCompartment: true});
g.eval("function f() { debugger; }");
var dbg = new Debugger(g);

var hits = 0;
function test(usingApply) {
    dbg.onDebuggerStatement = function (frame) {
        var fn = frame.arguments[0];
        var cv = usingApply ? fn.apply(null, [916]) : fn.call(null916);
        assertEq(Object.keys(cv).join(","), "return");
        assertEq(Object.getPrototypeOf(cv), Object.prototype);
        assertEq(cv.return25);

        cv = usingApply ? fn.apply(null, ["hello ""world"]) : fn.call(null"hello ""world");
        assertEq(Object.keys(cv).join(","), "return");
        assertEq(cv.return"hello world");

        // Handle more or less arguments.
        assertEq((usingApply ? fn.apply(null, [15100]) : fn.call(null15100)).return6);
        assertEq((usingApply ? fn.apply(null, []) : fn.call(null)).return, NaN);
        assertEq((usingApply ? fn.apply() : fn.call()).return, NaN);

        // Throw if a this-value or argument is an object but not a Debugger.Object.
        assertThrowsInstanceOf(function () { usingApply ? fn.apply({}, []) : fn.call({}); },
                               TypeError);
        assertThrowsInstanceOf(function () { usingApply ? fn.apply(null, [{}]) : fn.call(null, {}); },
                               TypeError);
        hits++;
    };
    g.eval("f(function (a, b) { return a + b; });");

    // The callee receives the right arguments even if more arguments are provided
    // than the callee's .length.
    dbg.onDebuggerStatement = function (frame) {
        assertEq((usingApply ? frame.arguments[0].apply(null, ['one''two'])
                             : frame.arguments[0].call(null'one''two')).return,
                 2);
        hits++;
    };
    g.eval("f(function () { return arguments.length; });");

    // Exceptions are reported as {throw,stack} completion values.
    dbg.onDebuggerStatement = function (frame) {
        var lose = frame.arguments[0];
        var cv = usingApply ? lose.apply(null, []) : lose.call(null);
        assertEq(Object.keys(cv).join(","), "throw,stack");
        assertEq(cv.throw, frame.callee);
        hits++;
    };
    g.eval("f(function lose() { throw f; });");
}

test(true);
test(false);
assertEq(hits, 6);

Messung V0.5 in Prozent
C=95 H=81 G=88

¤ Dauer der Verarbeitung: 0.16 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






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