summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/extensions/unterminated-literal-error-location.js
blob: de9767a1c2bb1b5bda482c32f47ba2ce8ed4b7ab (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
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
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/
 */

var BUGNUMBER = 1434429;
var summary =
  "Report unterminated string/template literal errors with the line/column " +
  "number of the point of non-termination";

function test(f, quotes, [line, col])
{
  var caught = false;
  try
  {
    f();
  }
  catch (e)
  {
    caught = true;
    assertEq(e.lineNumber, line, "line number");
    assertEq(e.columnNumber, col, "column number");
    assertEq(e.message.includes(quotes), true,
             "message must contain delimiter");
  }

  assertEq(caught, true);
}

test(function() {
      //0123
  eval("'hi");
}, "''", [1, 3]);

test(function() {
      //0123 4
  eval("'hi\\");
}, "''", [1, 4]);

test(function() {
      //0123456
  eval("   'hi");
}, "''", [1, 6]);

test(function() {
      //0123456 7
  eval("   'hi\\");
}, "''", [1, 7]);

test(function() {
      //01234567 01234567
  eval('var x =\n    "hi');
}, '""', [2, 7]);

test(function() {
      //0123456  01234567 8
  eval('var x =\n    "hi\\');
}, '""', [2, 8]);

test(function() {
      //                                          1
      //0123456  01234567   012345678   01234567890123
  eval('var x =\n    "hi\\\n     bye\\\n    no really');
}, '""', [4, 13]);

test(function() {
      //                                          1
      //0123456  01234567   012345678   01234567890123 4
  eval('var x =\n    "hi\\\n     bye\\\n    no really\\');
}, '""', [4, 14]);

test(function() {
      //0123456  01234567   012345678
  eval('var x =\n    "hi\\\n     bye\n');
}, '""', [3, 8]);

test(function() {
      //0123456  01234567   012345678 9
  eval('var x =\n    "hi\\\n     bye\\');
}, '""', [3, 9]);

test(function() {
      //0123456  01234567
  eval('var x =\n      `');
}, '``', [2, 7]);

test(function() {
      //0123456  01234567 8
  eval('var x =\n      `\\');
}, '``', [2, 8]);

test(function() {
      //                   1
      //0123456  0123456789012345
  eval('var x =\n    htmlEscape`');
}, '``', [2, 15]);

test(function() {
      //                   1
      //0123456  0123456789012345 6
  eval('var x =\n    htmlEscape`\\');
}, '``', [2, 16]);

test(function() {
      //                   1
      //0123456  01234567890123  01234
  eval('var x =\n    htmlEscape\n   `');
}, '``', [3, 4]);

test(function() {
      //                   1
      //0123456  01234567890123  01234 5
  eval('var x =\n    htmlEscape\n   `\\');
}, '``', [3, 5]);

if (typeof reportCompare === "function")
  reportCompare(0, 0, "ok");

print("Tests complete");