blob: 3cee5115b1486be993388efdf979533a935b38c2 (
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
|
// Copyright 2011 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* @path ch13/13.2/S13.2.3_A1.js
* @description check that strict mode functions/arguments have
* [[ThrowTypeError]]-like behavior
* function object.
* @onlyStrict
*/
"use strict";
var poison = Object.getOwnPropertyDescriptor(Function.prototype, 'caller').get;
if (typeof poison !== 'function') {
$ERROR("#1: A strict function's .caller should be poisoned with a function");
}
var threw = null;
try {
poison.call(function() {});
} catch (err) {
threw = err;
}
if (!threw || !(threw instanceof TypeError)) {
$ERROR("#2: Poisoned property should throw TypeError");
}
function checkNotPresent(obj, name) {
var desc = Object.getOwnPropertyDescriptor(obj, name);
if (desc !== undefined) {
$ERROR("#3: " + name + " should not appear as a descriptor");
}
}
var argumentsPoison =
Object.getOwnPropertyDescriptor(function() { return arguments; }(),
"callee").get;
function checkPoison(obj, name) {
var desc = Object.getOwnPropertyDescriptor(obj, name);
if (desc.enumerable) {
$ERROR("#3: Poisoned " + name + " should not be enumerable");
}
if (desc.configurable) {
$ERROR("#4: Poisoned " + name + " should not be configurable");
}
if (argumentsPoison !== desc.get) {
$ERROR("#5: " + name + "'s getter not poisoned with same poison");
}
if (argumentsPoison !== desc.set) {
$ERROR("#6: " + name + "'s setter not poisoned with same poison");
}
}
checkNotPresent(function() {}, 'caller');
checkNotPresent(function() {}, 'arguments');
checkPoison((function() { return arguments; })(), 'caller');
checkPoison((function() { return arguments; })(), 'callee');
checkNotPresent((function() {}).bind(null), 'caller');
checkNotPresent((function() {}).bind(null), 'arguments');
|