summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/harness/proxytrapshelper-overrides.js
blob: 32616b1bc331b2c55cf981b191dd4fa23e94f2d2 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2016 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: allowProxyTraps helper should default throw on all the proxy trap named methods being invoked
esid: pending
author: Jordan Harband
includes: [proxyTrapsHelper.js]
---*/
var overrides = {
    getPrototypeOf: function () {},
    setPrototypeOf: function () {},
    isExtensible: function () {},
    preventExtensions: function () {},
    getOwnPropertyDescriptor: function () {},
    has: function () {},
    get: function () {},
    set: function () {},
    deleteProperty: function () {},
    defineProperty: function () {},
    enumerate: function () {},
    ownKeys: function () {},
    apply: function () {},
    construct: function () {},
};
var traps = allowProxyTraps(overrides);

function assertTrapSucceeds(trap) {
    if (typeof traps[trap] !== 'function') {
        throw new Test262Error('trap ' + trap + ' is not a function');
    }
    if (traps[trap] !== overrides[trap]) {
        throw new Test262Error('trap ' + trap + ' was not overriden in allowProxyTraps');
    }
    var threw = false;
    try {
        traps[trap]();
    } catch (e) {
        threw = true;
    }
    if (threw) {
        throw new Test262Error('trap ' + trap + ' threw an error');
    }
}

function assertTrapThrows(trap) {
    if (typeof traps[trap] !== 'function') {
        throw new Test262Error('trap ' + trap + ' is not a function');
    }
    var failedToThrow = false;
    try {
        traps[trap]();
        failedToThrow = true;
    } catch (e) {}
    if (failedToThrow) {
        throw new Test262Error('trap ' + trap + ' did not throw an error');
    }
}

assertTrapSucceeds('getPrototypeOf');
assertTrapSucceeds('setPrototypeOf');
assertTrapSucceeds('isExtensible');
assertTrapSucceeds('preventExtensions');
assertTrapSucceeds('getOwnPropertyDescriptor');
assertTrapSucceeds('has');
assertTrapSucceeds('get');
assertTrapSucceeds('set');
assertTrapSucceeds('deleteProperty');
assertTrapSucceeds('defineProperty');
assertTrapSucceeds('ownKeys');
assertTrapSucceeds('apply');
assertTrapSucceeds('construct');

// enumerate should always throw because the trap has been removed
assertTrapThrows('enumerate');

reportCompare(0, 0);