Ref<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy) { auto buffer = tryCreate(numElements, elementByteSize, policy); if (!buffer) CRASH(); return buffer.releaseNonNull(); }
Ref<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLength) { auto buffer = tryCreate(source, byteLength); if (!buffer) CRASH(); return buffer.releaseNonNull(); }
Ref<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize) { auto buffer = tryCreate(numElements, elementByteSize); if (!buffer) CRASH(); return buffer.releaseNonNull(); }
ExceptionOr<Ref<Float32Array>> AudioBuffer::getChannelData(unsigned channelIndex) { if (channelIndex >= m_channels.size()) return Exception { SYNTAX_ERR }; auto& channelData = *m_channels[channelIndex]; auto array = Float32Array::create(channelData.unsharedBuffer(), channelData.byteOffset(), channelData.length()); RELEASE_ASSERT(array); return array.releaseNonNull(); }
static JSValue handlePostMessage(DOMWindow& impl, ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (UNLIKELY(state.argumentCount() < 2)) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); Vector<RefPtr<MessagePort>> messagePorts; Vector<RefPtr<JSC::ArrayBuffer>> arrayBuffers; // This function has variable arguments and can be: // Per current spec: // postMessage(message, targetOrigin) // postMessage(message, targetOrigin, {sequence of transferrables}) // Legacy non-standard implementations in webkit allowed: // postMessage(message, {sequence of transferrables}, targetOrigin); int targetOriginArgIndex = 1; if (state.argumentCount() > 2) { int transferablesArgIndex = 2; if (state.uncheckedArgument(2).isString()) { targetOriginArgIndex = 2; transferablesArgIndex = 1; } extractTransferables(state, state.argument(transferablesArgIndex), messagePorts, arrayBuffers); } RETURN_IF_EXCEPTION(scope, JSValue()); auto message = SerializedScriptValue::create(state, state.uncheckedArgument(0), messagePorts, WTFMove(arrayBuffers)); RETURN_IF_EXCEPTION(scope, JSValue()); String targetOrigin = convert<IDLNullable<IDLUSVString>>(state, state.uncheckedArgument(targetOriginArgIndex)); RETURN_IF_EXCEPTION(scope, JSValue()); propagateException(state, scope, impl.postMessage(message.releaseNonNull(), WTFMove(messagePorts), targetOrigin, callerDOMWindow(&state))); return jsUndefined(); }
EncodedJSValue JSC_HOST_CALL constructJSRTCPeerConnection(ExecState* exec) { // Spec says that we must have at least one arument, the RTCConfiguration. if (exec->argumentCount() < 1) return throwVMError(exec, createNotEnoughArgumentsError(exec)); ExceptionCode ec = 0; Dictionary rtcConfiguration(exec, exec->argument(0)); if (exec->hadException()) return JSValue::encode(jsUndefined()); if (!rtcConfiguration.isObject()) return throwVMError(exec, createTypeError(exec, "RTCPeerConnection argument must be a valid Dictionary")); DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee()); ScriptExecutionContext* scriptExecutionContext = jsConstructor->scriptExecutionContext(); if (!scriptExecutionContext) return throwVMError(exec, createReferenceError(exec, "RTCPeerConnection constructor associated document is unavailable")); auto peerConnection = RTCPeerConnection::create(*scriptExecutionContext, rtcConfiguration, ec); if (ec == TYPE_MISMATCH_ERR) { setDOMException(exec, ec); return throwVMError(exec, createTypeError(exec, "Invalid RTCPeerConnection constructor arguments")); } if (ec) { setDOMException(exec, ec); return throwVMError(exec, createTypeError(exec, "Error creating RTCPeerConnection")); } return JSValue::encode(CREATE_DOM_WRAPPER(jsConstructor->globalObject(), RTCPeerConnection, peerConnection.releaseNonNull())); }
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); }