@@ -269,17 +269,20 @@ Compiler.prototype._gr = function (hint, rest) {
269
269
*/
270
270
Compiler . prototype . outputInterruptTest = function ( ) { // Added by RNL
271
271
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
+ }
283
286
}
284
287
return output ;
285
288
} ;
@@ -918,7 +921,7 @@ Compiler.prototype.outputSuspensionHelpers = function (unit) {
918
921
var output = "var $wakeFromSuspension = function() {" +
919
922
"var susp = " + unit . scopename + ".wakingSuspension; delete " + unit . scopename + ".wakingSuspension;" +
920
923
"$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 ();" +
922
925
( hasCell ?"$cell=susp.$cell;" :"" ) ;
923
926
924
927
for ( i = 0 ; i < localsToSave . length ; i ++ ) {
@@ -1504,10 +1507,10 @@ Compiler.prototype.buildcodeobj = function (n, coname, decorator_list, args, cal
1504
1507
// all function invocations in call
1505
1508
this . u . varDeclsCode += "var $blk=" + entryBlock + ",$exc=[],$loc=" + locals + cells + ",$gbl=this,$err=undefined,$ret=undefined,currLineNo=undefined,currColNo=undefined;" ;
1506
1509
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 ()}" ;
1508
1511
}
1509
1512
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 ()}" ;
1511
1514
}
1512
1515
1513
1516
//
@@ -1821,10 +1824,10 @@ Compiler.prototype.cclass = function (s) {
1821
1824
this . u . switchCode += "return(function $" + s . name . v + "$_closure(){" ;
1822
1825
this . u . switchCode += "var $blk=" + entryBlock + ",$exc=[],$ret=undefined,currLineNo=undefined,currColNo=undefined;"
1823
1826
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 ()}" ;
1825
1828
}
1826
1829
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 ()}" ;
1828
1831
}
1829
1832
this . u . switchCode += "while(true){" ;
1830
1833
this . u . switchCode += this . outputInterruptTest ( ) ;
@@ -2221,10 +2224,10 @@ Compiler.prototype.cmod = function (mod) {
2221
2224
this . u . prefixCode = "var " + modf + "=(function($modname){" ;
2222
2225
this . u . varDeclsCode = "var $gbl = {}, $blk=" + entryBlock + ",$exc=[],$loc=$gbl,$err=undefined;$gbl.__name__=$modname,$ret=undefined,currLineNo=undefined,currColNo=undefined;" ;
2223
2226
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 ()}" ;
2225
2228
}
2226
2229
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 ()}" ;
2228
2231
}
2229
2232
2230
2233
this . u . varDeclsCode += "try {" ;
0 commit comments