Skip to content

Commit aeb55b1

Browse files
committed
Merge branch 'use-date-now'
2 parents f9cb71f + 916e74f commit aeb55b1

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/compile.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,20 @@ Compiler.prototype._gr = function (hint, rest) {
269269
*/
270270
Compiler.prototype.outputInterruptTest = function () { // Added by RNL
271271
var output = "";
272-
if (Sk.execLimit !== null) {
273-
output += "if (new Date() - Sk.execStart > Sk.execLimit) {throw new Sk.builtin.TimeLimitError(Sk.timeoutMsg())}";
274-
}
275-
if (Sk.yieldLimit !== null && this.u.canSuspend) {
276-
output += "if (new Date() - Sk.lastYield > Sk.yieldLimit) {";
277-
output += "var $susp = $saveSuspension({data: {type: 'Sk.yield'}, resume: function() {}}, '"+this.filename+"',currLineNo,currColNo);";
278-
output += "$susp.$blk = $blk;";
279-
output += "$susp.optional = true;";
280-
output += "return $susp;";
281-
output += "}";
282-
this.u.doesSuspend = true;
272+
if (Sk.execLimit !== null || Sk.yieldLimit !== null && this.u.canSuspend) {
273+
output += "var $dateNow = Date.now();";
274+
if (Sk.execLimit !== null) {
275+
output += "if ($dateNow - Sk.execStart > Sk.execLimit) {throw new Sk.builtin.TimeLimitError(Sk.timeoutMsg())}";
276+
}
277+
if (Sk.yieldLimit !== null && this.u.canSuspend) {
278+
output += "if ($dateNow - Sk.lastYield > Sk.yieldLimit) {";
279+
output += "var $susp = $saveSuspension({data: {type: 'Sk.yield'}, resume: function() {}}, '"+this.filename+"',currLineNo,currColNo);";
280+
output += "$susp.$blk = $blk;";
281+
output += "$susp.optional = true;";
282+
output += "return $susp;";
283+
output += "}";
284+
this.u.doesSuspend = true;
285+
}
283286
}
284287
return output;
285288
};
@@ -918,7 +921,7 @@ Compiler.prototype.outputSuspensionHelpers = function (unit) {
918921
var output = "var $wakeFromSuspension = function() {" +
919922
"var susp = "+unit.scopename+".wakingSuspension; delete "+unit.scopename+".wakingSuspension;" +
920923
"$blk=susp.$blk; $loc=susp.$loc; $gbl=susp.$gbl; $exc=susp.$exc; $err=susp.$err;" +
921-
"currLineNo=susp.lineno; currColNo=susp.colno; Sk.lastYield=new Date();" +
924+
"currLineNo=susp.lineno; currColNo=susp.colno; Sk.lastYield=Date.now();" +
922925
(hasCell?"$cell=susp.$cell;":"");
923926

924927
for (i = 0; i < localsToSave.length; i++) {
@@ -1504,10 +1507,10 @@ Compiler.prototype.buildcodeobj = function (n, coname, decorator_list, args, cal
15041507
// all function invocations in call
15051508
this.u.varDeclsCode += "var $blk=" + entryBlock + ",$exc=[],$loc=" + locals + cells + ",$gbl=this,$err=undefined,$ret=undefined,currLineNo=undefined,currColNo=undefined;";
15061509
if (Sk.execLimit !== null) {
1507-
this.u.varDeclsCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = new Date()}";
1510+
this.u.varDeclsCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = Date.now()}";
15081511
}
15091512
if (Sk.yieldLimit !== null && this.u.canSuspend) {
1510-
this.u.varDeclsCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = new Date()}";
1513+
this.u.varDeclsCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = Date.now()}";
15111514
}
15121515

15131516
//
@@ -1821,10 +1824,10 @@ Compiler.prototype.cclass = function (s) {
18211824
this.u.switchCode += "return(function $" + s.name.v + "$_closure(){";
18221825
this.u.switchCode += "var $blk=" + entryBlock + ",$exc=[],$ret=undefined,currLineNo=undefined,currColNo=undefined;"
18231826
if (Sk.execLimit !== null) {
1824-
this.u.switchCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = new Date()}";
1827+
this.u.switchCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = Date.now()}";
18251828
}
18261829
if (Sk.yieldLimit !== null && this.u.canSuspend) {
1827-
this.u.switchCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = new Date()}";
1830+
this.u.switchCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = Date.now()}";
18281831
}
18291832
this.u.switchCode += "while(true){";
18301833
this.u.switchCode += this.outputInterruptTest();
@@ -2221,10 +2224,10 @@ Compiler.prototype.cmod = function (mod) {
22212224
this.u.prefixCode = "var " + modf + "=(function($modname){";
22222225
this.u.varDeclsCode = "var $gbl = {}, $blk=" + entryBlock + ",$exc=[],$loc=$gbl,$err=undefined;$gbl.__name__=$modname,$ret=undefined,currLineNo=undefined,currColNo=undefined;";
22232226
if (Sk.execLimit !== null) {
2224-
this.u.varDeclsCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = new Date()}";
2227+
this.u.varDeclsCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = Date.now()}";
22252228
}
22262229
if (Sk.yieldLimit !== null && this.u.canSuspend) {
2227-
this.u.varDeclsCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = new Date()}";
2230+
this.u.varDeclsCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = Date.now()}";
22282231
}
22292232

22302233
this.u.varDeclsCode += "try {";

0 commit comments

Comments
 (0)