App-SocialCalc-Multiplayer
view release on metacpan or search on metacpan
socialcalc/socialcalc-3.js view on Meta::CPAN
alert("Recalc state error: "+scri.currentState+". Error in SocialCalc code.");
}
coord = sheet.recalcdata.nextcalc;
while (coord) {
cell = sheet.cells[coord];
eresult = scf.evaluate_parsed_formula(cell.parseinfo, sheet, false);
if (scf.SheetCache.waitingForLoading) { // wait until restarted
recalcdata.nextcalc = coord; // start with this cell again
recalcdata.count += count;
do_statuscallback("calcloading", {sheetname: scf.SheetCache.waitingForLoading});
scri.currentState = scri.state.start_wait; // start load on next timer call
SocialCalc.RecalcSetTimeout();
return;
}
if (scf.RemoteFunctionInfo.waitingForServer) { // wait until restarted
recalcdata.nextcalc = coord; // start with this cell again
recalcdata.count += count;
do_statuscallback("calcserverfunc",
{funcname: scf.RemoteFunctionInfo.waitingForServer, coord: coord, total: recalcdata.calclistlength, count: recalcdata.count});
scri.currentState = scri.state.done_wait; // start load on next timer call
return; // return and wait for next recalc timer event
}
if (cell.datavalue != eresult.value ||
cell.valuetype != eresult.type) { // only update if changed from last time
cell.datavalue = eresult.value;
cell.valuetype = eresult.type;
delete cell.displaystring;
sheet.recalcchangedavalue = true; // remember something changed in case other code wants to know
}
if (eresult.error) {
cell.errors = eresult.error;
}
count++;
coord = sheet.recalcdata.calclist[coord];
if (((new Date()) - starttime) >= scri.maxtimeslice) { // if taking too long, give up CPU for a while
recalcdata.nextcalc = coord; // start with next cell on chain
recalcdata.count += count;
do_statuscallback("calcstep", {coord: coord, total: recalcdata.calclistlength, count: recalcdata.count});
SocialCalc.RecalcSetTimeout();
return;
}
}
recalcdata.inrecalc = false;
delete sheet.recalcdata; // save memory and clear out for name lookup formula evaluation
delete sheet.attribs.needsrecalc; // remember recalc done
scri.sheet = sheet.previousrecalcsheet || null; // chain back if doing recalc of loaded sheets
if (scri.sheet) {
scri.currentState = scri.state.calc; // start where we left off
SocialCalc.RecalcSetTimeout();
return;
}
scf.FreshnessInfo.recalc_completed = true; // say freshness info is complete
do_statuscallback("calcfinished", (new Date()) - scri.starttime);
}
//
// circref = SocialCalc.RecalcCheckCell(sheet, coord)
//
// Checks cell to put on calclist, looking at parsed tokens.
// Also checks cells this cell is dependent upon
// if it contains a formula with cell references.
// If circular reference, returns non-null.
//
SocialCalc.RecalcCheckCell = function(sheet, startcoord) {
var parseinfo, ttext, ttype, i, rangecoord, circref, value, pos, pos2, cell, coordvals;
var scf = SocialCalc.Formula;
if (!scf) {
return "Need SocialCalc.Formula";
}
var tokentype = scf.TokenType;
var token_op = tokentype.op;
var token_name = tokentype.name;
var token_coord = tokentype.coord;
var recalcdata = sheet.recalcdata;
var checkinfo = recalcdata.checkinfo;
var sheetref = false; // if true, a sheet reference is in effect, so don't check that
var oldcoord = null; // coord of formula that referred to this one when checking down the tree
var coord = startcoord; // the coord of the cell we are checking
// Start with requested cell, and then continue down or up the dependency tree
// oldcoord (and checkinfo[coord].oldcoord) maintains the reference stack during the tree walk
// checkinfo[coord] maintains the stack of checking looping values, e.g., token number being checked
mainloop:
while (coord) {
cell = sheet.cells[coord];
coordvals = checkinfo[coord];
if (!cell || cell.datatype != "f" || // Don't calculate if not a formula
(coordvals && typeof coordvals != "object")) { // Don't calc if already calculated
coord = oldcoord; // go back up dependency tree to coord that referred to us
if (checkinfo[coord]) oldcoord = checkinfo[coord].oldcoord;
continue;
}
if (!coordvals) { // do we have checking information about this cell?
coordvals = new SocialCalc.RecalcCheckInfo(); // no - make a place to hold it
checkinfo[coord] = coordvals;
}
if (cell.errors) { // delete errors from previous recalcs
delete cell.errors;
}
if (!cell.parseinfo) { // cache parsed formula
( run in 1.361 second using v1.01-cache-2.11-cpan-800906f7e73 )