コード例 #1
0
void ScriptPromisePropertyBase::clearWrappers()
{
    v8::HandleScope handleScope(m_isolate);
    for (WeakPersistentSet::iterator i = m_wrappers.begin(); i != m_wrappers.end(); ++i) {
        v8::Local<v8::Object> wrapper = (*i)->newLocal(m_isolate);
        if (!wrapper.IsEmpty()) {
            wrapper->DeleteHiddenValue(resolverName());
            wrapper->DeleteHiddenValue(promiseName());
        }
    }
    m_wrappers.clear();
}
コード例 #2
0
void ScriptPromisePropertyBase::clearWrappers()
{
    checkThis();
    checkWrappers();
    v8::HandleScope handleScope(m_isolate);
    for (WeakPersistentSet::iterator i = m_wrappers.begin(); i != m_wrappers.end(); ++i) {
        v8::Local<v8::Object> wrapper = (*i)->newLocal(m_isolate);
        if (!wrapper.IsEmpty()) {
            ScriptState* scriptState = ScriptState::from(wrapper->CreationContext());
            V8HiddenValue::deleteHiddenValue(scriptState, wrapper, resolverName());
            V8HiddenValue::deleteHiddenValue(scriptState, wrapper, promiseName());
        }
    }
    m_wrappers.clear();
}
コード例 #3
0
ScriptPromise ScriptPromisePropertyBase::promise(DOMWrapperWorld& world)
{
    if (!getExecutionContext())
        return ScriptPromise();

    v8::HandleScope handleScope(m_isolate);
    v8::Local<v8::Context> context = toV8Context(getExecutionContext(), world);
    if (context.IsEmpty())
        return ScriptPromise();
    ScriptState* scriptState = ScriptState::from(context);
    ScriptState::Scope scope(scriptState);

    v8::Local<v8::Object> wrapper = ensureHolderWrapper(scriptState);
    ASSERT(wrapper->CreationContext() == context);

    v8::Local<v8::Value> cachedPromise = V8HiddenValue::getHiddenValue(scriptState, wrapper, promiseName());
    if (!cachedPromise.IsEmpty() && cachedPromise->IsPromise())
        return ScriptPromise(scriptState, cachedPromise);

    // Create and cache the Promise
    v8::Local<v8::Promise::Resolver> resolver;
    if (!v8::Promise::Resolver::New(context).ToLocal(&resolver))
        return ScriptPromise();
    v8::Local<v8::Promise> promise = resolver->GetPromise();
    V8HiddenValue::setHiddenValue(scriptState, wrapper, promiseName(), promise);

    switch (m_state) {
    case Pending:
        // Cache the resolver too
        V8HiddenValue::setHiddenValue(scriptState, wrapper, resolverName(), resolver);
        break;
    case Resolved:
    case Rejected:
        resolveOrRejectInternal(resolver);
        break;
    }

    return ScriptPromise(scriptState, promise);
}