ExceptionOr<Ref<FontFace>> FontFace::create(JSC::ExecState& state, Document& document, const String& family, JSC::JSValue source, const Descriptors& descriptors) { auto result = adoptRef(*new FontFace(document.fontSelector())); bool dataRequiresAsynchronousLoading = true; auto setFamilyResult = result->setFamily(family); if (setFamilyResult.hasException()) return setFamilyResult.releaseException(); if (source.isString()) { auto value = FontFace::parseString(source.getString(&state), CSSPropertySrc); if (!is<CSSValueList>(value.get())) return Exception { SYNTAX_ERR }; CSSFontFace::appendSources(result->backing(), downcast<CSSValueList>(*value), &document, false); } else if (auto arrayBufferView = toUnsharedArrayBufferView(source)) dataRequiresAsynchronousLoading = populateFontFaceWithArrayBuffer(result->backing(), arrayBufferView.releaseNonNull()); else if (auto arrayBuffer = toUnsharedArrayBuffer(source)) { auto arrayBufferView = JSC::Uint8Array::create(arrayBuffer, 0, arrayBuffer->byteLength()); dataRequiresAsynchronousLoading = populateFontFaceWithArrayBuffer(result->backing(), arrayBufferView.releaseNonNull()); } // These ternaries match the default strings inside the FontFaceDescriptors dictionary inside FontFace.idl. auto setStyleResult = result->setStyle(descriptors.style.isEmpty() ? ASCIILiteral("normal") : descriptors.style); if (setStyleResult.hasException()) return setStyleResult.releaseException(); auto setWeightResult = result->setWeight(descriptors.weight.isEmpty() ? ASCIILiteral("normal") : descriptors.weight); if (setWeightResult.hasException()) return setWeightResult.releaseException(); auto setStretchResult = result->setStretch(descriptors.stretch.isEmpty() ? ASCIILiteral("normal") : descriptors.stretch); if (setStretchResult.hasException()) return setStretchResult.releaseException(); auto setUnicodeRangeResult = result->setUnicodeRange(descriptors.unicodeRange.isEmpty() ? ASCIILiteral("U+0-10FFFF") : descriptors.unicodeRange); if (setUnicodeRangeResult.hasException()) return setUnicodeRangeResult.releaseException(); auto setVariantResult = result->setVariant(descriptors.variant.isEmpty() ? ASCIILiteral("normal") : descriptors.variant); if (setVariantResult.hasException()) return setVariantResult.releaseException(); auto setFeatureSettingsResult = result->setFeatureSettings(descriptors.featureSettings.isEmpty() ? ASCIILiteral("normal") : descriptors.featureSettings); if (setFeatureSettingsResult.hasException()) return setFeatureSettingsResult.releaseException(); if (!dataRequiresAsynchronousLoading) { result->backing().load(); ASSERT(result->backing().status() == CSSFontFace::Status::Success); } return WTFMove(result); }