mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-13 22:48:54 -04:00
Avoid necessity of try-catch around code evaluation by declaring all local variables that we are looking for.
This commit is contained in:
parent
afe61d61ac
commit
450d277fb4
1 changed files with 15 additions and 10 deletions
|
@ -131,18 +131,21 @@ var PaperScript = new function() {
|
|||
|
||||
function run(code) {
|
||||
with (paper) {
|
||||
paper.tool = /on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code) && new Tool();
|
||||
var res = eval(compile(code)),
|
||||
doc = paper.document;
|
||||
if (paper.tool) {
|
||||
var doc = paper.document,
|
||||
tool = paper.tool = /on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code)
|
||||
&& new Tool(null, doc),
|
||||
onEditOptions, onOptions, onSelect, onDeselect, onReselect,
|
||||
onMouseDown, onMouseUp, onMouseDrag, onMouseMove, onKeyDown,
|
||||
onKeyUp,
|
||||
res = eval(compile(code));
|
||||
if (tool) {
|
||||
Base.each(['onEditOptions', 'onOptions', 'onSelect',
|
||||
'onDeselect', 'onReselect', 'onMouseDown', 'onMouseUp',
|
||||
'onMouseDrag', 'onMouseMove', 'onKeyDown', 'onKeyUp'], function(key) {
|
||||
try {
|
||||
paper.tool[key] = eval(key);
|
||||
} catch (e) {
|
||||
'onDeselect', 'onReselect', 'onMouseDown', 'onMouseUp',
|
||||
'onMouseDrag', 'onMouseMove', 'onKeyDown', 'onKeyUp'],
|
||||
function(key) {
|
||||
tool[key] = eval(key);
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
try {
|
||||
var onFrame = eval('onFrame');
|
||||
|
@ -191,6 +194,8 @@ var PaperScript = new function() {
|
|||
// so the active document is defined.
|
||||
var canvas = script.getAttribute('canvas');
|
||||
if (canvas && (canvas = document.getElementById(canvas))) {
|
||||
// var canvas = script.attributes.canvas;
|
||||
// if (canvas = canvas && document.getElementById(canvas)) {
|
||||
new Document(canvas);
|
||||
}
|
||||
if (script.src) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue