bool ReadableStreamOperations::isReadableStreamReader(ScriptState* scriptState, ScriptValue value)
{
    ASSERT(!value.isEmpty());

    if (!value.isObject())
        return false;

    v8::Local<v8::Value> args[] = { value.v8Value() };
    return V8ScriptRunner::callExtraOrCrash(scriptState, "IsReadableStreamReader", args)->ToBoolean()->Value();
}
ScriptObject InjectedScriptCanvasModule::callWrapContextFunction(const String& functionName, const ScriptObject& context)
{
    ScriptFunctionCall function(injectedScriptObject(), functionName);
    function.appendArgument(context);
    bool hadException = false;
    ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException);
    if (hadException || resultValue.hasNoValue() || !resultValue.isObject()) {
        ASSERT_NOT_REACHED();
        return ScriptObject();
    }
    return ScriptObject(context.scriptState(), resultValue);
}
Example #3
0
void DevToolsHost::showContextMenu(LocalFrame* targetFrame, float x, float y, const Vector<ContextMenuItem>& items)
{
    ASSERT(m_frontendFrame);
    ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendFrame);
    ScriptValue devtoolsApiObject = frontendScriptState->getFromGlobalObject("DevToolsAPI");
    ASSERT(devtoolsApiObject.isObject());

    RefPtrWillBeRawPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider::create(this, devtoolsApiObject, items);
    m_menuProvider = menuProvider.get();
    float zoom = targetFrame->pageZoomFactor();
    if (m_client)
        m_client->showContextMenu(targetFrame, x * zoom, y * zoom, menuProvider);
}
ScriptValue InjectedScript::findCallFrameById(ErrorString* errorString, const ScriptValue& topCallFrame, const String& callFrameId)
{
    ScriptFunctionCall function(injectedScriptObject(), "callFrameForId");
    function.appendArgument(topCallFrame);
    function.appendArgument(callFrameId);
    bool hadException = false;
    ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException);
    ASSERT(!hadException);
    if (hadException || resultValue.hasNoValue() || !resultValue.isObject()) {
        *errorString = "Internal error";
        return ScriptValue();
    }
    return resultValue;
}
Example #5
0
void DevToolsHost::showContextMenu(Event* event, const Vector<ContextMenuItem>& items)
{
    if (!event)
        return;

    ASSERT(m_frontendFrame);
    ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendFrame);
    ScriptValue devtoolsApiObject = frontendScriptState->getFromGlobalObject("DevToolsAPI");
    ASSERT(devtoolsApiObject.isObject());

    Page* targetPage = m_frontendFrame->page();
    if (event->target() && event->target()->executionContext() && event->target()->executionContext()->executingWindow()) {
        LocalDOMWindow* window = event->target()->executionContext()->executingWindow();
        if (window->document() && window->document()->page())
            targetPage = window->document()->page();
    }

    RefPtrWillBeRawPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider::create(this, devtoolsApiObject, items);
    targetPage->contextMenuController().showContextMenu(event, menuProvider);
    m_menuProvider = menuProvider.get();
}
void V8TestDictionary::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, TestDictionary& impl, ExceptionState& exceptionState)
{
    if (isUndefinedOrNull(v8Value))
        return;
    if (!v8Value->IsObject()) {
        exceptionState.throwTypeError("cannot convert to dictionary.");
        return;
    }

    // FIXME: Do not use Dictionary and DictionaryHelper
    // https://crbug.com/321462
    Dictionary dictionary(v8Value, isolate);
    // FIXME: Remove this v8::TryCatch once the code is switched from
    // Dictionary/DictionaryHelper to something that uses ExceptionState.
    v8::TryCatch block;
    bool booleanMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "booleanMember", booleanMember)) {
        impl.setBooleanMember(booleanMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    bool create;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "create", create)) {
        impl.setCreateMember(create);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    double doubleOrNullMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "doubleOrNullMember", doubleOrNullMember)) {
        impl.setDoubleOrNullMember(doubleOrNullMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    RefPtrWillBeRawPtr<Element> elementOrNullMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "elementOrNullMember", elementOrNullMember)) {
        impl.setElementOrNullMember(elementOrNullMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    String enumMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "enumMember", enumMember)) {
        String string = enumMember;
        if (!(string == "foo" || string == "bar" || string == "baz")) {
            exceptionState.throwTypeError("member enumMember ('" + string + "') is not a valid enum value.");
            return;
        }
        impl.setEnumMember(enumMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    int longMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "longMember", longMember)) {
        impl.setLongMember(longMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    ScriptValue objectMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "objectMember", objectMember)) {
        if (!objectMember.isObject()) {
            exceptionState.throwTypeError("member objectMember is not an object.");
            return;
        }
        impl.setObjectMember(objectMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    ScriptValue objectOrNullMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "objectOrNullMember", objectOrNullMember)) {
        if (!objectOrNullMember.isObject()) {
            exceptionState.throwTypeError("member objectOrNullMember is not an object.");
            return;
        }
        impl.setObjectOrNullMember(objectOrNullMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    Vector<String> stringArrayMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "stringArrayMember", stringArrayMember)) {
        impl.setStringArrayMember(stringArrayMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    String stringMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "stringMember", stringMember)) {
        impl.setStringMember(stringMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    String stringOrNullMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "stringOrNullMember", stringOrNullMember)) {
        impl.setStringOrNullMember(stringOrNullMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    Vector<String> stringSequenceMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "stringSequenceMember", stringSequenceMember)) {
        impl.setStringSequenceMember(stringSequenceMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    RawPtr<TestInterfaceGarbageCollected> testInterfaceGarbageCollectedMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceGarbageCollectedMember", testInterfaceGarbageCollectedMember)) {
        impl.setTestInterfaceGarbageCollectedMember(testInterfaceGarbageCollectedMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    RawPtr<TestInterfaceGarbageCollected> testInterfaceGarbageCollectedOrNullMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceGarbageCollectedOrNullMember", testInterfaceGarbageCollectedOrNullMember)) {
        impl.setTestInterfaceGarbageCollectedOrNullMember(testInterfaceGarbageCollectedOrNullMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    RefPtr<TestInterfaceImplementation> testInterfaceMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceMember", testInterfaceMember)) {
        impl.setTestInterfaceMember(testInterfaceMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    RefPtr<TestInterfaceImplementation> testInterfaceOrNullMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceOrNullMember", testInterfaceOrNullMember)) {
        impl.setTestInterfaceOrNullMember(testInterfaceOrNullMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> testInterfaceWillBeGarbageCollectedMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceWillBeGarbageCollectedMember", testInterfaceWillBeGarbageCollectedMember)) {
        impl.setTestInterfaceWillBeGarbageCollectedMember(testInterfaceWillBeGarbageCollectedMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

    RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> testInterfaceWillBeGarbageCollectedOrNullMember;
    if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceWillBeGarbageCollectedOrNullMember", testInterfaceWillBeGarbageCollectedOrNullMember)) {
        impl.setTestInterfaceWillBeGarbageCollectedOrNullMember(testInterfaceWillBeGarbageCollectedOrNullMember);
    } else if (block.HasCaught()) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }

}
Example #7
0
bool CustomElementConstructorBuilder::validateOptions(const AtomicString& type, QualifiedName& tagName, ExceptionState& exceptionState)
{
    ASSERT(m_prototype.IsEmpty());

    v8::TryCatch tryCatch;

    ScriptValue prototypeScriptValue;
    if (m_options->get("prototype", prototypeScriptValue) && !prototypeScriptValue.isNull()) {
        ASSERT(!tryCatch.HasCaught());
        if (!prototypeScriptValue.isObject()) {
            CustomElementException::throwException(CustomElementException::PrototypeNotAnObject, type, exceptionState);
            tryCatch.ReThrow();
            return false;
        }
        m_prototype = prototypeScriptValue.v8Value().As<v8::Object>();
    } else if (!tryCatch.HasCaught()) {
        m_prototype = v8::Object::New(m_scriptState->isolate());
        v8::Local<v8::Object> basePrototype = m_scriptState->perContextData()->prototypeForType(&V8HTMLElement::wrapperTypeInfo);
        if (!basePrototype.IsEmpty())
            m_prototype->SetPrototype(basePrototype);
    }

    if (tryCatch.HasCaught()) {
        tryCatch.ReThrow();
        return false;
    }

    AtomicString extends;
    bool extendsProvidedAndNonNull = m_options->get("extends", extends);

    if (tryCatch.HasCaught()) {
        tryCatch.ReThrow();
        return false;
    }

    if (!m_scriptState->perContextData()) {
        // FIXME: This should generate an InvalidContext exception at a later point.
        CustomElementException::throwException(CustomElementException::ContextDestroyedCheckingPrototype, type, exceptionState);
        tryCatch.ReThrow();
        return false;
    }

    AtomicString namespaceURI = HTMLNames::xhtmlNamespaceURI;
    if (hasValidPrototypeChainFor(&V8SVGElement::wrapperTypeInfo))
        namespaceURI = SVGNames::svgNamespaceURI;

    ASSERT(!tryCatch.HasCaught());

    AtomicString localName;

    if (extendsProvidedAndNonNull) {
        localName = extends.lower();

        if (!Document::isValidName(localName)) {
            CustomElementException::throwException(CustomElementException::ExtendsIsInvalidName, type, exceptionState);
            tryCatch.ReThrow();
            return false;
        }
        if (CustomElement::isValidName(localName)) {
            CustomElementException::throwException(CustomElementException::ExtendsIsCustomElementName, type, exceptionState);
            tryCatch.ReThrow();
            return false;
        }
    } else {
        if (namespaceURI == SVGNames::svgNamespaceURI) {
            CustomElementException::throwException(CustomElementException::ExtendsIsInvalidName, type, exceptionState);
            tryCatch.ReThrow();
            return false;
        }
        localName = type;
    }

    if (!extendsProvidedAndNonNull)
        m_wrapperType = &V8HTMLElement::wrapperTypeInfo;
    else if (namespaceURI == HTMLNames::xhtmlNamespaceURI)
        m_wrapperType = findWrapperTypeForHTMLTagName(localName);
    else
        m_wrapperType = findWrapperTypeForSVGTagName(localName);

    ASSERT(!tryCatch.HasCaught());
    ASSERT(m_wrapperType);
    tagName = QualifiedName(nullAtom, localName, namespaceURI);
    return m_wrapperType;
}