Mercurial > spidermonkey-playground
changeset 39:067371eb9601
The playground now only allocates buffers the size of the JS files being loaded, rather than 100k ones.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 23 Jun 2009 12:32:39 -0700 |
parents | cfdbaadf21b8 |
children | f86740dc5fa0 |
files | spidermonkey-playground.cpp |
diffstat | 1 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/spidermonkey-playground.cpp Mon Jun 22 23:05:40 2009 -0700 +++ b/spidermonkey-playground.cpp Tue Jun 23 12:32:39 2009 -0700 @@ -45,9 +45,6 @@ #include "wrapper.h" -// Maximum size of any script that we load, in bytes. -#define MAX_SCRIPT_SIZE 100000 - // The name of our JS script containing our Trusted Code Base (TCB). #define TCB_FILENAME "tcb.js" @@ -226,8 +223,12 @@ return JS_FALSE; } - char source[MAX_SCRIPT_SIZE]; - fread(source, MAX_SCRIPT_SIZE, 1, f); + fseek(f, 0, SEEK_END); + long fileSize = ftell(f); + fseek(f, 0, SEEK_SET); + + char source[fileSize]; + fread(source, fileSize, 1, f); fclose(f); // TODO: Check for return values here. @@ -543,9 +544,13 @@ FILE *f = fopen(TCB_FILENAME, "r"); if (!f) return 1; + + fseek(f, 0, SEEK_END); + long fileSize = ftell(f); + fseek(f, 0, SEEK_SET); - char source[MAX_SCRIPT_SIZE]; - fread(source, MAX_SCRIPT_SIZE, 1, f); + char source[fileSize]; + fread(source, fileSize, 1, f); fclose(f); jsval rval;