Bug 784620 - Support reading self-hosted JS from a file set via environment variable. r=terrence

This commit is contained in:
Till Schneidereit 2012-10-11 11:19:43 +02:00
parent 491b02a2e0
commit 8af01ce667
3 changed files with 17 additions and 9 deletions

View File

@ -882,7 +882,8 @@ pm_linux.$(OBJ_SUFFIX): CXXFLAGS += $(LINUX_HEADERS_INCLUDES)
endif
# Prepare self-hosted JS code for embedding
export:: selfhosted.out.h
export:: selfhosting
selfhosting:: selfhosted.out.h
selfhosting_srcs := \
$(srcdir)/builtin/array.js \

View File

@ -43,10 +43,9 @@ def main():
messages_file = sys.argv[2]
macros_file = sys.argv[3]
source_files = sys.argv[4:]
combined_file = 'combined.js'
combined_file = 'selfhosted.js'
replaceErrorMsgs(source_files, messages_file, combined_file)
js2c.JS2C([combined_file, macros_file], [output_file], { 'TYPE': 'CORE', 'COMPRESSION': 'off', 'DEBUG':debug })
os.remove(combined_file)
if __name__ == "__main__":
main()

View File

@ -257,23 +257,31 @@ JSRuntime::initSelfHosting(JSContext *cx)
if (!(selfHostedGlobal_ = JS_NewGlobalObject(cx, &self_hosting_global_class, NULL)))
return false;
JS_SetGlobalObject(cx, selfHostedGlobal_);
const char *src = selfhosted::raw_sources;
uint32_t srcLen = selfhosted::GetRawScriptsSize();
RootedObject shg(cx, selfHostedGlobal_);
CompileOptions options(cx);
options.setFileAndLine("self-hosted", 1);
options.setSelfHostingMode(true);
RootedObject shg(cx, selfHostedGlobal_);
Value rv;
/*
* Set a temporary error reporter printing to stderr because it is too
* early in the startup process for any other reporter to be registered
* and we don't want errors in self-hosted code to be silently swallowed.
*/
JSErrorReporter oldReporter = JS_SetErrorReporter(cx, selfHosting_ErrorReporter);
bool ok = Evaluate(cx, shg, options, src, srcLen, &rv);
Value rv;
bool ok;
char *filename = getenv("MOZ_SELFHOSTEDJS");
if (filename) {
RootedScript script(cx, Compile(cx, shg, options, filename));
if (script)
ok = Execute(cx, script, *shg.get(), &rv);
} else {
const char *src = selfhosted::raw_sources;
uint32_t srcLen = selfhosted::GetRawScriptsSize();
ok = Evaluate(cx, shg, options, src, srcLen, &rv);
}
JS_SetErrorReporter(cx, oldReporter);
JS_SetGlobalObject(cx, savedGlobal);
return ok;