Error guides

Fix "toSource is not a function" on V8

TypeError: data.toSource is not a function
ReferenceError: uneval is not defined

Why it happens

toSource() and uneval() were Mozilla extensions that printed an object as source code, e.g. ({a:1}). Rhino-era scripts used them to log objects or save them to properties. V8 never had them.

The fix

// Rhino
Logger.log(data.toSource());
PropertiesService.getScriptProperties().setProperty('cache', uneval(rows));

// V8
Logger.log(JSON.stringify(data));
PropertiesService.getScriptProperties().setProperty('cache', JSON.stringify(rows));

Gotchas

How V8Shift handles it

x.toSource() → JSON.stringify(x) and uneval( → JSON.stringify( automatically, each marked V8Shift: review.

Have a whole project to migrate? Paste your .gs or upload a zip for a free V8 compatibility report — every occurrence of this pattern with file and line, plus an auto-rewritten project.
Related errors