mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Only include the global handlers in the return statement that actually seem to be defined.
This commit is contained in:
parent
4302682c1c
commit
227d511fc0
1 changed files with 10 additions and 5 deletions
|
@ -239,7 +239,7 @@ var PaperScript = Base.exports.PaperScript = (function() {
|
|||
var view = scope.getView(),
|
||||
// Only create a tool object if something resembling a tool handler
|
||||
// definition is contained in the code.
|
||||
tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code)
|
||||
tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/.test(code)
|
||||
? new Tool()
|
||||
: null,
|
||||
toolHandlers = tool ? tool._events : [],
|
||||
|
@ -270,11 +270,16 @@ var PaperScript = Base.exports.PaperScript = (function() {
|
|||
// end of the code execution, so we can retrieve their values from the
|
||||
// function call.
|
||||
handlers = Base.each(handlers, function(key) {
|
||||
params.push(key);
|
||||
this.push(key + ': ' + key);
|
||||
// Check for each handler explicitely and only return them if they
|
||||
// seem to exist.
|
||||
if (new RegExp('\\s+' + key + '\\b').test(code)) {
|
||||
params.push(key);
|
||||
this.push(key + ': ' + key);
|
||||
}
|
||||
}, []).join(', ');
|
||||
// We need an additional line that returns the handlers in one object.
|
||||
code += '\nreturn { ' + handlers + ' };';
|
||||
if (handlers)
|
||||
code += '\nreturn { ' + handlers + ' };';
|
||||
/*#*/ if (__options.environment == 'browser') {
|
||||
if (window.InstallTrigger || window.chrome) { // Firefox and Chrome
|
||||
// On Firefox, all error numbers inside dynamically compiled code
|
||||
|
@ -301,7 +306,7 @@ var PaperScript = Base.exports.PaperScript = (function() {
|
|||
/*#*/ } else { // !__options.environment == 'browser'
|
||||
func = Function(params, code);
|
||||
/*#*/ } // !__options.environment == 'browser'
|
||||
var res = func.apply(scope, args);
|
||||
var res = func.apply(scope, args) || {};
|
||||
// Now install the 'global' tool and view handlers, and we're done!
|
||||
Base.each(toolHandlers, function(key) {
|
||||
var value = res[key];
|
||||
|
|
Loading…
Reference in a new issue