本文整理汇总了C++中mozilla::ArrayLength方法的典型用法代码示例。如果您正苦于以下问题:C++ mozilla::ArrayLength方法的具体用法?C++ mozilla::ArrayLength怎么用?C++ mozilla::ArrayLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozilla
的用法示例。
在下文中一共展示了mozilla::ArrayLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFlags
bool
RegExpShared::compile(JSContext *cx, JSAtom *source)
{
if (!sticky())
return code.compile(cx, *source, &parenCount, getFlags());
/*
* The sticky case we implement hackily by prepending a caret onto the front
* and relying on |::execute| to pseudo-slice the string when it sees a sticky regexp.
*/
static const jschar prefix[] = {'^', '(', '?', ':'};
static const jschar postfix[] = {')'};
using mozilla::ArrayLength;
StringBuffer sb(cx);
if (!sb.reserve(ArrayLength(prefix) + source->length() + ArrayLength(postfix)))
return false;
sb.infallibleAppend(prefix, ArrayLength(prefix));
sb.infallibleAppend(source->chars(), source->length());
sb.infallibleAppend(postfix, ArrayLength(postfix));
JSAtom *fakeySource = sb.finishAtom();
if (!fakeySource)
return false;
return code.compile(cx, *fakeySource, &parenCount, getFlags());
}
示例2: TraceLoggerForMainThread
bool
RegExpShared::compile(JSContext *cx, bool matchOnly, const jschar *sampleChars, size_t sampleLength)
{
TraceLogger *logger = TraceLoggerForMainThread(cx->runtime());
AutoTraceLog logCompile(logger, TraceLogger::IrregexpCompile);
if (!sticky()) {
RootedAtom pattern(cx, source);
return compile(cx, pattern, matchOnly, sampleChars, sampleLength);
}
/*
* The sticky case we implement hackily by prepending a caret onto the front
* and relying on |::execute| to pseudo-slice the string when it sees a sticky regexp.
*/
static const jschar prefix[] = {'^', '(', '?', ':'};
static const jschar postfix[] = {')'};
using mozilla::ArrayLength;
StringBuffer sb(cx);
if (!sb.reserve(ArrayLength(prefix) + source->length() + ArrayLength(postfix)))
return false;
sb.infallibleAppend(prefix, ArrayLength(prefix));
sb.infallibleAppend(source->chars(), source->length());
sb.infallibleAppend(postfix, ArrayLength(postfix));
RootedAtom fakeySource(cx, sb.finishAtom());
if (!fakeySource)
return false;
return compile(cx, fakeySource, matchOnly, sampleChars, sampleLength);
}
示例3: TraceLoggerForMainThread
bool
RegExpShared::compile(JSContext* cx, HandleLinearString input,
CompilationMode mode, ForceByteCodeEnum force)
{
TraceLoggerThread* logger = TraceLoggerForMainThread(cx->runtime());
AutoTraceLog logCompile(logger, TraceLogger_IrregexpCompile);
if (!sticky()) {
RootedAtom pattern(cx, source);
return compile(cx, pattern, input, mode, force);
}
/*
* The sticky case we implement hackily by prepending a caret onto the front
* and relying on |::execute| to pseudo-slice the string when it sees a sticky regexp.
*/
static const char prefix[] = {'^', '(', '?', ':'};
static const char postfix[] = {')'};
using mozilla::ArrayLength;
StringBuffer sb(cx);
if (!sb.reserve(ArrayLength(prefix) + source->length() + ArrayLength(postfix)))
return false;
sb.infallibleAppend(prefix, ArrayLength(prefix));
if (!sb.append(source))
return false;
sb.infallibleAppend(postfix, ArrayLength(postfix));
RootedAtom fakeySource(cx, sb.finishAtom());
if (!fakeySource)
return false;
return compile(cx, fakeySource, input, mode, force);
}
示例4: marked
bool
RegExpShared::needsSweep(JSRuntime* rt)
{
// Sometimes RegExpShared instances are marked without the compartment
// being subsequently cleared. This can happen if a GC is restarted while
// in progress (i.e. performing a full GC in the middle of an incremental
// GC) or if a RegExpShared referenced via the stack is traced but is not
// in a zone being collected.
//
// Because of this we only treat the marked_ bit as a hint, and destroy the
// RegExpShared if it was accidentally marked earlier but wasn't marked by
// the current trace.
bool keep = marked() && IsMarked(&source);
for (size_t i = 0; i < ArrayLength(compilationArray); i++) {
RegExpShared::RegExpCompilation& compilation = compilationArray[i];
if (compilation.jitCode && gc::IsAboutToBeFinalized(&compilation.jitCode))
keep = false;
}
MOZ_ASSERT(rt->isHeapMajorCollecting());
if (keep || rt->gc.isHeapCompacting()) {
clearMarked();
return false;
}
return true;
}
示例5: CallArgsFromVp
static bool
GCParameter(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
JSString *str = ToString(cx, args.get(0));
if (!str)
return false;
JSFlatString *flatStr = JS_FlattenString(cx, str);
if (!flatStr)
return false;
size_t paramIndex = 0;
for (;; paramIndex++) {
if (paramIndex == ArrayLength(paramMap)) {
JS_ReportError(cx,
"the first argument must be one of " GC_PARAMETER_ARGS_LIST);
return false;
}
if (JS_FlatStringEqualsAscii(flatStr, paramMap[paramIndex].name))
break;
}
JSGCParamKey param = paramMap[paramIndex].param;
// Request mode.
if (args.length() == 1) {
uint32_t value = JS_GetGCParameter(cx->runtime(), param);
args.rval().setNumber(value);
return true;
}
if (param == JSGC_NUMBER || param == JSGC_BYTES) {
JS_ReportError(cx, "Attempt to change read-only parameter %s",
paramMap[paramIndex].name);
return false;
}
uint32_t value;
if (!ToUint32(cx, args[1], &value)) {
JS_ReportError(cx, "the second argument must be convertable to uint32_t "
"with non-zero value");
return false;
}
if (param == JSGC_MAX_BYTES) {
uint32_t gcBytes = JS_GetGCParameter(cx->runtime(), JSGC_BYTES);
if (value < gcBytes) {
JS_ReportError(cx,
"attempt to set maxBytes to the value less than the current "
"gcBytes (%u)",
gcBytes);
return false;
}
}
JS_SetGCParameter(cx->runtime(), param, value);
args.rval().setUndefined();
return true;
}
示例6: spec
// static
nsresult
nsChannelClassifier::SetBlockedTrackingContent(nsIChannel *channel)
{
// Can be called in EITHER the parent or child process.
nsCOMPtr<nsIParentChannel> parentChannel;
NS_QueryNotificationCallbacks(channel, parentChannel);
if (parentChannel) {
// This channel is a parent-process proxy for a child process request. The
// actual channel will be notified via the status passed to
// nsIRequest::Cancel and do this for us.
return NS_OK;
}
nsresult rv;
nsCOMPtr<nsIDOMWindow> win;
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
do_GetService(THIRDPARTYUTIL_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, NS_OK);
rv = thirdPartyUtil->GetTopWindowForChannel(channel, getter_AddRefs(win));
NS_ENSURE_SUCCESS(rv, NS_OK);
nsCOMPtr<nsPIDOMWindow> pwin = do_QueryInterface(win, &rv);
NS_ENSURE_SUCCESS(rv, NS_OK);
nsCOMPtr<nsIDocShell> docShell = pwin->GetDocShell();
if (!docShell) {
return NS_OK;
}
nsCOMPtr<nsIDocument> doc = do_GetInterface(docShell, &rv);
NS_ENSURE_SUCCESS(rv, NS_OK);
// Notify nsIWebProgressListeners of this security event.
// Can be used to change the UI state.
nsCOMPtr<nsISecurityEventSink> eventSink = do_QueryInterface(docShell, &rv);
NS_ENSURE_SUCCESS(rv, NS_OK);
uint32_t state = 0;
nsCOMPtr<nsISecureBrowserUI> securityUI;
docShell->GetSecurityUI(getter_AddRefs(securityUI));
if (!securityUI) {
return NS_OK;
}
doc->SetHasTrackingContentBlocked(true);
securityUI->GetState(&state);
state |= nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT;
eventSink->OnSecurityChange(nullptr, state);
// Log a warning to the web console.
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
nsCString utf8spec;
uri->GetSpec(utf8spec);
NS_ConvertUTF8toUTF16 spec(utf8spec);
const char16_t* params[] = { spec.get() };
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("Tracking Protection"),
doc,
nsContentUtils::eNECKO_PROPERTIES,
"TrackingUriBlocked",
params, ArrayLength(params));
return NS_OK;
}
示例7: IsObjectAboutToBeFinalized
void
RegExpCompartment::sweep(JSRuntime *rt)
{
for (Set::Enum e(set_); !e.empty(); e.popFront()) {
RegExpShared *shared = e.front();
// Sometimes RegExpShared instances are marked without the
// compartment being subsequently cleared. This can happen if a GC is
// restarted while in progress (i.e. performing a full GC in the
// middle of an incremental GC) or if a RegExpShared referenced via the
// stack is traced but is not in a zone being collected.
//
// Because of this we only treat the marked_ bit as a hint, and destroy
// the RegExpShared if it was accidentally marked earlier but wasn't
// marked by the current trace.
bool keep = shared->marked() && !IsStringAboutToBeFinalized(shared->source.unsafeGet());
for (size_t i = 0; i < ArrayLength(shared->compilationArray); i++) {
RegExpShared::RegExpCompilation &compilation = shared->compilationArray[i];
if (keep && compilation.jitCode)
keep = !IsJitCodeAboutToBeFinalized(compilation.jitCode.unsafeGet());
}
if (keep) {
shared->clearMarked();
} else {
js_delete(shared);
e.removeFront();
}
}
if (matchResultTemplateObject_ &&
IsObjectAboutToBeFinalized(matchResultTemplateObject_.unsafeGet()))
{
matchResultTemplateObject_.set(nullptr);
}
}
示例8: if
void
HelperThread::threadLoop()
{
MOZ_ASSERT(CanUseExtraThreads());
JS::AutoSuppressGCAnalysis nogc;
AutoLockHelperThreadState lock;
js::TlsPerThreadData.set(threadData.ptr());
// Compute the thread's stack limit, for over-recursed checks.
uintptr_t stackLimit = GetNativeStackBase();
#if JS_STACK_GROWTH_DIRECTION > 0
stackLimit += HELPER_STACK_QUOTA;
#else
stackLimit -= HELPER_STACK_QUOTA;
#endif
for (size_t i = 0; i < ArrayLength(threadData->nativeStackLimit); i++)
threadData->nativeStackLimit[i] = stackLimit;
while (true) {
MOZ_ASSERT(idle());
// Block until a task is available. Save the value of whether we are
// going to do an Ion compile, in case the value returned by the method
// changes.
bool ionCompile = false;
while (true) {
if (terminate)
return;
if (HelperThreadState().canStartAsmJSCompile() ||
(ionCompile = HelperThreadState().pendingIonCompileHasSufficientPriority()) ||
HelperThreadState().canStartParseTask() ||
HelperThreadState().canStartCompressionTask() ||
HelperThreadState().canStartGCHelperTask() ||
HelperThreadState().canStartGCParallelTask())
{
break;
}
HelperThreadState().wait(GlobalHelperThreadState::PRODUCER);
}
// Dispatch tasks, prioritizing AsmJS work.
if (HelperThreadState().canStartAsmJSCompile())
handleAsmJSWorkload();
else if (ionCompile)
handleIonWorkload();
else if (HelperThreadState().canStartParseTask())
handleParseWorkload();
else if (HelperThreadState().canStartCompressionTask())
handleCompressionWorkload();
else if (HelperThreadState().canStartGCHelperTask())
handleGCHelperWorkload();
else if (HelperThreadState().canStartGCParallelTask())
handleGCParallelWorkload();
else
MOZ_CRASH("No task to perform");
}
}
示例9: AssertCanGC
bool
js::XDRAtom(XDRState<mode> *xdr, MutableHandleAtom atomp)
{
AssertCanGC();
if (mode == XDR_ENCODE) {
uint32_t nchars = atomp->length();
if (!xdr->codeUint32(&nchars))
return false;
jschar *chars = const_cast<jschar *>(atomp->getChars(xdr->cx()));
if (!chars)
return false;
return xdr->codeChars(chars, nchars);
}
/* Avoid JSString allocation for already existing atoms. See bug 321985. */
uint32_t nchars;
if (!xdr->codeUint32(&nchars))
return false;
JSContext *cx = xdr->cx();
JSAtom *atom;
#if IS_LITTLE_ENDIAN
/* Directly access the little endian chars in the XDR buffer. */
const jschar *chars = reinterpret_cast<const jschar *>(xdr->buf.read(nchars * sizeof(jschar)));
atom = AtomizeChars<CanGC>(cx, chars, nchars);
#else
/*
* We must copy chars to a temporary buffer to convert between little and
* big endian data.
*/
jschar *chars;
jschar stackChars[256];
if (nchars <= ArrayLength(stackChars)) {
chars = stackChars;
} else {
/*
* This is very uncommon. Don't use the tempLifoAlloc arena for this as
* most allocations here will be bigger than tempLifoAlloc's default
* chunk size.
*/
chars = cx->runtime->pod_malloc<jschar>(nchars);
if (!chars)
return false;
}
JS_ALWAYS_TRUE(xdr->codeChars(chars, nchars));
atom = AtomizeChars<CanGC>(cx, chars, nchars);
if (chars != stackChars)
js_free(chars);
#endif /* !IS_LITTLE_ENDIAN */
if (!atom)
return false;
atomp.set(atom);
return true;
}
示例10: handler
// ES6 (22 May, 2014) 9.5.14 Proxy.[[Construct]]
bool
ScriptedDirectProxyHandler::construct(JSContext* cx, HandleObject proxy, const CallArgs& args) const
{
// step 1
RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));
// step 2
if (!handler) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
return false;
}
// step 3
RootedObject target(cx, proxy->as<ProxyObject>().target());
MOZ_ASSERT(target->isConstructor());
// step 7
RootedObject argsArray(cx, NewDenseCopiedArray(cx, args.length(), args.array()));
if (!argsArray)
return false;
// step 4-5
RootedValue trap(cx);
if (!GetProperty(cx, handler, handler, cx->names().construct, &trap))
return false;
// step 6
if (trap.isUndefined()) {
ConstructArgs cargs(cx);
if (!FillArgumentsFromArraylike(cx, cargs, args))
return false;
RootedValue targetv(cx, ObjectValue(*target));
RootedObject obj(cx);
if (!Construct(cx, targetv, cargs, args.newTarget(), &obj))
return false;
args.rval().setObject(*obj);
return true;
}
// step 8-9
Value constructArgv[] = {
ObjectValue(*target),
ObjectValue(*argsArray),
args.newTarget()
};
RootedValue thisValue(cx, ObjectValue(*handler));
if (!Invoke(cx, thisValue, trap, ArrayLength(constructArgv), constructArgv, args.rval()))
return false;
// step 10
if (!args.rval().isObject()) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_PROXY_CONSTRUCT_OBJECT);
return false;
}
return true;
}
示例11: handler
// ES6 draft rev 32 (2 Feb 2014) 9.5.10 Proxy.[[Delete]](P)
bool
ScriptedDirectProxyHandler::delete_(JSContext* cx, HandleObject proxy, HandleId id,
ObjectOpResult& result) const
{
// step 2
RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));
// step 3
if (!handler) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
return false;
}
// steps 4-5
RootedObject target(cx, proxy->as<ProxyObject>().target());
// steps 6-7
RootedValue trap(cx);
if (!GetProperty(cx, handler, handler, cx->names().deleteProperty, &trap))
return false;
// step 8
if (trap.isUndefined())
return DeleteProperty(cx, target, id, result);
// steps 9-10
RootedValue value(cx);
if (!IdToStringOrSymbol(cx, id, &value))
return false;
Value argv[] = {
ObjectValue(*target),
value
};
RootedValue trapResult(cx);
if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
return false;
// step 11
if (!ToBoolean(trapResult))
return result.fail(JSMSG_PROXY_DELETE_RETURNED_FALSE);
// steps 12-13
Rooted<PropertyDescriptor> desc(cx);
if (!GetOwnPropertyDescriptor(cx, target, id, &desc))
return false;
// step 14-15
if (desc.object() && !desc.configurable()) {
RootedValue v(cx, IdToValue(id));
ReportValueError(cx, JSMSG_CANT_DELETE, JSDVG_IGNORE_STACK, v, nullptr);
return false;
}
// step 16
return result.succeed();
}
示例12: handler
// ES6 (22 May, 2014) 9.5.4 Proxy.[[PreventExtensions]]()
bool
ScriptedDirectProxyHandler::preventExtensions(JSContext *cx, HandleObject proxy) const
{
// step 1
RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));
// step 2
if (!handler) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
return false;
}
// step 3
RootedObject target(cx, proxy->as<ProxyObject>().target());
// step 4-5
RootedValue trap(cx);
if (!JSObject::getProperty(cx, handler, handler, cx->names().preventExtensions, &trap))
return false;
// step 6
if (trap.isUndefined())
return DirectProxyHandler::preventExtensions(cx, proxy);
// step 7, 9
Value argv[] = {
ObjectValue(*target)
};
RootedValue trapResult(cx);
if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
return false;
// step 8
bool success = ToBoolean(trapResult);
if (success) {
// step 10
bool extensible;
if (!JSObject::isExtensible(cx, target, &extensible))
return false;
if (extensible) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE);
return false;
}
// step 11 "return true"
return true;
}
// step 11 "return false"
// This actually corresponds to 19.1.2.5 step 4. We cannot pass the failure back, so throw here
// directly instead.
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_CHANGE_EXTENSIBILITY);
return false;
}
示例13: TraceNullableEdge
void
RegExpShared::trace(JSTracer* trc)
{
if (trc->isMarkingTracer())
marked_ = true;
TraceNullableEdge(trc, &source, "RegExpShared source");
for (size_t i = 0; i < ArrayLength(compilationArray); i++) {
RegExpCompilation& compilation = compilationArray[i];
TraceNullableEdge(trc, &compilation.jitCode, "RegExpShared code");
}
}
示例14: handler
// ES6 20141014 9.5.4 Proxy.[[PreventExtensions]]()
bool
ScriptedDirectProxyHandler::preventExtensions(JSContext *cx, HandleObject proxy,
bool *succeeded) const
{
// Steps 1-3.
RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));
if (!handler) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
return false;
}
// Step 4.
RootedObject target(cx, proxy->as<ProxyObject>().target());
// Steps 5-6.
RootedValue trap(cx);
if (!JSObject::getProperty(cx, handler, handler, cx->names().preventExtensions, &trap))
return false;
// Step 7.
if (trap.isUndefined())
return DirectProxyHandler::preventExtensions(cx, proxy, succeeded);
// Steps 8, 10.
Value argv[] = {
ObjectValue(*target)
};
RootedValue trapResult(cx);
if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
return false;
// Step 9.
bool booleanTrapResult = ToBoolean(trapResult);
// Step 11.
if (booleanTrapResult) {
bool extensible;
if (!JSObject::isExtensible(cx, target, &extensible))
return false;
if (extensible) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_REPORT_AS_NON_EXTENSIBLE);
return false;
}
}
// Step 12.
*succeeded = booleanTrapResult;
return true;
}
示例15: MarkString
void
RegExpShared::trace(JSTracer* trc)
{
if (IS_GC_MARKING_TRACER(trc))
marked_ = true;
if (source)
MarkString(trc, &source, "RegExpShared source");
for (size_t i = 0; i < ArrayLength(compilationArray); i++) {
RegExpCompilation& compilation = compilationArray[i];
if (compilation.jitCode)
MarkJitCode(trc, &compilation.jitCode, "RegExpShared code");
}
}