summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser_webconsole_strict_mode_errors.js
blob: f6304b24d8a00cd614298aa91e7dd174bbb2317e (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
78
79
80
81
82
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Check that "use strict" JS errors generate errors, not warnings.

"use strict";

add_task(function* () {
  // On e10s, the exception is triggered in child process
  // and is ignored by test harness
  if (!Services.appinfo.browserTabsRemoteAutostart) {
    expectUncaughtException();
  }
  yield loadTab("data:text/html;charset=utf8,<script>'use strict';var arguments;</script>");

  let hud = yield openConsole();

  yield waitForMessages({
    webconsole: hud,
    messages: [
      {
        text: "SyntaxError: 'arguments' can't be defined or assigned to in strict mode code",
        category: CATEGORY_JS,
        severity: SEVERITY_ERROR,
      },
    ],
  });

  if (!Services.appinfo.browserTabsRemoteAutostart) {
    expectUncaughtException();
  }
  BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "data:text/html;charset="
    + "utf8,<script>'use strict';function f(a, a) {};</script>");

  yield waitForMessages({
    webconsole: hud,
    messages: [
      {
        text: "SyntaxError: duplicate formal argument a",
        category: CATEGORY_JS,
        severity: SEVERITY_ERROR,
      },
    ],
  });

  if (!Services.appinfo.browserTabsRemoteAutostart) {
    expectUncaughtException();
  }
  BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "data:text/html;charset="
    + "utf8,<script>'use strict';var o = {get p() {}};o.p = 1;</script>");

  yield waitForMessages({
    webconsole: hud,
    messages: [
      {
        text: 'TypeError: setting getter-only property "p"',
        category: CATEGORY_JS,
        severity: SEVERITY_ERROR,
      },
    ],
  });

  if (!Services.appinfo.browserTabsRemoteAutostart) {
    expectUncaughtException();
  }
  BrowserTestUtils.loadURI(gBrowser.selectedBrowser,
    "data:text/html;charset=utf8,<script>'use strict';v = 1;</script>");

  yield waitForMessages({
    webconsole: hud,
    messages: [
      {
        text: "ReferenceError: assignment to undeclared variable v",
        category: CATEGORY_JS,
        severity: SEVERITY_ERROR,
      },
    ],
  });

  hud = null;
});