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


Quelle  class-decorators.js   Sprache: JAVA

 
// |jit-test| skip-if: !getBuildConfiguration("decorators")

load(libdir + "asserts.js");

let dec1Called = false;

// This explicitly tests the case where undefined is returned.
function dec1(value, context) {
  dec1Called = true;
  // returns undefined
}

function dec2(value, context) {
  return class extends value {
    constructor(...args) {
      super(...args);
    }

    x2 = true;
  }
}

function checkDecoratorContext(name) {
  return function (value, context) {
    assertEq(typeof value, "function");
    assertEq(context.kind, "class");
    assertEq(context.name, name);
    assertEq(typeof context.addInitializer, "undefined");
    // return undefined
  }
}

@dec1 class C1 {};
assertEq(dec1Called, true);

@dec2 class C2 {
  x1 = true;
}

let c2 = new C2();
assertEq(c2.x1, true);
assertEq(c2.x2, true);

let c3 = new @dec2 class {
  x1 = true;
}

assertEq(c3.x1, true);
assertEq(c3.x2, true);

@checkDecoratorContext("D"class D {}
let d2 = new @checkDecoratorContext(undefined) class {};

class E {
  static #dec1(value, context) {
    return class extends value {
      constructor(...args) {
        super(...args);
      }

      x2 = true;
    }
  }
  static {
    this.F = @E.#dec1 class {
      x1 = true;
    }
  }
}

let f = new E.F();
assertEq(f.x1, true);
assertEq(f.x2, true);

assertThrowsInstanceOf(() => {
  @(() => { return "hello!"; }) class G {}
}, TypeError), "Returning a value other than undefined or a callable throws.";

assertThrowsInstanceOf(() => {
  class G {
    static #dec1() {}
    static {
      @G.#dec1 class G {}
    }
  }
}, ReferenceError), "can't access lexical declaration 'G' before initialization";

const decoratorOrder = [];
function makeOrderedDecorator(order) {
  return function (value, context) {
    decoratorOrder.push(order);
    return value;
  }
}

@makeOrderedDecorator(1) @makeOrderedDecorator(2) @makeOrderedDecorator(3)
class H {}
assertEq(decoratorOrder.length, 3);
assertEq(decoratorOrder[0], 3);
assertEq(decoratorOrder[1], 2);
assertEq(decoratorOrder[2], 1);

Messung V0.5
C=97 H=100 G=98

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






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge