forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-arguments-caller.js
More file actions
72 lines (55 loc) · 1.62 KB
/
test-arguments-caller.js
File metadata and controls
72 lines (55 loc) · 1.62 KB
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
/*
* Tests for the 'caller' property of an arguments object created
* for a non-strict callee.
*/
/*---
{
"comment": "breaks with DUK_USE_NONSTD_FUNC_CALLER_PROPERTY"
}
---*/
/*===
object foo bar
undefined undefined
123 123
dummy dummy
g
TypeError
===*/
// non-strict callee
function f(x,y) { return arguments; }
// strict caller
function g() { 'use strict'; return f('foo', 'bar'); }
// dummy non-strict function
function dummy() {}
f.myName = 'f';
g.myName = 'g';
dummy.myName = 'dummy';
function test() {
// Create arguments object for the case where a strict function (g)
// calls a non-strict caller (f).
a = g();
print(typeof a, a[0], a[1]);
// Initially there is no 'caller' property at all, and thus no
// special behavior.
print(Object.getOwnPropertyDescriptor(a, "caller"), a.caller);
// Setting 'caller' to a non-function value triggers no special
// behavior.
a.caller = 123;
print(Object.getOwnPropertyDescriptor(a, "caller").value, a.caller);
// Setting 'caller' to a non-strict function also triggers no
// special behavior.
a.caller = dummy;
print(Object.getOwnPropertyDescriptor(a, "caller").value.myName, a.caller.myName);
// Setting 'caller' to a strict function (any strict function, but
// here we set it to 'g') triggers special behavior.
a.caller = g;
// this is OK, the special behavior *only* happens at the [[Get]] level
print(Object.getOwnPropertyDescriptor(a, "caller").value.myName);
// this fails due to special behavior in [[Get]]
print(a.caller.myName);
}
try {
test();
} catch (e) {
print(e.name);
}