How to read the content from a (local) file with SpiderMonkey on the command line?
I want to use SpiderMonkey for driving a test harness (for the in-browser version see here). Now, I tried the foll开发者_如何学JAVAowing:
var defaultFileName = "all.n3";
var reader = new FileReader();
reader.readAsText(defaultFileName);
reader.onload = fileLoaded;
which fails with the following error:
regression-tests.js:9: ReferenceError: FileReader is not defined
Sorry if this is a dumb question but I did look around here and RTFMd for a bit but wasn't able to figure what to do (import? how?).
Check out help() in the SpiderMonkey shell -- it tells you about a whole bunch of functions that are available in the shell-only version (like snarf
, which is our (weirdly) named function to read a file into a string -- not sure the history of that name). It's a different API than is available in the browser, because the shell is supposed to be a minimal JS execution engine.
FileReader is an XUL component. XUL components aren't available the standalone version of SpiderMonkey - they're provided by the browser.
精彩评论