コード例 #1
0
JSC::JSValue JSMediaStreamTrack::getSettings(ExecState& state)
{
    JSValue thisValue = state.thisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (UNLIKELY(!castedThis))
        return JSValue::decode(throwThisTypeError(state, "MediaStreamTrack", "getSettings"));

    JSObject* object = constructEmptyObject(&state);
    auto& impl = castedThis->wrapped();
    RefPtr<MediaSourceSettings> settings = WTF::getPtr(impl.getSettings());

    if (settings->supportsWidth())
        object->putDirect(state.vm(), Identifier::fromString(&state, "width"), jsNumber(settings->width()), DontDelete | ReadOnly);
    if (settings->supportsHeight())
        object->putDirect(state.vm(), Identifier::fromString(&state, "height"), jsNumber(settings->height()), DontDelete | ReadOnly);
    if (settings->supportsAspectRatio())
        object->putDirect(state.vm(), Identifier::fromString(&state, "aspectRatio"), jsDoubleNumber(settings->aspectRatio()), DontDelete | ReadOnly);
    if (settings->supportsFrameRate())
        object->putDirect(state.vm(), Identifier::fromString(&state, "frameRate"), jsDoubleNumber(settings->frameRate()), DontDelete | ReadOnly);
    if (settings->supportsFacingMode())
        object->putDirect(state.vm(), Identifier::fromString(&state, "facingMode"), jsStringWithCache(&state, settings->facingMode()), DontDelete | ReadOnly);
    if (settings->supportsVolume())
        object->putDirect(state.vm(), Identifier::fromString(&state, "volume"), jsDoubleNumber(settings->volume()), DontDelete | ReadOnly);
    if (settings->supportsSampleRate())
        object->putDirect(state.vm(), Identifier::fromString(&state, "sampleRate"), jsNumber(settings->sampleRate()), DontDelete | ReadOnly);
    if (settings->supportsSampleSize())
        object->putDirect(state.vm(), Identifier::fromString(&state, "sampleSize"), jsNumber(settings->sampleSize()), DontDelete | ReadOnly);
    if (settings->supportsEchoCancellation())
        object->putDirect(state.vm(), Identifier::fromString(&state, "echoCancellation"), jsBoolean(settings->echoCancellation()), DontDelete | ReadOnly);
    if (settings->supportsDeviceId())
        object->putDirect(state.vm(), Identifier::fromString(&state, "deviceId"), jsStringWithCache(&state, settings->deviceId()), DontDelete | ReadOnly);
    if (settings->supportsGroupId())
        object->putDirect(state.vm(), Identifier::fromString(&state, "groupId"), jsStringWithCache(&state, settings->groupId()), DontDelete | ReadOnly);
    
    return object;
}
コード例 #2
0
EncodedJSValue JSC_HOST_CALL constructJSHTMLElement(ExecState& exec)
{
    VM& vm = exec.vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    auto* jsConstructor = jsCast<JSDOMConstructorBase*>(exec.jsCallee());
    ASSERT(jsConstructor);

    auto* context = jsConstructor->scriptExecutionContext();
    if (!context)
        return throwConstructorScriptExecutionContextUnavailableError(exec, scope, "HTMLElement");
    ASSERT(context->isDocument());

    JSValue newTargetValue = exec.thisValue();
    auto* newTarget = newTargetValue.getObject();
    auto* globalObject = jsCast<JSDOMGlobalObject*>(newTarget->globalObject(vm));
    JSValue htmlElementConstructorValue = JSHTMLElement::getConstructor(vm, globalObject);
    if (newTargetValue == htmlElementConstructorValue)
        return throwVMTypeError(&exec, scope, "new.target is not a valid custom element constructor"_s);

    auto& document = downcast<Document>(*context);

    auto* window = document.domWindow();
    if (!window)
        return throwVMTypeError(&exec, scope, "new.target is not a valid custom element constructor"_s);

    auto* registry = window->customElementRegistry();
    if (!registry)
        return throwVMTypeError(&exec, scope, "new.target is not a valid custom element constructor"_s);

    auto* elementInterface = registry->findInterface(newTarget);
    if (!elementInterface)
        return throwVMTypeError(&exec, scope, "new.target does not define a custom element"_s);

    if (!elementInterface->isUpgradingElement()) {
        Structure* baseStructure = getDOMStructure<JSHTMLElement>(vm, *globalObject);
        auto* newElementStructure = InternalFunction::createSubclassStructure(&exec, newTargetValue, baseStructure);
        RETURN_IF_EXCEPTION(scope, encodedJSValue());

        Ref<HTMLElement> element = HTMLElement::create(elementInterface->name(), document);
        element->setIsDefinedCustomElement(*elementInterface);
        auto* jsElement = JSHTMLElement::create(newElementStructure, globalObject, element.get());
        cacheWrapper(globalObject->world(), element.ptr(), jsElement);
        return JSValue::encode(jsElement);
    }

    Element* elementToUpgrade = elementInterface->lastElementInConstructionStack();
    if (!elementToUpgrade) {
        throwInvalidStateError(exec, scope, "Cannot instantiate a custom element inside its own constructor during upgrades"_s);
        return JSValue::encode(jsUndefined());
    }

    JSValue elementWrapperValue = toJS(&exec, jsConstructor->globalObject(), *elementToUpgrade);
    ASSERT(elementWrapperValue.isObject());

    JSValue newPrototype = newTarget->get(&exec, vm.propertyNames->prototype);
    RETURN_IF_EXCEPTION(scope, encodedJSValue());

    JSObject* elementWrapperObject = asObject(elementWrapperValue);
    JSObject::setPrototype(elementWrapperObject, &exec, newPrototype, true /* shouldThrowIfCantSet */);
    RETURN_IF_EXCEPTION(scope, encodedJSValue());

    elementInterface->didUpgradeLastElementInConstructionStack();

    return JSValue::encode(elementWrapperValue);
}