当前位置: 首页>>代码示例>>C++>>正文


C++ UniqueChars类代码示例

本文整理汇总了C++中UniqueChars的典型用法代码示例。如果您正苦于以下问题:C++ UniqueChars类的具体用法?C++ UniqueChars怎么用?C++ UniqueChars使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UniqueChars类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ToStringHelper

static nsresult
ToStringHelper(const char* aSeverity, const nsString& aMessage,
               const nsString& aSourceName, const nsString* aSourceLine,
               uint32_t aLineNumber, uint32_t aColumnNumber,
               nsACString& /*UTF8*/ aResult)
{
    static const char format0[] =
        "[%s: \"%s\" {file: \"%s\" line: %d column: %d source: \"%s\"}]";
    static const char format1[] =
        "[%s: \"%s\" {file: \"%s\" line: %d}]";
    static const char format2[] =
        "[%s: \"%s\"]";

    UniqueChars temp;
    char* tempMessage = nullptr;
    char* tempSourceName = nullptr;
    char* tempSourceLine = nullptr;

    if (!aMessage.IsEmpty())
        tempMessage = ToNewUTF8String(aMessage);
    if (!aSourceName.IsEmpty())
        // Use at most 512 characters from mSourceName.
        tempSourceName = ToNewUTF8String(StringHead(aSourceName, 512));
    if (aSourceLine && !aSourceLine->IsEmpty())
        // Use at most 512 characters from mSourceLine.
        tempSourceLine = ToNewUTF8String(StringHead(*aSourceLine, 512));

    if (nullptr != tempSourceName && nullptr != tempSourceLine) {
        temp = JS_smprintf(format0,
                           aSeverity,
                           tempMessage,
                           tempSourceName,
                           aLineNumber,
                           aColumnNumber,
                           tempSourceLine);
    } else if (!aSourceName.IsEmpty()) {
        temp = JS_smprintf(format1,
                           aSeverity,
                           tempMessage,
                           tempSourceName,
                           aLineNumber);
    } else {
        temp = JS_smprintf(format2,
                           aSeverity,
                           tempMessage);
    }

    if (nullptr != tempMessage)
        free(tempMessage);
    if (nullptr != tempSourceName)
        free(tempSourceName);
    if (nullptr != tempSourceLine)
        free(tempSourceLine);

    if (!temp)
        return NS_ERROR_OUT_OF_MEMORY;

    aResult.Assign(temp.get());
    return NS_OK;
}
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:60,代码来源:nsScriptError.cpp

示例2: Error

template<size_t N> inline bool
Error(JSContext* cx, const char (&input)[N], uint32_t expectedLine,
      uint32_t expectedColumn)
{
    AutoInflatedString str(cx);
    RootedValue dummy(cx);
    str = input;

    bool ok = JS_ParseJSON(cx, str.chars(), str.length(), &dummy);
    CHECK(!ok);

    RootedValue exn(cx);
    CHECK(JS_GetPendingException(cx, &exn));
    JS_ClearPendingException(cx);

    js::ErrorReport report(cx);
    CHECK(report.init(cx, exn, js::ErrorReport::WithSideEffects));
    CHECK(report.report()->errorNumber == JSMSG_JSON_BAD_PARSE);

    UniqueChars lineAndColumnASCII = JS_smprintf("line %d column %d", expectedLine, expectedColumn);
    CHECK(strstr(report.toStringResult().c_str(), lineAndColumnASCII.get()) != nullptr);

    /* We do not execute JS, so there should be no exception thrown. */
    CHECK(!JS_IsExceptionPending(cx));

    return true;
}
开发者ID:luke-chang,项目名称:gecko-1,代码行数:27,代码来源:testParseJSON.cpp

示例3: fprintf

void
Statistics::printStats()
{
    if (aborted) {
        if (fullFormat)
            fprintf(fp, "OOM during GC statistics collection. The report is unavailable for this GC.\n");
        fflush(fp);
        return;
    }

    if (fullFormat) {
        UniqueChars msg = formatDetailedMessage();
        if (msg)
            fprintf(fp, "GC(T+%.3fs) %s\n", t(slices[0].start - startupTime) / 1000.0, msg.get());
    } else {
        int64_t total, longest;
        gcDuration(&total, &longest);

        int64_t markTotal = SumPhase(PHASE_MARK, phaseTimes);
        fprintf(fp, "%f %f %f\n",
                t(total),
                t(markTotal),
                t(phaseTimes[PHASE_DAG_NONE][PHASE_SWEEP]));
        MOZ_ASSERT(phaseExtra[PHASE_SWEEP].dagSlot == PHASE_DAG_NONE);
    }
    fflush(fp);
}
开发者ID:alexey-kalashnikov,项目名称:gecko-dev,代码行数:27,代码来源:Statistics.cpp

示例4: strlen

/*
 * Serializes the script/function pair into a "descriptive string" which is
 * allowed to fail. This function cannot trigger a GC because it could finalize
 * some scripts, resize the hash table of profile strings, and invalidate the
 * AddPtr held while invoking allocProfileString.
 */
UniqueChars
SPSProfiler::allocProfileString(JSScript* script, JSFunction* maybeFun)
{
    // Note: this profiler string is regexp-matched by
    // devtools/client/profiler/cleopatra/js/parserWorker.js.

    // Get the function name, if any.
    JSAtom* atom = maybeFun ? maybeFun->displayAtom() : nullptr;

    // Get the script filename, if any, and its length.
    const char* filename = script->filename();
    if (filename == nullptr)
        filename = "<unknown>";
    size_t lenFilename = strlen(filename);

    // Get the line number and its length as a string.
    uint64_t lineno = script->lineno();
    size_t lenLineno = 1;
    for (uint64_t i = lineno; i /= 10; lenLineno++);

    // Determine the required buffer size.
    size_t len = lenFilename + lenLineno + 1; // +1 for the ":" separating them.
    if (atom) {
        len += JS::GetDeflatedUTF8StringLength(atom) + 3; // +3 for the " (" and ")" it adds.
    }

    // Allocate the buffer.
    UniqueChars cstr(js_pod_malloc<char>(len + 1));
    if (!cstr)
        return nullptr;

    // Construct the descriptive string.
    DebugOnly<size_t> ret;
    if (atom) {
        UniqueChars atomStr = StringToNewUTF8CharsZ(nullptr, *atom);
        if (!atomStr)
            return nullptr;

        ret = snprintf(cstr.get(), len + 1, "%s (%s:%" PRIu64 ")", atomStr.get(), filename, lineno);
    } else {
        ret = snprintf(cstr.get(), len + 1, "%s:%" PRIu64, filename, lineno);
    }

    MOZ_ASSERT(ret == len, "Computed length should match actual length!");

    return cstr;
}
开发者ID:mephisto41,项目名称:gecko-dev,代码行数:53,代码来源:SPSProfiler.cpp

示例5: NewUPluralRules

/**
 * Returns a new UPluralRules with the locale and type options of the given
 * PluralRules.
 */
static UPluralRules* NewUPluralRules(JSContext* cx,
                                     Handle<PluralRulesObject*> pluralRules) {
  RootedObject internals(cx, intl::GetInternalsObject(cx, pluralRules));
  if (!internals) {
    return nullptr;
  }

  RootedValue value(cx);

  if (!GetProperty(cx, internals, internals, cx->names().locale, &value)) {
    return nullptr;
  }
  UniqueChars locale = intl::EncodeLocale(cx, value.toString());
  if (!locale) {
    return nullptr;
  }

  if (!GetProperty(cx, internals, internals, cx->names().type, &value)) {
    return nullptr;
  }

  UPluralType category;
  {
    JSLinearString* type = value.toString()->ensureLinear(cx);
    if (!type) {
      return nullptr;
    }

    if (StringEqualsAscii(type, "cardinal")) {
      category = UPLURAL_TYPE_CARDINAL;
    } else {
      MOZ_ASSERT(StringEqualsAscii(type, "ordinal"));
      category = UPLURAL_TYPE_ORDINAL;
    }
  }

  UErrorCode status = U_ZERO_ERROR;
  UPluralRules* pr =
      uplrules_openForType(IcuLocale(locale.get()), category, &status);
  if (U_FAILURE(status)) {
    intl::ReportInternalError(cx);
    return nullptr;
  }
  return pr;
}
开发者ID:servo,项目名称:mozjs,代码行数:49,代码来源:PluralRules.cpp

示例6: FilterJsonKey

UniqueChars
Statistics::formatJsonPhaseTimes(const PhaseTimeTable phaseTimes)
{
    FragmentVector fragments;
    char buffer[128];
    for (AllPhaseIterator iter(phaseTimes); !iter.done(); iter.advance()) {
        Phase phase;
        size_t dagSlot;
        iter.get(&phase, &dagSlot);

        UniqueChars name = FilterJsonKey(phases[phase].name);
        int64_t ownTime = phaseTimes[dagSlot][phase];
        JS_snprintf(buffer, sizeof(buffer), "\"%s\":%llu.%03llu",
                    name.get(), ownTime / 1000, ownTime % 1000);

        if (!fragments.append(DuplicateString(buffer)))
            return UniqueChars(nullptr);
    }
    return Join(fragments, ",");
}
开发者ID:cliqz-oss,项目名称:browser-f,代码行数:20,代码来源:Statistics.cpp

示例7: DecodeFieldName

static UniqueChars
DecodeFieldName(JSContext* cx, Decoder& d, CStringSet* dupSet)
{
    UniqueChars fieldName = d.readCString();
    if (!fieldName) {
        Fail(cx, d, "expected export external name string");
        return nullptr;
    }

    CStringSet::AddPtr p = dupSet->lookupForAdd(fieldName.get());
    if (p) {
        Fail(cx, d, "duplicate export");
        return nullptr;
    }

    if (!dupSet->add(p, fieldName.get()))
        return nullptr;

    return Move(fieldName);
}
开发者ID:kitcambridge,项目名称:gecko-dev,代码行数:20,代码来源:Wasm.cpp

示例8: fprintf

void
Statistics::printStats()
{
    if (aborted) {
        fprintf(fp, "OOM during GC statistics collection. The report is unavailable for this GC.\n");
    } else {
        UniqueChars msg = formatDetailedMessage();
        if (msg)
            fprintf(fp, "GC(T+%.3fs) %s\n", t(slices[0].start - startupTime) / 1000.0, msg.get());
    }
    fflush(fp);
}
开发者ID:mephisto41,项目名称:gecko-dev,代码行数:12,代码来源:Statistics.cpp

示例9: CallArgsFromVp

// ES6 draft rev34 (2015/02/20) 19.1.2.2 Object.create(O [, Properties])
bool
js::obj_create(JSContext* cx, unsigned argc, Value* vp)
{
    CallArgs args = CallArgsFromVp(argc, vp);

    // Step 1.
    if (args.length() == 0) {
        JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
                             "Object.create", "0", "s");
        return false;
    }

    if (!args[0].isObjectOrNull()) {
        RootedValue v(cx, args[0]);
        UniqueChars bytes = DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, v, nullptr);
        if (!bytes)
            return false;
        JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_UNEXPECTED_TYPE,
                             bytes.get(), "not an object or null");
        return false;
    }

    // Step 2.
    RootedObject proto(cx, args[0].toObjectOrNull());
    RootedPlainObject obj(cx, ObjectCreateImpl(cx, proto));
    if (!obj)
        return false;

    // Step 3.
    if (args.hasDefined(1)) {
        RootedValue val(cx, args[1]);
        RootedObject props(cx, ToObject(cx, val));
        if (!props || !DefineProperties(cx, obj, props))
            return false;
    }

    // Step 4.
    args.rval().setObject(*obj);
    return true;
}
开发者ID:cbradley857,项目名称:gecko-dev,代码行数:41,代码来源:Object.cpp

示例10: FormatWasmFrame

static char*
FormatWasmFrame(JSContext* cx, const FrameIter& iter, char* buf, int num, bool showArgs)
{
    JSAtom* functionDisplayAtom = iter.functionDisplayAtom();
    UniqueChars nameStr;
    if (functionDisplayAtom)
        nameStr = StringToNewUTF8CharsZ(cx, *functionDisplayAtom);

    buf = sprintf_append(cx, buf, "%d %s()",
                         num,
                         nameStr ? nameStr.get() : "<wasm-function>");
    if (!buf)
        return nullptr;
    const char* filename = iter.filename();
    uint32_t lineno = iter.computeLine();
    buf = sprintf_append(cx, buf, " [\"%s\":%d]\n",
                         filename ? filename : "<unknown>",
                         lineno);

    MOZ_ASSERT(!cx->isExceptionPending());
    return buf;
}
开发者ID:mephisto41,项目名称:gecko-dev,代码行数:22,代码来源:jsfriendapi.cpp

示例11: GetPM

static PerfMeasurement*
GetPM(JSContext* cx, JS::HandleValue value, const char* fname)
{
    if (!value.isObject()) {
        UniqueChars bytes = DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, value, nullptr);
        if (!bytes)
            return nullptr;
        JS_ReportErrorNumber(cx, GetErrorMessage, 0, JSMSG_NOT_NONNULL_OBJECT, bytes.get());
        return nullptr;
    }
    RootedObject obj(cx, &value.toObject());
    PerfMeasurement* p = (PerfMeasurement*)
        JS_GetInstancePrivate(cx, obj, &pm_class, nullptr);
    if (p)
        return p;

    // JS_GetInstancePrivate only sets an exception if its last argument
    // is nonzero, so we have to do it by hand.
    JS_ReportErrorNumber(cx, GetErrorMessage, 0, JSMSG_INCOMPATIBLE_PROTO,
                         pm_class.name, fname, JS_GetClass(obj)->name);
    return nullptr;
}
开发者ID:cstipkovic,项目名称:gecko-dev,代码行数:22,代码来源:jsperf.cpp

示例12: WeakMap_set_impl

MOZ_ALWAYS_INLINE bool
WeakMap_set_impl(JSContext* cx, const CallArgs& args)
{
    MOZ_ASSERT(IsWeakMap(args.thisv()));

    if (!args.get(0).isObject()) {
        UniqueChars bytes = DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, args.get(0), nullptr);
        if (!bytes)
            return false;
        JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT, bytes.get());
        return false;
    }

    RootedObject key(cx, &args[0].toObject());
    Rooted<JSObject*> thisObj(cx, &args.thisv().toObject());
    Rooted<WeakMapObject*> map(cx, &thisObj->as<WeakMapObject>());

    if (!SetWeakMapEntryInternal(cx, map, key, args.get(1)))
        return false;
    args.rval().set(args.thisv());
    return true;
}
开发者ID:cliqz-oss,项目名称:browser-f,代码行数:22,代码来源:WeakMapObject.cpp

示例13: DecodeImport

static bool
DecodeImport(JSContext* cx, Decoder& d, ModuleGeneratorData* init, ImportNameVector* importNames)
{
    const DeclaredSig* sig;
    if (!DecodeSignatureIndex(cx, d, *init, &sig))
        return false;

    if (!init->imports.emplaceBack(sig))
        return false;

    UniqueChars moduleName = d.readCString();
    if (!moduleName)
        return Fail(cx, d, "expected import module name");

    if (!*moduleName.get())
        return Fail(cx, d, "module name cannot be empty");

    UniqueChars funcName = d.readCString();
    if (!funcName)
        return Fail(cx, d, "expected import func name");

    return importNames->emplaceBack(Move(moduleName), Move(funcName));
}
开发者ID:kitcambridge,项目名称:gecko-dev,代码行数:23,代码来源:Wasm.cpp

示例14: WasmTextToBinary

static bool
WasmTextToBinary(JSContext* cx, unsigned argc, Value* vp)
{
    CallArgs args = CallArgsFromVp(argc, vp);
    RootedObject callee(cx, &args.callee());

    if (args.length() != 1) {
        ReportUsageError(cx, callee, "Wrong number of arguments");
        return false;
    }

    if (!args[0].isString()) {
        ReportUsageError(cx, callee, "First argument must be a String");
        return false;
    }

    AutoStableStringChars twoByteChars(cx);
    if (!twoByteChars.initTwoByte(cx, args[0].toString()))
        return false;

    UniqueChars error;
    wasm::UniqueBytecode bytes = wasm::TextToBinary(twoByteChars.twoByteChars(), &error);
    if (!bytes) {
        JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_WASM_TEXT_FAIL,
                             error.get() ? error.get() : "out of memory");
        return false;
    }

    Rooted<ArrayBufferObject*> buffer(cx, ArrayBufferObject::create(cx, bytes->length()));
    if (!buffer)
        return false;

    memcpy(buffer->dataPointer(), bytes->begin(), bytes->length());

    args.rval().setObject(*buffer);
    return true;
}
开发者ID:ajkerrigan,项目名称:gecko-dev,代码行数:37,代码来源:Wasm.cpp

示例15: DecodeUnknownSection

static bool
DecodeUnknownSection(JSContext* cx, Decoder& d)
{
    UniqueChars sectionName = d.readCString();
    if (!sectionName)
        return Fail(cx, d, "failed to read section name");

    if (!strcmp(sectionName.get(), SigLabel) ||
        !strcmp(sectionName.get(), ImportLabel) ||
        !strcmp(sectionName.get(), DeclLabel) ||
        !strcmp(sectionName.get(), TableLabel) ||
        !strcmp(sectionName.get(), MemoryLabel) ||
        !strcmp(sectionName.get(), ExportLabel) ||
        !strcmp(sectionName.get(), FuncLabel) ||
        !strcmp(sectionName.get(), DataLabel))
    {
        return Fail(cx, d, "known section out of order");
    }

    if (!d.skipSection())
        return Fail(cx, d, "unable to skip unknown section");

    return true;
}
开发者ID:kitcambridge,项目名称:gecko-dev,代码行数:24,代码来源:Wasm.cpp


注:本文中的UniqueChars类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。