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 { debounceManager } from "../../../shared/ensure-debounce";
|
||||||
import * as sessionApi from '../../../shared/session-api';
|
import * as sessionApi from '../../../shared/session-api';
|
||||||
import { isSessionPage } from "../../../shared/page";
|
import { isSessionPage } from "../../../shared/page";
|
||||||
|
import { sanityConvert } from "../../../shared/sanity-code-check";
|
||||||
|
|
||||||
export class CodeEditor extends BaseElement {
|
export class CodeEditor extends BaseElement {
|
||||||
|
|
||||||
@@ -45,13 +46,13 @@ export class CodeEditor extends BaseElement {
|
|||||||
localStorage.setItem(this.language + "LastInputCache", this.input);
|
localStorage.setItem(this.language + "LastInputCache", this.input);
|
||||||
debounce.ensureDebounce(() => {
|
debounce.ensureDebounce(() => {
|
||||||
sessionApi.setSessionData(this.language, this.input);
|
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.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;
|
this.lastInputCache = this.input;
|
||||||
localStorage.setItem(this.language + "LastInputCache", this.input);
|
localStorage.setItem(this.language + "LastInputCache", this.input);
|
||||||
this.editor.setValue(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)) {
|
if (this.Iframe && this.hasChild(this.Iframe)) {
|
||||||
this.Iframe.setAttribute("sandbox", "allow-pointer-lock allow-same-origin");
|
this.Iframe.setAttribute("sandbox", "allow-pointer-lock allow-same-origin");
|
||||||
console.log("REMOVING IFRAME!");
|
|
||||||
this.removeChild(this.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");
|
this.Iframe.setAttribute("sandbox", "allow-pointer-lock allow-same-origin allow-scripts");
|
||||||
if (onload) {
|
if (onload) {
|
||||||
this.Iframe.onload = ((ev) => {
|
this.Iframe.onload = ((ev) => {
|
||||||
console.log("IFRAME LOADED");
|
|
||||||
onload(ev);
|
onload(ev);
|
||||||
if (this.Iframe)
|
if (this.Iframe)
|
||||||
this.Iframe.onload = () => { };
|
this.Iframe.onload = () => { };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log("IF SOURCE BEFORE", this.Iframe.src);
|
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
console.log("CUSOMSRC S:"+source, source);
|
|
||||||
this.Iframe.src = source;
|
this.Iframe.src = source;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.Iframe.src = GetOutputFrameUrl();
|
this.Iframe.src = GetOutputFrameUrl();
|
||||||
}
|
}
|
||||||
console.log("IF SOURCE AFTER", this.Iframe.src);
|
|
||||||
|
|
||||||
if (source !== "") {
|
if (source !== "") {
|
||||||
this.appendChild(this.Iframe);
|
this.appendChild(this.Iframe);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
console.log("SPPCHD");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resetNotificationBubbles) {
|
if (resetNotificationBubbles) {
|
||||||
var bubbles = GetNotificationBubbles();
|
var bubbles = GetNotificationBubbles();
|
||||||
@@ -70,18 +62,16 @@ export class OutputFrame extends BaseElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setError() {
|
setError() {
|
||||||
console.log("RCALLED");
|
|
||||||
this.reset(() => {
|
this.reset(() => {
|
||||||
|
console.log("ERROR RESET");
|
||||||
if (this.Iframe) {
|
if (this.Iframe) {
|
||||||
// this.Iframe.contentWindow?.location.reload();
|
// this.Iframe.contentWindow?.location.reload();
|
||||||
console.log("RESET AFTER", this.Iframe.src);
|
|
||||||
}
|
}
|
||||||
}, true, "");//GetOutputFrameUrl("execution-time-error.html"));
|
}, true, "");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setContent(language: string, value: string) {
|
setContent(language: string, value: string) {
|
||||||
console.log("setting content", language, value);
|
|
||||||
this.contents[language] = value;
|
this.contents[language] = value;
|
||||||
this.reset(() => {
|
this.reset(() => {
|
||||||
for (const lang in this.contents) {
|
for (const lang in this.contents) {
|
||||||
@@ -97,7 +87,6 @@ export class OutputFrame extends BaseElement {
|
|||||||
doPostMessage(language: string, value: string) {
|
doPostMessage(language: string, value: string) {
|
||||||
this.CurrentIframeScriptRemoveResponseListener = postMessage(this.Iframe?.contentWindow, language, this.contents[language], language == 'javascript' ?
|
this.CurrentIframeScriptRemoveResponseListener = postMessage(this.Iframe?.contentWindow, language, this.contents[language], language == 'javascript' ?
|
||||||
(executeTimeInMs, exceedTimeInMs) => {
|
(executeTimeInMs, exceedTimeInMs) => {
|
||||||
console.log("onresponse", executeTimeInMs + " " + exceedTimeInMs);
|
|
||||||
if (executeTimeInMs === -1) {
|
if (executeTimeInMs === -1) {
|
||||||
this.setError();
|
this.setError();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ export class WindowControlConnector extends BaseElement {
|
|||||||
|
|
||||||
if (distTarget) {
|
if (distTarget) {
|
||||||
var visibleTargetChildren = this.visibleChildren(distTarget);
|
var visibleTargetChildren = this.visibleChildren(distTarget);
|
||||||
console.log(visibleTargetChildren);
|
|
||||||
|
|
||||||
if (visibleTargetChildren.length === 0) {
|
if (visibleTargetChildren.length === 0) {
|
||||||
distTarget.classList.add("force-close");
|
distTarget.classList.add("force-close");
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
<render-canvas></render-canvas>
|
<render-canvas></render-canvas>
|
||||||
<loading-spinner></loading-spinner>
|
<loading-spinner></loading-spinner>
|
||||||
hi
|
|
||||||
@@ -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.davidssoft.com/";
|
||||||
//var apiUrl = "https://codeeditor-api.azurewebsites.net/";
|
var apiUrl = "https://codeeditor-api.azurewebsites.net/";
|
||||||
|
|
||||||
export function hasSession() {
|
export function hasSession() {
|
||||||
var localstorageSessionId = localStorage.getItem("sessionId");
|
var localstorageSessionId = localStorage.getItem("sessionId");
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export function IsLocalhost(): boolean {
|
|||||||
export function GetOutputFrameUrl(path: string = ""): string {
|
export function GetOutputFrameUrl(path: string = ""): string {
|
||||||
var v = "?v=" + (+new Date());
|
var v = "?v=" + (+new Date());
|
||||||
if (IsLocalhost()) {
|
if (IsLocalhost()) {
|
||||||
return "http://127.0.0.1:8021/" + path + v;
|
return "http://localhost:8021/" + path + v;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "https://outputframe.davidmeincke.dk/" + path + v;
|
return "https://outputframe.davidmeincke.dk/" + path + v;
|
||||||
|
|||||||
Reference in New Issue
Block a user