diff options
Diffstat (limited to 'threads.js')
| -rw-r--r-- | threads.js | 57 |
1 files changed, 52 insertions, 5 deletions
@@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2013-December-11'; +modules.threads = '2014-January-08'; var ThreadManager; var Process; @@ -151,15 +151,19 @@ ThreadManager.prototype.startProcess = function (block, isThreadSafe) { return newProc; }; -ThreadManager.prototype.stopAll = function () { +ThreadManager.prototype.stopAll = function (excpt) { + // excpt is optional this.processes.forEach(function (proc) { - proc.stop(); + if (proc !== excpt) { + proc.stop(); + } }); }; -ThreadManager.prototype.stopAllForReceiver = function (rcvr) { +ThreadManager.prototype.stopAllForReceiver = function (rcvr, excpt) { + // excpt is optional this.processes.forEach(function (proc) { - if (proc.homeContext.receiver === rcvr) { + if (proc.homeContext.receiver === rcvr && proc !== excpt) { proc.stop(); if (rcvr.isClone) { proc.isDead = true; @@ -1368,6 +1372,29 @@ Process.prototype.doStopAll = function () { } }; +Process.prototype.doStopOthers = function (choice) { + var stage; + if (this.homeContext.receiver) { + stage = this.homeContext.receiver.parentThatIsA(StageMorph); + if (stage) { + + switch (this.inputOption(choice)) { + case 'all but this script': + stage.threads.stopAll(this); + break; + case 'other scripts in sprite': + stage.threads.stopAllForReceiver( + this.homeContext.receiver, + this + ); + break; + default: + nop(); + } + } + } +}; + Process.prototype.doWarp = function (body) { // execute my contents block atomically (more or less) var outer = this.context.outerContext, // for tail call elimination @@ -1730,6 +1757,11 @@ Process.prototype.reportURL = function (url) { if (!this.httpRequest) { this.httpRequest = new XMLHttpRequest(); this.httpRequest.open("GET", 'http://' + url, true); + this.httpRequest.setRequestHeader( + "X-Requested-With", + "XMLHttpRequest" + ); + this.httpRequest.setRequestHeader("X-Application", "Snap! 4.0"); this.httpRequest.send(null); } else if (this.httpRequest.readyState === 4) { response = this.httpRequest.responseText; @@ -2377,6 +2409,9 @@ Process.prototype.reportAttributeOf = function (attribute, name) { thatObj = this.getOtherObject(name, thisObj, stage); } if (thatObj) { + if (attribute instanceof Context) { + return this.reportContextFor(attribute, thatObj); + } if (isString(attribute)) { return thatObj.variables.getVar(attribute); } @@ -2401,6 +2436,18 @@ Process.prototype.reportAttributeOf = function (attribute, name) { return ''; }; +Process.prototype.reportContextFor = function (context, otherObj) { + // Private - return a copy of the context + // and bind it to another receiver + var result = copy(context); + result.receiver = otherObj; + if (result.outerContext) { + result.outerContext = copy(result.outerContext); + result.outerContext.receiver = otherObj; + } + return result; +}; + Process.prototype.reportMouseX = function () { var stage, world; if (this.homeContext.receiver) { |
