some tests

This commit is contained in:
2023-06-01 22:02:03 +02:00
parent e3515901e4
commit 65a6312b8e
9 changed files with 153 additions and 40 deletions
@@ -21,27 +21,45 @@ export class OutputFrame extends BaseElement {
onUpdate(): void {
}
reset(onload: ((ev: Event) => void) | null = null, resetNotificationBubbles: boolean = true) {
reset(onload: ((ev: Event) => void) | null = null, resetNotificationBubbles: boolean = true, source: string | null = null) {
if (this.CurrentIframeScriptRemoveResponseListener != null) {
this.CurrentIframeScriptRemoveResponseListener();
this.CurrentIframeScriptRemoveResponseListener = null;
}
if (this.Iframe && this.hasChild(this.Iframe)) {
this.Iframe.setAttribute("sandbox", "allow-pointer-lock allow-same-origin");
console.log("REMOVING IFRAME!");
this.removeChild(this.Iframe);
}
this.Iframe = document.createElement("iframe");
this.Iframe.setAttribute("sandbox", "allow-pointer-lock allow-same-origin allow-scripts");
this.Iframe.src = GetOutputFrameUrl();
if (onload) {
this.Iframe.onload = ((ev) => {
console.log("IFRAME LOADED");
onload(ev);
if (this.Iframe)
this.Iframe.onload = () => { };
});
}
console.log("IF SOURCE BEFORE", this.Iframe.src);
if (source != null) {
console.log("CUSOMSRC S:"+source, source);
this.Iframe.src = source;
}
else {
this.Iframe.src = GetOutputFrameUrl();
}
console.log("IF SOURCE AFTER", this.Iframe.src);
this.appendChild(this.Iframe);
if (source !== "") {
this.appendChild(this.Iframe);
}
else {
console.log("SPPCHD");
}
if (resetNotificationBubbles) {
var bubbles = GetNotificationBubbles();
@@ -52,13 +70,18 @@ export class OutputFrame extends BaseElement {
}
setError() {
console.log("RCALLED");
this.reset(() => {
if (this.Iframe)
this.Iframe.src = GetOutputFrameUrl() + "execution-time-error.html";
});
if (this.Iframe) {
// this.Iframe.contentWindow?.location.reload();
console.log("RESET AFTER", this.Iframe.src);
}
}, true, "");//GetOutputFrameUrl("execution-time-error.html"));
}
setContent(language: string, value: string) {
console.log("setting content", language, value);
this.contents[language] = value;
this.reset(() => {
for (const lang in this.contents) {
@@ -72,14 +95,16 @@ export class OutputFrame extends BaseElement {
}
doPostMessage(language: string, value: string) {
this.CurrentIframeScriptRemoveResponseListener = postMessage(this.Iframe?.contentWindow, language, this.contents[language], language == 'javascript' ? (executeTimeInMs, exceedTimeInMs) => {
if (executeTimeInMs === -1) {
this.setError();
}
else {
var bubbles = GetNotificationBubbles();
bubbles.add(language + " executed in: " + executeTimeInMs + "ms", "info");
}
} : undefined);
this.CurrentIframeScriptRemoveResponseListener = postMessage(this.Iframe?.contentWindow, language, this.contents[language], language == 'javascript' ?
(executeTimeInMs, exceedTimeInMs) => {
console.log("onresponse", executeTimeInMs + " " + exceedTimeInMs);
if (executeTimeInMs === -1) {
this.setError();
}
else {
var bubbles = GetNotificationBubbles();
bubbles.add(language + " executed in: " + executeTimeInMs + "ms", "info");
}
} : undefined);
}
}