-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only sandbox dynamic javascript evaluation, allows using workers in w…
…ebviews
- Loading branch information
Showing
8 changed files
with
401 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div id="paper"></div> | ||
<script src="libs/require.js"></script> | ||
<script src="libs/jquery.min.js"></script> | ||
<script> | ||
require(['cnc/cam', 'libs/svg'], function (cam, svg) { | ||
window.addEventListener('message', function (event) { | ||
switch (event.data.command) { | ||
case 'eval': | ||
try { | ||
var code = event.data.code; | ||
var paper = new svg(document.getElementById("paper")); | ||
var machine = new cam.Machine(paper); | ||
|
||
function sendResponse() { | ||
var operationsData = []; | ||
for (var i = 0; i < machine.operations.length; ++i) { | ||
var operation = machine.operations[i]; | ||
operationsData.push({ | ||
className: operation.constructor.name, | ||
path: operation.path | ||
}); | ||
} | ||
event.source.postMessage({ | ||
command: 'eval-result', | ||
success: true, | ||
result: { | ||
operations: operationsData, | ||
svg: paper.node.innerHTML | ||
}, | ||
requestIndex: event.data.requestIndex | ||
}, event.origin); | ||
} | ||
|
||
function sendError(message) { | ||
event.source.postMessage({ | ||
command: 'eval-result', | ||
success: false, | ||
error: message, | ||
requestIndex: event.data.requestIndex | ||
}, event.origin); | ||
} | ||
|
||
var waitForWhenDone = true; | ||
|
||
function whenDone() { | ||
if (waitForWhenDone) | ||
sendResponse(); | ||
else | ||
throw new Exception("You must return true at the end of your code if you use whenDone"); | ||
} | ||
|
||
waitForWhenDone = new Function(['cam', 'machine', 'whenDone'], code)(cam, machine, whenDone); | ||
} catch (error) { | ||
sendError(error.message); | ||
return; | ||
} | ||
if (!waitForWhenDone) | ||
sendResponse(); | ||
break; | ||
} | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,6 @@ | |
} | ||
}, | ||
"sandbox": { | ||
"pages": ["CAM.html", "oldCAM.html"] | ||
"pages": ["js_sandbox.html"] | ||
} | ||
} | ||
} |