Jelajahi Sumber

add RecursionError

blueloveTH 3 tahun lalu
induk
melakukan
054a2a6873
2 mengubah file dengan 8 tambahan dan 2 penghapusan
  1. 8 1
      src/vm.h
  2. 0 1
      web/index.js

+ 8 - 1
src/vm.h

@@ -431,6 +431,11 @@ public:
 
 
     PyVar _exec(const _Code& code, PyVar _module, PyVarDict& locals){
     PyVar _exec(const _Code& code, PyVar _module, PyVarDict& locals){
         if(code == nullptr) UNREACHABLE();
         if(code == nullptr) UNREACHABLE();
+
+        if(callstack.size() > 1000){
+            throw RuntimeError("RecursionError", "maximum recursion depth exceeded", _cleanErrorAndGetSnapshots());
+        }
+
         Frame* frame = new Frame(
         Frame* frame = new Frame(
             code.get(),
             code.get(),
             _module,
             _module,
@@ -663,7 +668,9 @@ private:
     std::stack<_Str> _cleanErrorAndGetSnapshots(){
     std::stack<_Str> _cleanErrorAndGetSnapshots(){
         std::stack<_Str> snapshots;
         std::stack<_Str> snapshots;
         while (!callstack.empty()){
         while (!callstack.empty()){
-            snapshots.push(callstack.top()->errorSnapshot());
+            if(snapshots.size() < 10){
+                snapshots.push(callstack.top()->errorSnapshot());
+            }
             callstack.pop();
             callstack.pop();
         }
         }
         return snapshots;
         return snapshots;

+ 0 - 1
web/index.js

@@ -17,7 +17,6 @@ var Module = {
     },
     },
     'onAbort': function(text) { 
     'onAbort': function(text) { 
       stopped = true;
       stopped = true;
-      term.write("Aborted\r\n");
     },
     },
   };
   };