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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1782450
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1782450</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
// Verify the environment chain for DOM event handlers described in
// js/src/vm/EnvironmentObject.h.
let count = 0;
function check(envs, hasEval) {
is(envs.length, hasEval ? 8 : 6);
let i = 0, env;
if (hasEval) {
env = envs[i]; i++;
is(env.type, "BlockLexicalEnvironmentObject");
is(env.qualified, false);
is(env.unqualified, false);
is(env.lexical, true, "lexical must live in the function lexical env");
is(env.prop, false);
is(env.form_prop, false);
is(env.document_prop, false);
is(env.button_prop, false);
env = envs[i]; i++;
is(env.type, "CallObject");
is(env.qualified, true, "qualified var live in the function call object");
is(env.unqualified, false);
is(env.lexical, false);
is(env.prop, false);
is(env.form_prop, false);
is(env.document_prop, false);
is(env.button_prop, false);
} else {
// qualified var and lexical live in function's frame.
}
env = envs[i]; i++;
is(env.type, "NonSyntacticLexicalEnvironmentObject");
is(env.qualified, false);
is(env.unqualified, false);
is(env.lexical, false);
is(env.prop, false);
is(env.form_prop, false);
is(env.document_prop, false);
is(env.button_prop, false);
env = envs[i]; i++;
is(env.type, "WithEnvironmentObject");
is(env.qualified, false);
is(env.unqualified, false);
is(env.lexical, false);
is(env.prop, true, "this property must live in the with env for button");
is(env.form_prop, false);
is(env.document_prop, false);
is(env.button_prop, true, "button property must live in the with env for button");
env = envs[i]; i++;
is(env.type, "WithEnvironmentObject");
is(env.qualified, false);
is(env.unqualified, false);
is(env.lexical, false);
is(env.prop, false);
is(env.form_prop, true, "form property must live in the with env for form");
is(env.document_prop, false);
is(env.button_prop, false);
env = envs[i]; i++;
is(env.type, "WithEnvironmentObject");
is(env.qualified, false);
is(env.unqualified, false);
is(env.lexical, false);
is(env.prop, false);
is(env.form_prop, false);
is(env.document_prop, true, "document property must live in the with env for document");
is(env.button_prop, false);
env = envs[i]; i++;
is(env.type, "GlobalLexicalEnvironmentObject");
is(env.qualified, false);
is(env.unqualified, false);
is(env.lexical, false);
is(env.prop, false);
is(env.form_prop, false);
is(env.document_prop, false);
is(env.button_prop, false);
env = envs[i]; i++;
is(env.type, "*global*");
is(env.qualified, false);
is(env.unqualified, true, "unqualified name must live in the global");
is(env.lexical, false);
is(env.prop, false);
is(env.form_prop, false);
is(env.document_prop, false);
is(env.button_prop, false);
count++;
if (count == 2) {
SimpleTest.finish();
}
}
</script>
</head>
<body>
<form id="form">
<button id="button_optimized" onclick="event.preventDefault(); var qualified = 10; unqualified = 20; let lexical = 30; this.prop = 40; const funcs = Cu.getJSTestingFunctions(); const envs = []; let env = funcs.getInnerMostEnvironmentObject(); while (env) { envs.push({ type: funcs.getEnvironmentObjectType(env) || '*global*', qualified: !!Object.getOwnPropertyDescriptor(env, 'qualified'), unqualified: !!Object.getOwnPropertyDescriptor(env, 'unqualified'), lexical: !!Object.getOwnPropertyDescriptor(env, 'lexical'), prop: !!Object.getOwnPropertyDescriptor(env, 'prop'), document_prop: !!Object.getOwnPropertyDescriptor(env, 'document_prop'), form_prop: !!Object.getOwnPropertyDescriptor(env, 'form_prop'), button_prop: !!Object.getOwnPropertyDescriptor(env, 'button_prop'), }); env = funcs.getEnclosingEnvironmentObject(env); } check(envs, false); return false;">Click Me!</button>
<!-- Put direct eval to de-optimize function scope -->
<button id="button_unoptimized" onclick="event.preventDefault(); eval(''); var qualified = 10; unqualified = 20; let lexical = 30; this.prop = 40; const funcs = Cu.getJSTestingFunctions(); const envs = []; let env = funcs.getInnerMostEnvironmentObject(); while (env) { envs.push({ type: funcs.getEnvironmentObjectType(env) || '*global*', qualified: !!Object.getOwnPropertyDescriptor(env, 'qualified'), unqualified: !!Object.getOwnPropertyDescriptor(env, 'unqualified'), lexical: !!Object.getOwnPropertyDescriptor(env, 'lexical'), prop: !!Object.getOwnPropertyDescriptor(env, 'prop'), document_prop: !!Object.getOwnPropertyDescriptor(env, 'document_prop'), form_prop: !!Object.getOwnPropertyDescriptor(env, 'form_prop'), button_prop: !!Object.getOwnPropertyDescriptor(env, 'button_prop'), }); env = funcs.getEnclosingEnvironmentObject(env); } check(envs, true);">Click Me!</button>
</form>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1782450">Mozilla Bug 1782450</a>
<script type="application/javascript">
"use strict";
document.document_prop = 50;
const form = document.getElementById("form");
form.form_prop = 50;
const button_unoptimized = document.getElementById("button_unoptimized");
button_unoptimized.button_prop = 60;
button_unoptimized.click();
const button_optimized = document.getElementById("button_optimized");
button_optimized.button_prop = 60;
button_optimized.click();
</script>
</body>
</html>
|