Skip to content

Commit

Permalink
Fix scoping issues in PaperScript code.
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Jan 4, 2014
1 parent 0dddd89 commit 42bed58
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/core/PaperScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
* @name PaperScript
* @namespace
*/
var PaperScript = Base.exports.PaperScript = (function(root) {
var PaperScript = Base.exports.PaperScript = (function() {
// Locally turn of exports and define for inlined acorn / esprima.
// Just declaring the local vars is enough, as they will be undefined.
var exports, define,
// The scope into which the library is loaded.
scope = this;
/*#*/ if (__options.version == 'dev') {
// As the above inclusion loads code into the root scope during dev,
// set scope to root, so we can find the library.
scope = root;
/*#*/ } // __options.version == 'dev'
/*#*/ if (__options.parser == 'acorn') {
/*#*/ include('../../bower_components/acorn/acorn.min.js', { exports: false });
/*#*/ } else if (__options.parser == 'esprima') {
Expand Down Expand Up @@ -281,7 +276,7 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
// We need an additional line that returns the handlers in one object.
code += '\nreturn { ' + handlers + ' };';
/*#*/ if (__options.environment == 'browser') {
if (root.InstallTrigger) { // Firefox
if (window.InstallTrigger) { // Firefox
// Add a semi-colon at the start so Firefox doesn't swallow empty
// lines and shift error messages.
code = ';' + code;
Expand All @@ -306,18 +301,18 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
lineNumber += (new Error().lineNumber - lineNumber) * 3;
}
try {
res = new Function(params, code).apply(scope, args);
res = Function(params, code).apply(scope, args);
// NOTE: in order for the calculation of the above lineNumber
// offset to work, we cannot add any statements before the above
// line of code, nor can we put it into a separate function.
} catch (e) {
handle(e);
}
} else {
res = new Function(params, code).apply(scope, args);
res = Function(params, code).apply(scope, args);
}
/*#*/ } else { // !__options.environment == 'browser'
res = new Function(params, code).apply(scope, args);
res = Function(params, code).apply(scope, args);
/*#*/ } // !__options.environment == 'browser'
// Now install the 'global' tool and view handlers, and we're done!
Base.each(toolHandlers, function(key) {
Expand Down Expand Up @@ -428,4 +423,6 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
};

/*#*/ } // !__options.environment == 'browser'
})(this);
// Pass on `this` as the binding object, so we can reference Acorn both in
// development and in the built library.
}).call(this);

0 comments on commit 42bed58

Please sign in to comment.