summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Object-getOwnPropertyDescriptor-01.js
blob: 5a67074dd0c1d99712e97bc05bce9d2f206381c1 (plain)
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
50
51
52
53
54
55
56
57
58
59
// getOwnPropertyDescriptor works with simple data properties.

var g = newGlobal();
var dbg = Debugger(g);
var hits;
var expected;
dbg.onDebuggerStatement = function (frame) {
    var args = frame.arguments;
    var obj = args[0], id = args[1];
    var desc = obj.getOwnPropertyDescriptor(id);
    if (expected === undefined) {
        assertEq(desc, undefined);
    } else {
        assertEq(desc instanceof Object, true);
        assertEq(desc.enumerable, expected.enumerable);
        assertEq(desc.configurable, expected.configurable);
        assertEq(desc.hasOwnProperty("value"), true);
        assertEq(desc.value, expected.value);
        assertEq(desc.writable, expected.writable === undefined ? true : expected.writable);
        assertEq("get" in desc, false);
        assertEq("set" in desc, false);
    }
    hits++;
};

g.eval("function f(obj, id) { debugger; }");

function test(obj, id, desc) {
    expected = desc;
    hits = 0;
    g.f(obj, id);
    assertEq(hits, 1);
}

var obj = g.eval("({a: 1, ' ': undefined, '0': 0})");
test(obj, "a", {value: 1, enumerable: true, configurable: true});
test(obj, " ", {value: undefined, enumerable: true, configurable: true});
test(obj, "b", undefined);
test(obj, "0", {value: 0, enumerable: true, configurable: true});
test(obj, 0, {value: 0, enumerable: true, configurable: true});

var arr = g.eval("[7,,]");
test(arr, 'length', {value: 2, enumerable: false, configurable: false});
test(arr, 0, {value: 7, enumerable: true, configurable: true});
test(arr, "0", {value: 7, enumerable: true, configurable: true});
test(arr, 1, undefined);
test(arr, "1", undefined);
test(arr, 2, undefined);
test(arr, "2", undefined);
test(arr, "argelfraster", undefined);

var re = g.eval("/erwe/");
test(re, 'lastIndex', {value: 0, enumerable: false, configurable: false});

// String objects have a well-behaved resolve hook.
var str = g.eval("new String('hello world')");
test(str, 'length', {value: 11, enumerable: false, configurable: false, writable: false});
test(str, 0, {value: 'h', enumerable: true, configurable: false, writable: false});
test(str, "0", {value: 'h', enumerable: true, configurable: false, writable: false});