code: private BThreadSyncSnapshot handleContinuationPending(ContinuationPending cbs, Context jsContext) throws IllegalStateException {
          final Object capturedStatement = cbs.getApplicationState();
          
          if ( capturedStatement instanceof SyncStatement ) {
              final SyncStatement syncStatement = (SyncStatement) cbs.getApplicationState();
              return bss.copyWith(cbs.getContinuation(), syncStatement);
              
          } else if ( capturedStatement instanceof ForkStatement ) {
              ForkStatement forkStmt = (ForkStatement) capturedStatement;
              forkStmt.setForkingBThread(bss);
              
              final ScriptableObject globalScope = jsContext.initStandardObjects();
              try ( ByteArrayOutputStream baos = new ByteArrayOutputStream();
                  BThreadSyncSnapshotOutputStream btos = new BThreadSyncSnapshotOutputStream(baos, globalScope) ) {
                  btos.writeObject(cbs.getContinuation());
                  btos.flush();
                  baos.flush();
                  forkStmt.setSerializedContinuation(baos.toByteArray());
                  
              } catch (IOException ex) {
                  Logger.getLogger(BPEngineTask.class.getName()).log(Level.SEVERE, "Error while serializing continuation during fork:" + ex.getMessage(), ex);
                  throw new RuntimeException("Error while serializing continuation during fork:" + ex.getMessage(), ex);
              }
              
              listener.addFork(forkStmt);
              return continueParentOfFork(cbs, jsContext);
              
          } else {
              throw new IllegalStateException("Captured a statement of an unknown type: " + capturedStatement);
          }
      }
docs: Handle a captures continuation. This can be because of a sync statement,
  or because of a fork.
  @param cbs
  @param jsContext
  @return Snapshot for the continued execution of the parent.
  @throws IllegalStateException