PaperScript: Better deal with compile exceptions

This commit is contained in:
Jürg Lehni 2018-10-13 18:49:54 +02:00
parent d6d5accd1a
commit 70e58162f0

View file

@ -534,24 +534,25 @@ Base.exports.PaperScript = function() {
} else { } else {
func = Function(params, code); func = Function(params, code);
} }
var exports = func.apply(scope, args) || {}; var exports = func && func.apply(scope, args);
var obj = exports || {};
// Now install the 'global' tool and view handlers, and we're done! // Now install the 'global' tool and view handlers, and we're done!
Base.each(toolHandlers, function(key) { Base.each(toolHandlers, function(key) {
var value = exports[key]; var value = obj[key];
if (value) if (value)
tool[key] = value; tool[key] = value;
}); });
if (view) { if (view) {
if (exports.onResize) if (obj.onResize)
view.setOnResize(exports.onResize); view.setOnResize(obj.onResize);
// Emit resize event directly, so any user // Emit resize event directly, so any user
// defined resize handlers are called. // defined resize handlers are called.
view.emit('resize', { view.emit('resize', {
size: view.size, size: view.size,
delta: new Point() delta: new Point()
}); });
if (exports.onFrame) if (obj.onFrame)
view.setOnFrame(exports.onFrame); view.setOnFrame(obj.onFrame);
// Automatically request an update at the end. This is only needed // Automatically request an update at the end. This is only needed
// if the script does not actually produce anything yet, and the // if the script does not actually produce anything yet, and the
// used canvas contains previous content. // used canvas contains previous content.