DCL

An elegant OOP with mixins + AOP for JavaScript.

dcl.SuperError

Version 2.x

dcl.SuperError is present only when dcl/debug is imported. Otherwise, Error will be thrown.

It is thrown, when various errors related to super calls are detected. It works for supercalls in class-level and object-level advices.

dcl.SuperError is based on dcl.DclError.

Examples

Wrong super

Wrong super
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var dcl = require("dcl/debug");

var A = dcl({
  declaredClass: "A",
  m: 42 // not a function
});

var B = dcl(A, {
  declaredClass: "B",
  m: dcl.superCall(function (sup) {
    return sup ? sup.call(this) : 0;
  })
});

// At this point dcl.SuperError will be thrown.

You will see the following exception:

1
dcl: super call error in B, while weaving B, method m (value) wrong arg

Wrong supercalling method

Wrong supercalling method
1
2
3
4
5
6
7
8
var dcl = require("dcl/debug");

var A = dcl({
  declaredClass: "A",
  m: dcl.superCall("Should be a function, but it is a string.")
});

// At this point dcl.SuperError will be thrown.

You will see the following exception:

1
dcl: super call error in A, while weaving A, method m (value) wrong call

Wrong result

Wrong result
1
2
3
4
5
6
7
8
9
10
var dcl = require("dcl/debug");

var A = dcl({
  declaredClass: "A",
  m: dcl.superCall(function (sup) {
    return "Instead of a function I return a string.";
  })
});

// At this point dcl.SuperError will be thrown.

You will see the following exception:

1
dcl: super call error in A, while weaving A, method m (value) wrong result

Wrong supercalling getter

Wrong supercalling method
1
2
3
4
5
6
7
8
9
10
var dcl = require("dcl/debug");

var A = dcl({
  declaredClass: "A",
  m: dcl.prop({
    get: dcl.superCall("Should be a function, but it is a string.")
  })
});

// At this point dcl.SuperError will be thrown.

You will see the following exception:

1
dcl: super call error in A, while weaving A, method m (get) wrong call

Wrong object super

Wrong super
1
2
3
4
5
6
7
8
9
10
var dcl = require("dcl/debug"),
  advise = require("dcl/advise");

var a = {m: 42};

advise.around(a, "m", function (sup) {
  return function () { return 33; };
});

// At this point dcl.SuperError will be thrown.

You will see the following exception:

1
dcl: super call error in object of UNNAMED, while weaving method m (value) wrong arg