Skip to content

Commit 25b6089

Browse files
Add support for non string createElement calls (#379)
1 parent 70666bd commit 25b6089

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

integration-test/test-pages/runtime-checks/pages/basic-run.html

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
];
4242
});
4343

44-
// eslint-disable-next-line no-undef
4544
test('Script that should execute', async () => {
4645
window.scripty2Ran = false;
4746
const scriptElement = document.createElement('script');
@@ -66,7 +65,32 @@
6665
];
6766
});
6867

69-
// eslint-disable-next-line no-undef
68+
test('Script array createElement that should execute', async () => {
69+
window.scripty2aRan = false;
70+
let scriptElementArray
71+
try {
72+
scriptElementArray = document.createElement(['script']);
73+
scriptElementArray.innerText = 'window.scripty2aRan = true';
74+
scriptElementArray.id = 'scripty2a';
75+
scriptElementArray.setAttribute('type', 'application/javascript');
76+
document.body.appendChild(scriptElementArray);
77+
} catch {
78+
// We shouldn't ever get here unless the test is failing in which case the run check will fail.
79+
}
80+
const hadInspectorNode = scriptElementArray === document.querySelector('ddg-runtime-checks:last-of-type');
81+
const instanceofResult = scriptElementArray instanceof HTMLScriptElement;
82+
const scriptyArray = document.querySelector('#scripty2a');
83+
84+
return [
85+
{ name: 'hadInspectorNode', result: hadInspectorNode, expected: true },
86+
{ name: 'expect script to match', result: scriptyArray, expected: scriptElementArray },
87+
{ name: 'instanceof matches HTMLScriptElement', result: instanceofResult, expected: true },
88+
{ name: 'scripty.type', result: scriptyArray?.type, expected: 'application/javascript' },
89+
{ name: 'scripty.id', result: scriptyArray?.id, expected: 'scripty2a' },
90+
{ name: 'script ran', result: window.scripty2aRan, expected: true }
91+
];
92+
});
93+
7094
test('Invalid external script should trigger error listeners', async () => {
7195
const scriptElement = document.createElement('script');
7296
scriptElement.id = 'scripty3';

src/features/runtime-checks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ function overrideCreateElement () {
434434
const proxy = new DDGProxy(featureName, Document.prototype, 'createElement', {
435435
apply (fn, scope, args) {
436436
if (args.length >= 1) {
437-
const initialTagName = args[0].toLowerCase()
437+
// String() is used to coerce the value to a string (For: ProseMirror/prosemirror-model/src/to_dom.ts)
438+
const initialTagName = String(args[0]).toLowerCase()
438439
if (shouldInterrogate(initialTagName)) {
439440
args[0] = 'ddg-runtime-checks'
440441
const el = Reflect.apply(fn, scope, args)

0 commit comments

Comments
 (0)