本文整理汇总了C++中JSContext::names方法的典型用法代码示例。如果您正苦于以下问题:C++ JSContext::names方法的具体用法?C++ JSContext::names怎么用?C++ JSContext::names使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSContext
的用法示例。
在下文中一共展示了JSContext::names方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Atomize
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;
}
示例2: report
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;
}
示例3: UnrootedFlatString
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;
}
示例4: suppressGC
/*
* 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));
}
示例5: suppressGC
/*
* 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);
}
}
示例6: suppressGC
/*
* 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());
}
示例7: context
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;
}
示例8: UnrootedAtom
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;
}
示例9: fun
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;
}
示例10: suppressGC
/*
* 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());
}