xref: /aosp_15_r20/external/pdfium/testing/resources/javascript/constructor.js (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1// Copyright 2020 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5function testLegalConstructor(name, allowed) {
6  const constructorString = name + ".constructor";
7  var constructor;
8  try {
9    constructor = eval(constructorString);
10  } catch (e) {
11    app.alert("FAIL: No such " + constructorString);
12    return;
13  }
14  try {
15    constructor();
16    app.alert("FAIL: " + constructorString + "(): returned");
17  } catch (e) {
18    app.alert("PASS: " + constructorString + "(): " + e);
19  }
20  try {
21    var thing = new constructor;
22    app.alert("PASS: new " + constructorString + ": " + thing);
23  } catch (e) {
24    app.alert("FAIL: new " + constructorString + ": " + e);
25  }
26}
27
28function testIllegalConstructor(name, allowed) {
29  const constructorString = name + ".constructor";
30  var constructor;
31  try {
32    constructor = eval(constructorString);
33  } catch (e) {
34    app.alert("FAIL: No such " + constructorString);
35    return;
36  }
37  try {
38    constructor();
39    app.alert("FAIL: " + constructorString + "(): returned");
40  } catch (e) {
41    app.alert("PASS: " + constructorString + "(): " + e);
42  }
43  try {
44    new constructor;
45    app.alert("FAIL: new " + constructorString + ": returned");
46  } catch (e) {
47    app.alert("PASS: new " + constructorString + ": " + e);
48  }
49}
50