File: func-decl.js

package info (click to toggle)
kjs 5.103.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,020 kB
  • sloc: cpp: 36,704; javascript: 5,079; yacc: 790; perl: 191; sh: 52; makefile: 7
file content (44 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// We can't use normal shouldBe here, since they'd eval in the wrong context...
function shouldBeOfType(msg, val, type) {
  if (typeof(val) != type)
    testFailed(msg + ": value has type " + typeof(val) + " , not:" + type);
  else
    testPassed(msg);
}

function shouldBeVal(msg, val, expected) {
  if (val != expected)
    testFailed(msg + ": value is " + val + " , not:" + expected);
  else
    testPassed(msg);
}

f = "global";

function test() {
  try {
    shouldBeOfType("Function declaration takes effect at entry", f, "function");
  }
  catch (e) {
    testFailed("Scoping very broken!");
  }

  for (var i = 0; i < 3; ++i) {
    if (i == 0)
      shouldBeOfType("Decl not yet overwritten", f, 'function');
    else
      shouldBeOfType("Decl already overwritten", f, 'number');

    f = 3;
    shouldBeVal("After assign ("+i+")", f, 3);

    function f() {};
    shouldBeVal("function decls have no execution content", f, 3);

    f = 5;

    shouldBeVal("After assign #2 ("+i+")", f, 5);
  }
}

test();