browser/devtools/debugger/test/browser_dbg_parser-08.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Test that inferring anonymous function information is done correctly.
michael@0 6 */
michael@0 7
michael@0 8 function test() {
michael@0 9 let { Parser, ParserHelpers, SyntaxTreeVisitor } =
michael@0 10 Cu.import("resource:///modules/devtools/Parser.jsm", {});
michael@0 11
michael@0 12 function verify(source, predicate, details) {
michael@0 13 let { name, chain } = details;
michael@0 14 let [[sline, scol], [eline, ecol]] = details.loc;
michael@0 15 let ast = Parser.reflectionAPI.parse(source);
michael@0 16 let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
michael@0 17 let info = ParserHelpers.inferFunctionExpressionInfo(node);
michael@0 18
michael@0 19 is(info.name, name,
michael@0 20 "The function expression assignment property name is correct.");
michael@0 21 is(chain ? info.chain.toSource() : info.chain, chain ? chain.toSource() : chain,
michael@0 22 "The function expression assignment property chain is correct.");
michael@0 23 is(info.loc.start.toSource(), { line: sline, column: scol }.toSource(),
michael@0 24 "The start location was correct for the identifier in: '" + source + "'.");
michael@0 25 is(info.loc.end.toSource(), { line: eline, column: ecol }.toSource(),
michael@0 26 "The end location was correct for the identifier in: '" + source + "'.");
michael@0 27 }
michael@0 28
michael@0 29 // VariableDeclarator
michael@0 30
michael@0 31 verify("var foo=function(){}", e => e.type == "FunctionExpression", {
michael@0 32 name: "foo",
michael@0 33 chain: null,
michael@0 34 loc: [[1, 4], [1, 7]]
michael@0 35 });
michael@0 36 verify("\nvar\nfoo\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression", {
michael@0 37 name: "foo",
michael@0 38 chain: null,
michael@0 39 loc: [[3, 0], [3, 3]]
michael@0 40 });
michael@0 41
michael@0 42 // AssignmentExpression
michael@0 43
michael@0 44 verify("foo=function(){}", e => e.type == "FunctionExpression",
michael@0 45 { name: "foo", chain: [], loc: [[1, 0], [1, 3]] });
michael@0 46
michael@0 47 verify("\nfoo\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
michael@0 48 { name: "foo", chain: [], loc: [[2, 0], [2, 3]] });
michael@0 49
michael@0 50 verify("foo.bar=function(){}", e => e.type == "FunctionExpression",
michael@0 51 { name: "bar", chain: ["foo"], loc: [[1, 0], [1, 7]] });
michael@0 52
michael@0 53 verify("\nfoo.bar\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
michael@0 54 { name: "bar", chain: ["foo"], loc: [[2, 0], [2, 7]] });
michael@0 55
michael@0 56 verify("this.foo=function(){}", e => e.type == "FunctionExpression",
michael@0 57 { name: "foo", chain: ["this"], loc: [[1, 0], [1, 8]] });
michael@0 58
michael@0 59 verify("\nthis.foo\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
michael@0 60 { name: "foo", chain: ["this"], loc: [[2, 0], [2, 8]] });
michael@0 61
michael@0 62 verify("this.foo.bar=function(){}", e => e.type == "FunctionExpression",
michael@0 63 { name: "bar", chain: ["this", "foo"], loc: [[1, 0], [1, 12]] });
michael@0 64
michael@0 65 verify("\nthis.foo.bar\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
michael@0 66 { name: "bar", chain: ["this", "foo"], loc: [[2, 0], [2, 12]] });
michael@0 67
michael@0 68 verify("foo.this.bar=function(){}", e => e.type == "FunctionExpression",
michael@0 69 { name: "bar", chain: ["foo", "this"], loc: [[1, 0], [1, 12]] });
michael@0 70
michael@0 71 verify("\nfoo.this.bar\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
michael@0 72 { name: "bar", chain: ["foo", "this"], loc: [[2, 0], [2, 12]] });
michael@0 73
michael@0 74 // ObjectExpression
michael@0 75
michael@0 76 verify("({foo:function(){}})", e => e.type == "FunctionExpression",
michael@0 77 { name: "foo", chain: [], loc: [[1, 2], [1, 5]] });
michael@0 78
michael@0 79 verify("(\n{\nfoo\n:\nfunction\n(\n)\n{\n}\n}\n)", e => e.type == "FunctionExpression",
michael@0 80 { name: "foo", chain: [], loc: [[3, 0], [3, 3]] });
michael@0 81
michael@0 82 verify("({foo:{bar:function(){}}})", e => e.type == "FunctionExpression",
michael@0 83 { name: "bar", chain: ["foo"], loc: [[1, 7], [1, 10]] });
michael@0 84
michael@0 85 verify("(\n{\nfoo\n:\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n}\n)", e => e.type == "FunctionExpression",
michael@0 86 { name: "bar", chain: ["foo"], loc: [[6, 0], [6, 3]] });
michael@0 87
michael@0 88 // AssignmentExpression + ObjectExpression
michael@0 89
michael@0 90 verify("foo={bar:function(){}}", e => e.type == "FunctionExpression",
michael@0 91 { name: "bar", chain: ["foo"], loc: [[1, 5], [1, 8]] });
michael@0 92
michael@0 93 verify("\nfoo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 94 { name: "bar", chain: ["foo"], loc: [[5, 0], [5, 3]] });
michael@0 95
michael@0 96 verify("foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
michael@0 97 { name: "baz", chain: ["foo", "bar"], loc: [[1, 10], [1, 13]] });
michael@0 98
michael@0 99 verify("\nfoo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 100 { name: "baz", chain: ["foo", "bar"], loc: [[8, 0], [8, 3]] });
michael@0 101
michael@0 102 verify("nested.foo={bar:function(){}}", e => e.type == "FunctionExpression",
michael@0 103 { name: "bar", chain: ["nested", "foo"], loc: [[1, 12], [1, 15]] });
michael@0 104
michael@0 105 verify("\nnested.foo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 106 { name: "bar", chain: ["nested", "foo"], loc: [[5, 0], [5, 3]] });
michael@0 107
michael@0 108 verify("nested.foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
michael@0 109 { name: "baz", chain: ["nested", "foo", "bar"], loc: [[1, 17], [1, 20]] });
michael@0 110
michael@0 111 verify("\nnested.foo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 112 { name: "baz", chain: ["nested", "foo", "bar"], loc: [[8, 0], [8, 3]] });
michael@0 113
michael@0 114 verify("this.foo={bar:function(){}}", e => e.type == "FunctionExpression",
michael@0 115 { name: "bar", chain: ["this", "foo"], loc: [[1, 10], [1, 13]] });
michael@0 116
michael@0 117 verify("\nthis.foo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 118 { name: "bar", chain: ["this", "foo"], loc: [[5, 0], [5, 3]] });
michael@0 119
michael@0 120 verify("this.foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
michael@0 121 { name: "baz", chain: ["this", "foo", "bar"], loc: [[1, 15], [1, 18]] });
michael@0 122
michael@0 123 verify("\nthis.foo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 124 { name: "baz", chain: ["this", "foo", "bar"], loc: [[8, 0], [8, 3]] });
michael@0 125
michael@0 126 verify("this.nested.foo={bar:function(){}}", e => e.type == "FunctionExpression",
michael@0 127 { name: "bar", chain: ["this", "nested", "foo"], loc: [[1, 17], [1, 20]] });
michael@0 128
michael@0 129 verify("\nthis.nested.foo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 130 { name: "bar", chain: ["this", "nested", "foo"], loc: [[5, 0], [5, 3]] });
michael@0 131
michael@0 132 verify("this.nested.foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
michael@0 133 { name: "baz", chain: ["this", "nested", "foo", "bar"], loc: [[1, 22], [1, 25]] });
michael@0 134
michael@0 135 verify("\nthis.nested.foo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 136 { name: "baz", chain: ["this", "nested", "foo", "bar"], loc: [[8, 0], [8, 3]] });
michael@0 137
michael@0 138 verify("nested.this.foo={bar:function(){}}", e => e.type == "FunctionExpression",
michael@0 139 { name: "bar", chain: ["nested", "this", "foo"], loc: [[1, 17], [1, 20]] });
michael@0 140
michael@0 141 verify("\nnested.this.foo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 142 { name: "bar", chain: ["nested", "this", "foo"], loc: [[5, 0], [5, 3]] });
michael@0 143
michael@0 144 verify("nested.this.foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
michael@0 145 { name: "baz", chain: ["nested", "this", "foo", "bar"], loc: [[1, 22], [1, 25]] });
michael@0 146
michael@0 147 verify("\nnested.this.foo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 148 { name: "baz", chain: ["nested", "this", "foo", "bar"], loc: [[8, 0], [8, 3]] });
michael@0 149
michael@0 150 // VariableDeclarator + AssignmentExpression + ObjectExpression
michael@0 151
michael@0 152 verify("let foo={bar:function(){}}", e => e.type == "FunctionExpression",
michael@0 153 { name: "bar", chain: ["foo"], loc: [[1, 9], [1, 12]] });
michael@0 154
michael@0 155 verify("\nlet\nfoo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 156 { name: "bar", chain: ["foo"], loc: [[6, 0], [6, 3]] });
michael@0 157
michael@0 158 verify("let foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
michael@0 159 { name: "baz", chain: ["foo", "bar"], loc: [[1, 14], [1, 17]] });
michael@0 160
michael@0 161 verify("\nlet\nfoo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
michael@0 162 { name: "baz", chain: ["foo", "bar"], loc: [[9, 0], [9, 3]] });
michael@0 163
michael@0 164 // New/CallExpression + AssignmentExpression + ObjectExpression
michael@0 165
michael@0 166 verify("foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 167 { name: "bar", chain: [], loc: [[1, 5], [1, 8]] });
michael@0 168
michael@0 169 verify("\nfoo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 170 { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
michael@0 171
michael@0 172 verify("foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 173 { name: "baz", chain: ["bar"], loc: [[1, 10], [1, 13]] });
michael@0 174
michael@0 175 verify("\nfoo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 176 { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
michael@0 177
michael@0 178 verify("nested.foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 179 { name: "bar", chain: [], loc: [[1, 12], [1, 15]] });
michael@0 180
michael@0 181 verify("\nnested.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 182 { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
michael@0 183
michael@0 184 verify("nested.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 185 { name: "baz", chain: ["bar"], loc: [[1, 17], [1, 20]] });
michael@0 186
michael@0 187 verify("\nnested.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 188 { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
michael@0 189
michael@0 190 verify("this.foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 191 { name: "bar", chain: [], loc: [[1, 10], [1, 13]] });
michael@0 192
michael@0 193 verify("\nthis.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 194 { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
michael@0 195
michael@0 196 verify("this.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 197 { name: "baz", chain: ["bar"], loc: [[1, 15], [1, 18]] });
michael@0 198
michael@0 199 verify("\nthis.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 200 { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
michael@0 201
michael@0 202 verify("this.nested.foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 203 { name: "bar", chain: [], loc: [[1, 17], [1, 20]] });
michael@0 204
michael@0 205 verify("\nthis.nested.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 206 { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
michael@0 207
michael@0 208 verify("this.nested.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 209 { name: "baz", chain: ["bar"], loc: [[1, 22], [1, 25]] });
michael@0 210
michael@0 211 verify("\nthis.nested.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 212 { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
michael@0 213
michael@0 214 verify("nested.this.foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 215 { name: "bar", chain: [], loc: [[1, 17], [1, 20]] });
michael@0 216
michael@0 217 verify("\nnested.this.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 218 { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
michael@0 219
michael@0 220 verify("nested.this.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 221 { name: "baz", chain: ["bar"], loc: [[1, 22], [1, 25]] });
michael@0 222
michael@0 223 verify("\nnested.this.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 224 { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
michael@0 225
michael@0 226 // New/CallExpression + VariableDeclarator + AssignmentExpression + ObjectExpression
michael@0 227
michael@0 228 verify("let target=foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 229 { name: "bar", chain: ["target"], loc: [[1, 16], [1, 19]] });
michael@0 230
michael@0 231 verify("\nlet\ntarget=\nfoo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 232 { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
michael@0 233
michael@0 234 verify("let target=foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 235 { name: "baz", chain: ["target", "bar"], loc: [[1, 21], [1, 24]] });
michael@0 236
michael@0 237 verify("\nlet\ntarget=\nfoo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 238 { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
michael@0 239
michael@0 240 verify("let target=nested.foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 241 { name: "bar", chain: ["target"], loc: [[1, 23], [1, 26]] });
michael@0 242
michael@0 243 verify("\nlet\ntarget=\nnested.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 244 { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
michael@0 245
michael@0 246 verify("let target=nested.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 247 { name: "baz", chain: ["target", "bar"], loc: [[1, 28], [1, 31]] });
michael@0 248
michael@0 249 verify("\nlet\ntarget=\nnested.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 250 { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
michael@0 251
michael@0 252 verify("let target=this.foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 253 { name: "bar", chain: ["target"], loc: [[1, 21], [1, 24]] });
michael@0 254
michael@0 255 verify("\nlet\ntarget=\nthis.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 256 { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
michael@0 257
michael@0 258 verify("let target=this.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 259 { name: "baz", chain: ["target", "bar"], loc: [[1, 26], [1, 29]] });
michael@0 260
michael@0 261 verify("\nlet\ntarget=\nthis.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 262 { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
michael@0 263
michael@0 264 verify("let target=this.nested.foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 265 { name: "bar", chain: ["target"], loc: [[1, 28], [1, 31]] });
michael@0 266
michael@0 267 verify("\nlet\ntarget=\nthis.nested.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 268 { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
michael@0 269
michael@0 270 verify("let target=this.nested.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 271 { name: "baz", chain: ["target", "bar"], loc: [[1, 33], [1, 36]] });
michael@0 272
michael@0 273 verify("\nlet\ntarget=\nthis.nested.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 274 { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
michael@0 275
michael@0 276 verify("let target=nested.this.foo({bar:function(){}})", e => e.type == "FunctionExpression",
michael@0 277 { name: "bar", chain: ["target"], loc: [[1, 28], [1, 31]] });
michael@0 278
michael@0 279 verify("\nlet\ntarget=\nnested.this.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 280 { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
michael@0 281
michael@0 282 verify("let target=nested.this.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
michael@0 283 { name: "baz", chain: ["target", "bar"], loc: [[1, 33], [1, 36]] });
michael@0 284
michael@0 285 verify("\nlet\ntarget=\nnested.this.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
michael@0 286 { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
michael@0 287
michael@0 288 finish();
michael@0 289 }

mercurial