开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜