@@ -267,17 +267,20 @@ Compiler.prototype._gr = function (hint, rest) {
267
267
*/
268
268
Compiler . prototype . outputInterruptTest = function ( ) { // Added by RNL
269
269
var output = "" ;
270
- if ( Sk . execLimit !== null ) {
271
- output += "if (new Date() - Sk.execStart > Sk.execLimit) {throw new Sk.builtin.TimeLimitError(Sk.timeoutMsg())}" ;
272
- }
273
- if ( Sk . yieldLimit !== null && this . u . canSuspend ) {
274
- output += "if (new Date() - Sk.lastYield > Sk.yieldLimit) {" ;
275
- output += "var $susp = $saveSuspension({data: {type: 'Sk.yield'}, resume: function() {}}, '" + this . filename + "',currLineNo,currColNo);" ;
276
- output += "$susp.$blk = $blk;" ;
277
- output += "$susp.optional = true;" ;
278
- output += "return $susp;" ;
279
- output += "}" ;
280
- this . u . doesSuspend = true ;
270
+ if ( Sk . execLimit !== null || Sk . yieldLimit !== null && this . u . canSuspend ) {
271
+ output += "var $dateNow = Date.now();" ;
272
+ if ( Sk . execLimit !== null ) {
273
+ output += "if ($dateNow - Sk.execStart > Sk.execLimit) {throw new Sk.builtin.TimeLimitError(Sk.timeoutMsg())}" ;
274
+ }
275
+ if ( Sk . yieldLimit !== null && this . u . canSuspend ) {
276
+ output += "if ($dateNow - 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 ;
283
+ }
281
284
}
282
285
return output ;
283
286
} ;
@@ -916,7 +919,7 @@ Compiler.prototype.outputSuspensionHelpers = function (unit) {
916
919
var output = "var $wakeFromSuspension = function() {" +
917
920
"var susp = " + unit . scopename + ".wakingSuspension; delete " + unit . scopename + ".wakingSuspension;" +
918
921
"$blk=susp.$blk; $loc=susp.$loc; $gbl=susp.$gbl; $exc=susp.$exc; $err=susp.$err;" +
919
- "currLineNo=susp.lineno; currColNo=susp.colno; Sk.lastYield=new Date();" +
922
+ "currLineNo=susp.lineno; currColNo=susp.colno; Sk.lastYield=Date.now ();" +
920
923
( hasCell ?"$cell=susp.$cell;" :"" ) ;
921
924
922
925
for ( i = 0 ; i < localsToSave . length ; i ++ ) {
@@ -1502,10 +1505,10 @@ Compiler.prototype.buildcodeobj = function (n, coname, decorator_list, args, cal
1502
1505
// all function invocations in call
1503
1506
this . u . varDeclsCode += "var $blk=" + entryBlock + ",$exc=[],$loc=" + locals + cells + ",$gbl=this,$err=undefined,$ret=undefined,currLineNo=undefined,currColNo=undefined;" ;
1504
1507
if ( Sk . execLimit !== null ) {
1505
- this . u . varDeclsCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = new Date()}" ;
1508
+ this . u . varDeclsCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = Date.now ()}" ;
1506
1509
}
1507
1510
if ( Sk . yieldLimit !== null && this . u . canSuspend ) {
1508
- this . u . varDeclsCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = new Date()}" ;
1511
+ this . u . varDeclsCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = Date.now ()}" ;
1509
1512
}
1510
1513
1511
1514
//
@@ -1819,10 +1822,10 @@ Compiler.prototype.cclass = function (s) {
1819
1822
this . u . switchCode += "return(function $" + s . name . v + "$_closure(){" ;
1820
1823
this . u . switchCode += "var $blk=" + entryBlock + ",$exc=[],$ret=undefined,currLineNo=undefined,currColNo=undefined;"
1821
1824
if ( Sk . execLimit !== null ) {
1822
- this . u . switchCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = new Date()}" ;
1825
+ this . u . switchCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = Date.now ()}" ;
1823
1826
}
1824
1827
if ( Sk . yieldLimit !== null && this . u . canSuspend ) {
1825
- this . u . switchCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = new Date()}" ;
1828
+ this . u . switchCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = Date.now ()}" ;
1826
1829
}
1827
1830
this . u . switchCode += "while(true){" ;
1828
1831
this . u . switchCode += this . outputInterruptTest ( ) ;
@@ -2219,10 +2222,10 @@ Compiler.prototype.cmod = function (mod) {
2219
2222
this . u . prefixCode = "var " + modf + "=(function($modname){" ;
2220
2223
this . u . varDeclsCode = "var $gbl = {}, $blk=" + entryBlock + ",$exc=[],$loc=$gbl,$err=undefined;$gbl.__name__=$modname,$ret=undefined,currLineNo=undefined,currColNo=undefined;" ;
2221
2224
if ( Sk . execLimit !== null ) {
2222
- this . u . varDeclsCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = new Date()}" ;
2225
+ this . u . varDeclsCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = Date.now ()}" ;
2223
2226
}
2224
2227
if ( Sk . yieldLimit !== null && this . u . canSuspend ) {
2225
- this . u . varDeclsCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = new Date()}" ;
2228
+ this . u . varDeclsCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = Date.now ()}" ;
2226
2229
}
2227
2230
2228
2231
this . u . varDeclsCode += "try {" ;
0 commit comments