-
Notifications
You must be signed in to change notification settings - Fork 9
/
html.js
24 lines (22 loc) · 985 Bytes
/
html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const {getFramesArray, getDeclarativeShadows} = require('./utils');
const {document, getChildElementCount, setInnerHTML} = require('./natives');
const {error, ERR_DECLARATIVE_SHADOWS_BLOCKED, ERR_HTML_FRAMES_SRCDOC_BLOCKED} = require('./log');
function assertHTML(args) {
for (let i = 0; i < args.length; i++) {
const template = document.createElement('html');
setInnerHTML(template, args[i]);
if (getChildElementCount(template)) {
if (getDeclarativeShadows(template).length > 0) {
throw error(ERR_DECLARATIVE_SHADOWS_BLOCKED, args[i]);
}
const frames = getFramesArray(template, false);
for (let j = 0; j < frames.length; j++) {
const frame = frames[j];
if (template.getAttribute.call(frame, 'srcdoc')) {
throw error(ERR_HTML_FRAMES_SRCDOC_BLOCKED, args[i]);
}
}
}
}
}
module.exports = {assertHTML};