JSAtom* FrameIterator::functionDisplayAtom() const { MOZ_ASSERT(!done()); JSContext* cx = activation_->cx(); if (missingFrameMessage_) { const char* msg = "asm.js/wasm frames may be missing; enable the profiler before running " "to see all frames"; JSAtom* atom = Atomize(cx, msg, strlen(msg)); if (!atom) { cx->clearPendingException(); return cx->names().empty; } return atom; } MOZ_ASSERT(codeRange_); JSAtom* atom = code_->getFuncDefAtom(cx, codeRange_->funcDefIndex()); if (!atom) { cx->clearPendingException(); return cx->names().empty; } return atom; }
bool report(Census &census, MutableHandleValue report) { JSContext *cx = census.cx; RootedObject obj(cx, NewBuiltinClassInstance(cx, &JSObject::class_)); if (!obj) return false; RootedValue objectsReport(cx); if (!objects.report(census, &objectsReport) || !JSObject::defineProperty(cx, obj, cx->names().objects, objectsReport)) return false; RootedValue scriptsReport(cx); if (!scripts.report(census, &scriptsReport) || !JSObject::defineProperty(cx, obj, cx->names().scripts, scriptsReport)) return false; RootedValue stringsReport(cx); if (!strings.report(census, &stringsReport) || !JSObject::defineProperty(cx, obj, cx->names().strings, stringsReport)) return false; RootedValue otherReport(cx); if (!other.report(census, &otherReport) || !JSObject::defineProperty(cx, obj, cx->names().other, otherReport)) return false; report.setObject(*obj); return true; }
UnrootedFlatString StringBuffer::finishString() { JSContext *cx = context(); if (cb.empty()) return UnrootedFlatString(cx->names().empty); size_t length = cb.length(); if (!JSString::validateLength(cx, length)) return UnrootedFlatString(); JS_STATIC_ASSERT(JSShortString::MAX_SHORT_LENGTH < CharBuffer::InlineLength); if (JSShortString::lengthFits(length)) return NewShortString<CanGC>(cx, TwoByteChars(cb.begin(), length)); if (!cb.append('\0')) return UnrootedFlatString(); jschar *buf = extractWellSized(); if (!buf) return UnrootedFlatString(); JSFlatString *str = js_NewString<CanGC>(cx, buf, length); if (!str) js_free(buf); return str; }
/* * Since memory has been exhausted, avoid the normal error-handling path which * allocates an error object, report and callstack. If code is running, simply * throw the static atom "out of memory". If code is not running, call the * error reporter directly. * * Furthermore, callers of ReportOutOfMemory (viz., malloc) assume a GC does * not occur, so GC must be avoided or suppressed. */ void js::ReportOutOfMemory(ExclusiveContext* cxArg) { #ifdef JS_MORE_DETERMINISTIC /* * OOMs are non-deterministic, especially across different execution modes * (e.g. interpreter vs JIT). In more-deterministic builds, print to stderr * so that the fuzzers can detect this. */ fprintf(stderr, "ReportOutOfMemory called\n"); #endif if (!cxArg->isJSContext()) return cxArg->addPendingOutOfMemory(); JSContext* cx = cxArg->asJSContext(); cx->runtime()->hadOutOfMemory = true; AutoSuppressGC suppressGC(cx); /* Report the oom. */ if (JS::OutOfMemoryCallback oomCallback = cx->runtime()->oomCallback) oomCallback(cx, cx->runtime()->oomCallbackData); cx->setPendingException(StringValue(cx->names().outOfMemory)); }
/* * Since memory has been exhausted, avoid the normal error-handling path which * allocates an error object, report and callstack. If code is running, simply * throw the static atom "out of memory". If code is not running, call the * error reporter directly. * * Furthermore, callers of js_ReportOutOfMemory (viz., malloc) assume a GC does * not occur, so GC must be avoided or suppressed. */ void js_ReportOutOfMemory(ThreadSafeContext *cxArg) { if (!cxArg->isJSContext()) return; JSContext *cx = cxArg->asJSContext(); cx->runtime()->hadOutOfMemory = true; if (JS_IsRunning(cx)) { cx->setPendingException(StringValue(cx->names().outOfMemory)); return; } /* Get the message for this error, but we don't expand any arguments. */ const JSErrorFormatString *efs = js_GetLocalizedErrorMessage(cx, NULL, NULL, JSMSG_OUT_OF_MEMORY); const char *msg = efs ? efs->format : "Out of memory"; /* Fill out the report, but don't do anything that requires allocation. */ JSErrorReport report; PodZero(&report); report.flags = JSREPORT_ERROR; report.errorNumber = JSMSG_OUT_OF_MEMORY; PopulateReportBlame(cx, &report); /* Report the error. */ if (JSErrorReporter onError = cx->errorReporter) { AutoSuppressGC suppressGC(cx); onError(cx, msg, &report); } }
/* * Since memory has been exhausted, avoid the normal error-handling path which * allocates an error object, report and callstack. If code is running, simply * throw the static atom "out of memory". If code is not running, call the * error reporter directly. * * Furthermore, callers of js_ReportOutOfMemory (viz., malloc) assume a GC does * not occur, so GC must be avoided or suppressed. */ void js_ReportOutOfMemory(ThreadSafeContext *cxArg) { #ifdef JS_MORE_DETERMINISTIC /* * OOMs are non-deterministic, especially across different execution modes * (e.g. interpreter vs JIT). In more-deterministic builds, print to stderr * so that the fuzzers can detect this. */ fprintf(stderr, "js_ReportOutOfMemory called\n"); #endif if (cxArg->isForkJoinSlice()) { cxArg->asForkJoinSlice()->setPendingAbortFatal(ParallelBailoutOutOfMemory); return; } if (!cxArg->isJSContext()) return; JSContext *cx = cxArg->asJSContext(); cx->runtime()->hadOutOfMemory = true; if (JS_IsRunning(cx)) { cx->setPendingException(StringValue(cx->names().outOfMemory)); return; } /* Get the message for this error, but we don't expand any arguments. */ const JSErrorFormatString *efs = js_GetLocalizedErrorMessage(cx, nullptr, nullptr, JSMSG_OUT_OF_MEMORY); const char *msg = efs ? efs->format : "Out of memory"; /* Fill out the report, but don't do anything that requires allocation. */ JSErrorReport report; PodZero(&report); report.flags = JSREPORT_ERROR; report.errorNumber = JSMSG_OUT_OF_MEMORY; PopulateReportBlame(cx, &report); /* Report the error. */ if (JSErrorReporter onError = cx->errorReporter) { AutoSuppressGC suppressGC(cx); onError(cx, msg, &report); } /* * We would like to enforce the invariant that any exception reported * during an OOM situation does not require wrapping. Besides avoiding * allocation when memory is low, this reduces the number of places where * we might need to GC. * * When JS code is running, we set the pending exception to an atom, which * does not need wrapping. If no JS code is running, no exception should be * set at all. */ JS_ASSERT(!cx->isExceptionPending()); }
JSAtom * StringBuffer::finishAtom() { JSContext *cx = context(); size_t length = cb.length(); if (length == 0) return cx->names().empty; JSAtom *atom = AtomizeChars(cx, cb.begin(), length); cb.clear(); return atom; }
UnrootedAtom StringBuffer::finishAtom() { AssertCanGC(); JSContext *cx = context(); size_t length = cb.length(); if (length == 0) return UnrootedAtom(cx->names().empty); UnrootedAtom atom = AtomizeChars<CanGC>(cx, cb.begin(), length); cb.clear(); return atom; }
static bool MaybeCheckEvalFreeVariables(ExclusiveContext *cxArg, HandleScript evalCaller, HandleObject scopeChain, Parser<FullParseHandler> &parser, ParseContext<FullParseHandler> &pc) { if (!evalCaller || !evalCaller->functionOrCallerFunction()) return true; // Eval scripts are only compiled on the main thread. JSContext *cx = cxArg->asJSContext(); // Watch for uses of 'arguments' within the evaluated script, both as // free variables and as variables redeclared with 'var'. RootedFunction fun(cx, evalCaller->functionOrCallerFunction()); HandlePropertyName arguments = cx->names().arguments; for (AtomDefnRange r = pc.lexdeps->all(); !r.empty(); r.popFront()) { if (r.front().key() == arguments) { if (!CheckArgumentsWithinEval(cx, parser, fun)) return false; } } for (AtomDefnListMap::Range r = pc.decls().all(); !r.empty(); r.popFront()) { if (r.front().key() == arguments) { if (!CheckArgumentsWithinEval(cx, parser, fun)) return false; } } // If the eval'ed script contains any debugger statement, force construction // of arguments objects for the caller script and any other scripts it is // transitively nested inside. The debugger can access any variable on the // scope chain. if (pc.sc->hasDebuggerStatement()) { RootedObject scope(cx, scopeChain); while (scope->is<ScopeObject>() || scope->is<DebugScopeObject>()) { if (scope->is<CallObject>() && !scope->as<CallObject>().isForEval()) { RootedScript script(cx, scope->as<CallObject>().callee().getOrCreateScript(cx)); if (!script) return false; if (script->argumentsHasVarBinding()) { if (!JSScript::argumentsOptimizationFailed(cx, script)) return false; } } scope = scope->enclosingScope(); } } return true; }
/* * Since memory has been exhausted, avoid the normal error-handling path which * allocates an error object, report and callstack. If code is running, simply * throw the static atom "out of memory". If code is not running, call the * error reporter directly. * * Furthermore, callers of js_ReportOutOfMemory (viz., malloc) assume a GC does * not occur, so GC must be avoided or suppressed. */ void js_ReportOutOfMemory(ThreadSafeContext *cxArg) { if (!cxArg->isJSContext()) return; JSContext *cx = cxArg->asJSContext(); cx->runtime()->hadOutOfMemory = true; if (JS_IsRunning(cx)) { cx->setPendingException(StringValue(cx->names().outOfMemory)); return; } /* Get the message for this error, but we don't expand any arguments. */ const JSErrorFormatString *efs = js_GetLocalizedErrorMessage(cx, NULL, NULL, JSMSG_OUT_OF_MEMORY); const char *msg = efs ? efs->format : "Out of memory"; /* Fill out the report, but don't do anything that requires allocation. */ JSErrorReport report; PodZero(&report); report.flags = JSREPORT_ERROR; report.errorNumber = JSMSG_OUT_OF_MEMORY; PopulateReportBlame(cx, &report); /* Report the error. */ if (JSErrorReporter onError = cx->errorReporter) { AutoSuppressGC suppressGC(cx); onError(cx, msg, &report); } /* * We would like to enforce the invariant that any exception reported * during an OOM situation does not require wrapping. Besides avoiding * allocation when memory is low, this reduces the number of places where * we might need to GC. * * When JS code is running, we set the pending exception to an atom, which * does not need wrapping. If no JS code is running, no exception should be * set at all. */ JS_ASSERT(!cx->isExceptionPending()); }