Move JS helper testIllegalConstructor() to its own .js file.
Allow using this on the xfa side someday.
-- also add a test for globalThis variable while at it.
Change-Id: I8dde7e47b800c6d3d88a217d5f1680544f36cb4f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/66170
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/testing/resources/javascript/constructor.in b/testing/resources/javascript/constructor.in
index 1211f89..c3cdff6 100644
--- a/testing/resources/javascript/constructor.in
+++ b/testing/resources/javascript/constructor.in
@@ -31,29 +31,9 @@
{{streamlen}}
>>
stream
-function testIllegalConstructor(name, allowed) {
- const constructorString = name + ".constructor";
- let constructor;
- try {
- constructor = eval(constructorString);
- } catch (e) {
- app.alert("FAIL: No such " + constructorString);
- return;
- }
- try {
- constructor();
- app.alert("FAIL: " + constructorString + "(): returned");
- } catch (e) {
- app.alert("PASS: " + constructorString + "(): " + e);
- }
- try {
- new constructor;
- app.alert("FAIL: new " + constructorString + ": returned");
- } catch (e) {
- app.alert("PASS: new " + constructorString + ": " + e);
- }
-}
+{{include constructor.js}}
testIllegalConstructor("this");
+testIllegalConstructor("globalThis");
testIllegalConstructor("app");
testIllegalConstructor("event");
testIllegalConstructor("font");
diff --git a/testing/resources/javascript/constructor.js b/testing/resources/javascript/constructor.js
new file mode 100644
index 0000000..bc6d478
--- /dev/null
+++ b/testing/resources/javascript/constructor.js
@@ -0,0 +1,26 @@
+// Copyright 2020 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function testIllegalConstructor(name, allowed) {
+ const constructorString = name + ".constructor";
+ let constructor;
+ try {
+ constructor = eval(constructorString);
+ } catch (e) {
+ app.alert("FAIL: No such " + constructorString);
+ return;
+ }
+ try {
+ constructor();
+ app.alert("FAIL: " + constructorString + "(): returned");
+ } catch (e) {
+ app.alert("PASS: " + constructorString + "(): " + e);
+ }
+ try {
+ new constructor;
+ app.alert("FAIL: new " + constructorString + ": returned");
+ } catch (e) {
+ app.alert("PASS: new " + constructorString + ": " + e);
+ }
+}
diff --git a/testing/resources/javascript/constructor_expected.txt b/testing/resources/javascript/constructor_expected.txt
index af03337..bb13a3a 100644
--- a/testing/resources/javascript/constructor_expected.txt
+++ b/testing/resources/javascript/constructor_expected.txt
@@ -1,5 +1,7 @@
Alert: PASS: this.constructor(): illegal constructor
Alert: PASS: new this.constructor: not a dynamic object
+Alert: PASS: globalThis.constructor(): illegal constructor
+Alert: PASS: new globalThis.constructor: not a dynamic object
Alert: PASS: app.constructor(): illegal constructor
Alert: PASS: new app.constructor: not a dynamic object
Alert: PASS: event.constructor(): illegal constructor