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


C++ AutoIdVector::appendAll方法代码示例

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


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

示例1: handler

// ES6 9.5.12 Proxy.[[OwnPropertyKeys]]()
bool
ScriptedDirectProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject proxy,
                                            AutoIdVector& props) const
{
    // Step 1.
    RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));

    // Step 2.
    if (!handler) {
        JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
        return false;
    }
    // Step 3. Superfluous assertion.

    // Step 4.
    RootedObject target(cx, proxy->as<ProxyObject>().target());

    // Steps 5-6.
    RootedValue trap(cx);
    if (!GetProperty(cx, handler, handler, cx->names().ownKeys, &trap))
        return false;

    // Step 7.
    if (trap.isUndefined())
        return GetPropertyKeys(cx, target, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &props);

    // Step 8.
    Value argv[] = {
        ObjectValue(*target)
    };
    RootedValue trapResultArray(cx);
    if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResultArray))
        return false;

    // Steps 9-10.
    AutoIdVector trapResult(cx);
    if (!CreateFilteredListFromArrayLike(cx, trapResultArray, trapResult))
        return false;

    // Steps 11-12.
    bool extensibleTarget;
    if (!IsExtensible(cx, target, &extensibleTarget))
        return false;

    // Steps 13-14.
    AutoIdVector targetKeys(cx);
    if (!GetPropertyKeys(cx, target, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &targetKeys))
        return false;

    // Step 15. Superfluous assertion.

    // Steps 16-17.
    AutoIdVector targetConfigurableKeys(cx);
    AutoIdVector targetNonconfigurableKeys(cx);

    // Step 18.
    Rooted<PropertyDescriptor> desc(cx);
    for (size_t i = 0; i < targetKeys.length(); ++i) {
        // Steps a-b.
        if (!GetOwnPropertyDescriptor(cx, target, targetKeys[i], &desc))
            return false;

        // Steps c-d.
        if (desc.object() && !desc.configurable()) {
            if (!targetNonconfigurableKeys.append(targetKeys[i]))
                return false;
        } else {
            if (!targetConfigurableKeys.append(targetKeys[i]))
                return false;
        }
    }

    // Step 19.
    if (extensibleTarget && targetNonconfigurableKeys.empty())
        return props.appendAll(trapResult);

    // Step 20.
    AutoIdVector uncheckedResultKeys(cx);
    if (!uncheckedResultKeys.appendAll(trapResult))
        return false;

    // Step 21.
    for (size_t i = 0; i < targetNonconfigurableKeys.length(); ++i) {
        RootedId key(cx, targetNonconfigurableKeys[i]);
        MOZ_ASSERT(key != JSID_VOID);

        bool found = false;
        for (size_t j = 0; j < uncheckedResultKeys.length(); ++j) {
            if (key == uncheckedResultKeys[j]) {
                uncheckedResultKeys[j].set(JSID_VOID);
                found = true;
                break;
            }
        }

        if (!found) {
            JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_CANT_SKIP_NC);
            return false;
        }
//.........这里部分代码省略.........
开发者ID:paulmadore,项目名称:luckyde,代码行数:101,代码来源:ScriptedDirectProxyHandler.cpp

示例2: handler

// ES2018 draft rev aab1ea3bd4d03c85d6f4a91503b4169346ab7271
// 9.5.11 Proxy.[[OwnPropertyKeys]]()
bool
ScriptedProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject proxy, AutoIdVector& props) const
{
    // Steps 1-3.
    RootedObject handler(cx, ScriptedProxyHandler::handlerObject(proxy));
    if (!handler) {
        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
        return false;
    }

    // Step 4.
    RootedObject target(cx, proxy->as<ProxyObject>().target());
    MOZ_ASSERT(target);

    // Step 5.
    RootedValue trap(cx);
    if (!GetProxyTrap(cx, handler, cx->names().ownKeys, &trap))
        return false;

    // Step 6.
    if (trap.isUndefined())
        return GetPropertyKeys(cx, target, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &props);

    // Step 7.
    RootedValue trapResultArray(cx);
    RootedValue targetVal(cx, ObjectValue(*target));
    if (!Call(cx, trap, handler, targetVal, &trapResultArray))
        return false;

    // Step 8.
    AutoIdVector trapResult(cx);
    if (!CreateFilteredListFromArrayLike(cx, trapResultArray, trapResult))
        return false;

    // Steps 9, 18.
    Rooted<GCHashSet<jsid>> uncheckedResultKeys(cx, GCHashSet<jsid>(cx));
    if (!uncheckedResultKeys.init(trapResult.length()))
        return false;

    for (size_t i = 0, len = trapResult.length(); i < len; i++) {
        MOZ_ASSERT(!JSID_IS_VOID(trapResult[i]));

        auto ptr = uncheckedResultKeys.lookupForAdd(trapResult[i]);
        if (ptr)
            return js::Throw(cx, trapResult[i], JSMSG_OWNKEYS_DUPLICATE);

        if (!uncheckedResultKeys.add(ptr, trapResult[i]))
            return false;
    }

    // Step 10.
    bool extensibleTarget;
    if (!IsExtensible(cx, target, &extensibleTarget))
        return false;

    // Steps 11-13.
    AutoIdVector targetKeys(cx);
    if (!GetPropertyKeys(cx, target, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &targetKeys))
        return false;

    // Steps 14-15.
    AutoIdVector targetConfigurableKeys(cx);
    AutoIdVector targetNonconfigurableKeys(cx);

    // Step 16.
    Rooted<PropertyDescriptor> desc(cx);
    for (size_t i = 0; i < targetKeys.length(); ++i) {
        // Step 16.a.
        if (!GetOwnPropertyDescriptor(cx, target, targetKeys[i], &desc))
            return false;

        // Steps 16.b-c.
        if (desc.object() && !desc.configurable()) {
            if (!targetNonconfigurableKeys.append(targetKeys[i]))
                return false;
        } else {
            if (!targetConfigurableKeys.append(targetKeys[i]))
                return false;
        }
    }

    // Step 17.
    if (extensibleTarget && targetNonconfigurableKeys.empty())
        return props.appendAll(trapResult);

    // Step 19.
    for (size_t i = 0; i < targetNonconfigurableKeys.length(); ++i) {
        MOZ_ASSERT(!JSID_IS_VOID(targetNonconfigurableKeys[i]));

        auto ptr = uncheckedResultKeys.lookup(targetNonconfigurableKeys[i]);

        // Step 19.a.
        if (!ptr)
            return js::Throw(cx, targetNonconfigurableKeys[i], JSMSG_CANT_SKIP_NC);

        // Step 19.b.
        uncheckedResultKeys.remove(ptr);
    }
//.........这里部分代码省略.........
开发者ID:luke-chang,项目名称:gecko-1,代码行数:101,代码来源:ScriptedProxyHandler.cpp

示例3: handler

// ES8 rev 0c1bd3004329336774cbc90de727cd0cf5f11e93 9.5.11 Proxy.[[OwnPropertyKeys]]()
bool
ScriptedProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject proxy, AutoIdVector& props) const
{
    // Steps 1-3.
    RootedObject handler(cx, ScriptedProxyHandler::handlerObject(proxy));
    if (!handler) {
        JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
        return false;
    }

    // Step 4.
    RootedObject target(cx, proxy->as<ProxyObject>().target());
    MOZ_ASSERT(target);

    // Step 5.
    RootedValue trap(cx);
    if (!GetProxyTrap(cx, handler, cx->names().ownKeys, &trap))
        return false;

    // Step 6.
    if (trap.isUndefined())
        return GetPropertyKeys(cx, target, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &props);

    // Step 7.
    RootedValue trapResultArray(cx);
    RootedValue targetVal(cx, ObjectValue(*target));
    if (!Call(cx, trap, handler, targetVal, &trapResultArray))
        return false;

    // Step 8.
    AutoIdVector trapResult(cx);
    if (!CreateFilteredListFromArrayLike(cx, trapResultArray, trapResult))
        return false;

    // Step 9.
    bool extensibleTarget;
    if (!IsExtensible(cx, target, &extensibleTarget))
        return false;

    // Steps 10-11.
    AutoIdVector targetKeys(cx);
    if (!GetPropertyKeys(cx, target, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &targetKeys))
        return false;

    // Steps 12-13.
    AutoIdVector targetConfigurableKeys(cx);
    AutoIdVector targetNonconfigurableKeys(cx);

    // Step 14.
    Rooted<PropertyDescriptor> desc(cx);
    for (size_t i = 0; i < targetKeys.length(); ++i) {
        // Step 14a.
        if (!GetOwnPropertyDescriptor(cx, target, targetKeys[i], &desc))
            return false;

        // Steps 14b-c.
        if (desc.object() && !desc.configurable()) {
            if (!targetNonconfigurableKeys.append(targetKeys[i]))
                return false;
        } else {
            if (!targetConfigurableKeys.append(targetKeys[i]))
                return false;
        }
    }

    // Step 15.
    if (extensibleTarget && targetNonconfigurableKeys.empty())
        return props.appendAll(trapResult);

    // Step 16.
    // The algorithm below always removes all occurences of the same key
    // at once, so we can use a set here.
    Rooted<GCHashSet<jsid>> uncheckedResultKeys(cx, GCHashSet<jsid>(cx));
    if (!uncheckedResultKeys.init(trapResult.length()))
        return false;

    for (size_t i = 0, len = trapResult.length(); i < len; i++) {
        MOZ_ASSERT(!JSID_IS_VOID(trapResult[i]));

        if (!uncheckedResultKeys.put(trapResult[i]))
            return false;
    }

    // Step 17.
    for (size_t i = 0; i < targetNonconfigurableKeys.length(); ++i) {
        MOZ_ASSERT(!JSID_IS_VOID(targetNonconfigurableKeys[i]));

        auto ptr = uncheckedResultKeys.lookup(targetNonconfigurableKeys[i]);

        // Step 17a.
        if (!ptr) {
            JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_CANT_SKIP_NC);
            return false;
        }

        // Step 17b.
        uncheckedResultKeys.remove(ptr);
    }

//.........这里部分代码省略.........
开发者ID:cstipkovic,项目名称:gecko-dev,代码行数:101,代码来源:ScriptedProxyHandler.cpp


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