File: arguments-scope.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 (49 lines) | stat: -rw-r--r-- 1,216 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
45
46
47
48
49
// 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 test0() {
    var arguments;
    // var execution should not overwrite something that was 
    // in scope beforehand -- e.g. the arguments thing
    shouldBeOfType("test0", arguments, 'object');
 }

function test1() {
    // No need to undef-initialize something in scope already!
    shouldBeOfType("test1", arguments, 'object');
    var arguments;
}

function test2(arguments) {
    // Formals OTOH can overwrite the args object
    shouldBeOfType("test2", arguments, 'number');
}


function test3() {
    // Ditto for functions..
    shouldBeOfType("test3", arguments, 'function');
    function arguments() {}
}

function test4() {
    // Here, the -declaration- part of the var below should have no 
    // effect..
    shouldBeOfType('test4.(1)', arguments, 'object');
    var arguments = 4;
    // .. but the assignment shoud just happen
    shouldBeOfType('test4.(2)', arguments, 'number');
}


test0();
test1();
test2(42);
test3();
test4();