| --- BytecodeCompiler.cpp |
| +++ BytecodeCompiler.cpp |
| @@ -22,16 +22,36 @@ |
| |
| #include "frontend/Parser-inl.h" |
| #include "vm/ScopeObject-inl.h" |
| |
| using namespace js; |
| using namespace js::frontend; |
| using mozilla::Maybe; |
| |
| +class MOZ_STACK_CLASS AutoCompilationTraceLogger |
| +{ |
| + public: |
| + AutoCompilationTraceLogger(ExclusiveContext* cx, const TraceLoggerTextId id); |
| + |
| + private: |
| + TraceLoggerThread* logger; |
| + TraceLoggerEvent event; |
| + AutoTraceLog scriptLogger; |
| + AutoTraceLog typeLogger; |
| +}; |
| + |
| +AutoCompilationTraceLogger::AutoCompilationTraceLogger(ExclusiveContext* cx, const TraceLoggerTextId id) |
| + : logger(cx->isJSContext() ? TraceLoggerForMainThread(cx->asJSContext()->runtime()) |
| + : TraceLoggerForCurrentThread()), |
| + event(logger, TraceLogger_AnnotateScripts), |
| + scriptLogger(logger, event), |
| + typeLogger(logger, id) |
| +{} |
| + |
| static bool |
| CheckLength(ExclusiveContext* cx, SourceBufferHolder& srcBuf) |
| { |
| // Note this limit is simply so we can store sourceStart and sourceEnd in |
| // JSScript as 32-bits. It could be lifted fairly easily, since the compiler |
| // is using size_t internally already. |
| if (srcBuf.length() > UINT32_MAX) { |
| if (cx->isJSContext()) |
| @@ -218,24 +238,17 @@ frontend::CompileScript(ExclusiveContext |
| JSString* source_ /* = nullptr */, |
| unsigned staticLevel /* = 0 */, |
| SourceCompressionTask* extraSct /* = nullptr */) |
| { |
| MOZ_ASSERT(srcBuf.get()); |
| |
| RootedString source(cx, source_); |
| |
| - js::TraceLoggerThread* logger = nullptr; |
| - if (cx->isJSContext()) |
| - logger = TraceLoggerForMainThread(cx->asJSContext()->runtime()); |
| - else |
| - logger = TraceLoggerForCurrentThread(); |
| - js::TraceLoggerEvent event(logger, TraceLogger_AnnotateScripts, options); |
| - js::AutoTraceLog scriptLogger(logger, event); |
| - js::AutoTraceLog typeLogger(logger, TraceLogger_ParserCompileScript); |
| + AutoCompilationTraceLogger traceLogger(cx, TraceLogger_ParserCompileScript); |
| |
| /* |
| * The scripted callerFrame can only be given for compile-and-go scripts |
| * and non-zero static level requires callerFrame. |
| */ |
| MOZ_ASSERT_IF(evalCaller, options.isRunOnce); |
| MOZ_ASSERT_IF(evalCaller, options.forEval); |
| MOZ_ASSERT_IF(evalCaller && evalCaller->strict(), options.strictOption); |
| @@ -467,20 +480,17 @@ frontend::CompileLazyFunction(JSContext* |
| |
| CompileOptions options(cx, lazy->version()); |
| options.setMutedErrors(lazy->mutedErrors()) |
| .setFileAndLine(lazy->filename(), lazy->lineno()) |
| .setColumn(lazy->column()) |
| .setNoScriptRval(false) |
| .setSelfHostingMode(false); |
| |
| - js::TraceLoggerThread* logger = js::TraceLoggerForMainThread(cx->runtime()); |
| - js::TraceLoggerEvent event(logger, TraceLogger_AnnotateScripts, options); |
| - js::AutoTraceLog scriptLogger(logger, event); |
| - js::AutoTraceLog typeLogger(logger, TraceLogger_ParserCompileLazy); |
| + AutoCompilationTraceLogger traceLogger(cx, TraceLogger_ParserCompileLazy); |
| |
| Parser<FullParseHandler> parser(cx, &cx->tempLifoAlloc(), options, chars, length, |
| /* foldConstants = */ true, nullptr, lazy); |
| if (!parser.checkOptions()) |
| return false; |
| |
| uint32_t staticLevel = lazy->staticLevel(cx); |
| |
| @@ -534,20 +544,17 @@ frontend::CompileLazyFunction(JSContext* |
| // handler attribute in an HTML <INPUT> tag, or in a Function() constructor. |
| static bool |
| CompileFunctionBody(JSContext* cx, MutableHandleFunction fun, const ReadOnlyCompileOptions& options, |
| const AutoNameVector& formals, SourceBufferHolder& srcBuf, |
| HandleObject enclosingStaticScope, GeneratorKind generatorKind) |
| { |
| MOZ_ASSERT(!options.isRunOnce); |
| |
| - js::TraceLoggerThread* logger = js::TraceLoggerForMainThread(cx->runtime()); |
| - js::TraceLoggerEvent event(logger, TraceLogger_AnnotateScripts, options); |
| - js::AutoTraceLog scriptLogger(logger, event); |
| - js::AutoTraceLog typeLogger(logger, TraceLogger_ParserCompileFunction); |
| + AutoCompilationTraceLogger traceLogger(cx, TraceLogger_ParserCompileFunction); |
| |
| // FIXME: make Function pass in two strings and parse them as arguments and |
| // ProgramElements respectively. |
| |
| if (!CheckLength(cx, srcBuf)) |
| return false; |
| |
| RootedScriptSource sourceObject(cx, CreateScriptSourceObject(cx, options)); |