added sanity check
This commit is contained in:
@@ -5,6 +5,7 @@ import { OutputFrame } from "../output-frame/output-frame";
|
||||
import { debounceManager } from "../../../shared/ensure-debounce";
|
||||
import * as sessionApi from '../../../shared/session-api';
|
||||
import { isSessionPage } from "../../../shared/page";
|
||||
import { sanityConvert } from "../../../shared/sanity-code-check";
|
||||
|
||||
export class CodeEditor extends BaseElement {
|
||||
|
||||
@@ -45,13 +46,13 @@ export class CodeEditor extends BaseElement {
|
||||
localStorage.setItem(this.language + "LastInputCache", this.input);
|
||||
debounce.ensureDebounce(() => {
|
||||
sessionApi.setSessionData(this.language, this.input);
|
||||
this.outputFrame.setContent(this.language, this.input);
|
||||
this.outputFrame.setContent(this.language, this.language.toLowerCase() === "javascript" ? sanityConvert(this.input) : this.input);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.waitFor(this.outputFrame, () => {
|
||||
this.outputFrame.setContent(this.language, isSessionPage() ? "" : this.input);
|
||||
this.outputFrame.setContent(this.language, isSessionPage() ? "" : (this.language.toLowerCase() === "javascript" ? sanityConvert(this.input) : this.input));
|
||||
});
|
||||
|
||||
}
|
||||
@@ -62,7 +63,7 @@ export class CodeEditor extends BaseElement {
|
||||
this.lastInputCache = this.input;
|
||||
localStorage.setItem(this.language + "LastInputCache", this.input);
|
||||
this.editor.setValue(input);
|
||||
this.outputFrame.setContent(this.language, this.input);
|
||||
this.outputFrame.setContent(this.language, this.language.toLowerCase() === "javascript" ? sanityConvert(this.input) : this.input);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ export class OutputFrame extends BaseElement {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -38,28 +37,21 @@ export class OutputFrame extends BaseElement {
|
||||
this.Iframe.setAttribute("sandbox", "allow-pointer-lock allow-same-origin allow-scripts");
|
||||
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);
|
||||
|
||||
if (source !== "") {
|
||||
this.appendChild(this.Iframe);
|
||||
}
|
||||
else {
|
||||
console.log("SPPCHD");
|
||||
}
|
||||
|
||||
if (resetNotificationBubbles) {
|
||||
var bubbles = GetNotificationBubbles();
|
||||
@@ -70,18 +62,16 @@ export class OutputFrame extends BaseElement {
|
||||
}
|
||||
|
||||
setError() {
|
||||
console.log("RCALLED");
|
||||
this.reset(() => {
|
||||
console.log("ERROR RESET");
|
||||
if (this.Iframe) {
|
||||
// this.Iframe.contentWindow?.location.reload();
|
||||
console.log("RESET AFTER", this.Iframe.src);
|
||||
// this.Iframe.contentWindow?.location.reload();
|
||||
}
|
||||
}, true, "");//GetOutputFrameUrl("execution-time-error.html"));
|
||||
}, true, "");
|
||||
|
||||
}
|
||||
|
||||
setContent(language: string, value: string) {
|
||||
console.log("setting content", language, value);
|
||||
this.contents[language] = value;
|
||||
this.reset(() => {
|
||||
for (const lang in this.contents) {
|
||||
@@ -97,7 +87,6 @@ export class OutputFrame extends BaseElement {
|
||||
doPostMessage(language: string, value: string) {
|
||||
this.CurrentIframeScriptRemoveResponseListener = postMessage(this.Iframe?.contentWindow, language, this.contents[language], language == 'javascript' ?
|
||||
(executeTimeInMs, exceedTimeInMs) => {
|
||||
console.log("onresponse", executeTimeInMs + " " + exceedTimeInMs);
|
||||
if (executeTimeInMs === -1) {
|
||||
this.setError();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ export class WindowControlConnector extends BaseElement {
|
||||
|
||||
if (distTarget) {
|
||||
var visibleTargetChildren = this.visibleChildren(distTarget);
|
||||
console.log(visibleTargetChildren);
|
||||
|
||||
if (visibleTargetChildren.length === 0) {
|
||||
distTarget.classList.add("force-close");
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
<render-canvas></render-canvas>
|
||||
<loading-spinner></loading-spinner>
|
||||
hi
|
||||
<loading-spinner></loading-spinner>
|
||||
@@ -0,0 +1,17 @@
|
||||
export function sanityConvert(code: string, maxLoops: number = 2000) {
|
||||
var beforeConidition = "var conditionCount = " + maxLoops + "; \n";
|
||||
var insideCondition = "\n --conditionCount; \n if (conditionCount <= 0) { break; } \n";
|
||||
|
||||
const regex = /(while|for|foreach)(\s*\([^)]*\)\s*)({[^}]*}|[^{;]*;?)/gs;
|
||||
const output = code.replace(regex, (match, p1, p2, p3) => {
|
||||
let statement = p3.trim();
|
||||
if (statement.startsWith('{') && statement.endsWith('}')) {
|
||||
statement = statement.replace('{', '{' + insideCondition);
|
||||
} else {
|
||||
statement = statement.endsWith(';') ? statement.slice(0, -1) : statement;
|
||||
statement = `{${insideCondition}${statement};}`;
|
||||
}
|
||||
return `${beforeConidition}${p1}${p2}${statement}`;
|
||||
});
|
||||
return output;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
var apiUrl = "https://codeeditor-api.davidssoft.com/";
|
||||
//var apiUrl = "https://codeeditor-api.azurewebsites.net/";
|
||||
//var apiUrl = "https://codeeditor-api.davidssoft.com/";
|
||||
var apiUrl = "https://codeeditor-api.azurewebsites.net/";
|
||||
|
||||
export function hasSession() {
|
||||
var localstorageSessionId = localStorage.getItem("sessionId");
|
||||
|
||||
@@ -9,7 +9,7 @@ export function IsLocalhost(): boolean {
|
||||
export function GetOutputFrameUrl(path: string = ""): string {
|
||||
var v = "?v=" + (+new Date());
|
||||
if (IsLocalhost()) {
|
||||
return "http://127.0.0.1:8021/" + path + v;
|
||||
return "http://localhost:8021/" + path + v;
|
||||
}
|
||||
else {
|
||||
return "https://outputframe.davidmeincke.dk/" + path + v;
|
||||
|
||||
Reference in New Issue
Block a user