| /* |
| This file is part of the WebKit open source project. |
| This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
| |
| This library is free software; you can redistribute it and/or |
| modify it under the terms of the GNU Library General Public |
| License as published by the Free Software Foundation; either |
| version 2 of the License, or (at your option) any later version. |
| |
| This library is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| Library General Public License for more details. |
| |
| You should have received a copy of the GNU Library General Public License |
| along with this library; see the file COPYING.LIB. If not, write to |
| the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| Boston, MA 02110-1301, USA. |
| */ |
| |
| #include "config.h" |
| |
| #if ENABLE(FETCH_API) |
| |
| #include "JSFetchResponse.h" |
| |
| #include "ExceptionCode.h" |
| #include "FetchResponse.h" |
| #include "FetchResponseBuiltins.h" |
| #include "JSDOMBinding.h" |
| #include "JSDOMConstructor.h" |
| #include "JSDOMConvert.h" |
| #include "JSDOMPromise.h" |
| #include "JSFetchHeaders.h" |
| #include "JSFetchResponse.h" |
| #include "JSReadableStreamSource.h" |
| #include "ReadableStreamSource.h" |
| #include "URL.h" |
| #include "WebCoreJSClientData.h" |
| #include <runtime/Error.h> |
| #include <runtime/FunctionPrototype.h> |
| #include <runtime/JSString.h> |
| #include <wtf/GetPtr.h> |
| |
| using namespace JSC; |
| |
| namespace WebCore { |
| |
| template<typename T> Optional<T> parse(ExecState&, JSValue); |
| template<typename T> const char* expectedEnumerationValues(); |
| |
| JSString* jsStringWithCache(ExecState*, FetchResponse::Type); |
| |
| JSString* jsStringWithCache(ExecState* state, FetchResponse::Type enumerationValue) |
| { |
| static NeverDestroyed<const String> values[] = { |
| ASCIILiteral("basic"), |
| ASCIILiteral("cors"), |
| ASCIILiteral("default"), |
| ASCIILiteral("error"), |
| ASCIILiteral("opaque"), |
| ASCIILiteral("opaqueredirect"), |
| }; |
| static_assert(static_cast<size_t>(FetchResponse::Type::Basic) == 0, "FetchResponse::Type::Basic is not 0 as expected"); |
| static_assert(static_cast<size_t>(FetchResponse::Type::Cors) == 1, "FetchResponse::Type::Cors is not 1 as expected"); |
| static_assert(static_cast<size_t>(FetchResponse::Type::Default) == 2, "FetchResponse::Type::Default is not 2 as expected"); |
| static_assert(static_cast<size_t>(FetchResponse::Type::Error) == 3, "FetchResponse::Type::Error is not 3 as expected"); |
| static_assert(static_cast<size_t>(FetchResponse::Type::Opaque) == 4, "FetchResponse::Type::Opaque is not 4 as expected"); |
| static_assert(static_cast<size_t>(FetchResponse::Type::Opaqueredirect) == 5, "FetchResponse::Type::Opaqueredirect is not 5 as expected"); |
| ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| return jsStringWithCache(state, values[static_cast<size_t>(enumerationValue)]); |
| } |
| |
| template<> struct JSValueTraits<FetchResponse::Type> { |
| static JSString* arrayJSValue(ExecState* state, JSDOMGlobalObject*, FetchResponse::Type value) { return jsStringWithCache(state, value); } |
| }; |
| |
| template<> Optional<FetchResponse::Type> parse<FetchResponse::Type>(ExecState& state, JSValue value) |
| { |
| auto stringValue = value.toWTFString(&state); |
| if (stringValue == "basic") |
| return FetchResponse::Type::Basic; |
| if (stringValue == "cors") |
| return FetchResponse::Type::Cors; |
| if (stringValue == "default") |
| return FetchResponse::Type::Default; |
| if (stringValue == "error") |
| return FetchResponse::Type::Error; |
| if (stringValue == "opaque") |
| return FetchResponse::Type::Opaque; |
| if (stringValue == "opaqueredirect") |
| return FetchResponse::Type::Opaqueredirect; |
| return Nullopt; |
| } |
| |
| template<> FetchResponse::Type convert<FetchResponse::Type>(ExecState& state, JSValue value) |
| { |
| VM& vm = state.vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| auto result = parse<FetchResponse::Type>(state, value); |
| if (UNLIKELY(!result)) { |
| throwTypeError(&state, throwScope); |
| return { }; |
| } |
| return result.value(); |
| } |
| |
| template<> inline const char* expectedEnumerationValues<FetchResponse::Type>() |
| { |
| return "\"basic\", \"cors\", \"default\", \"error\", \"opaque\", \"opaqueredirect\""; |
| } |
| |
| // Functions |
| |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponseConstructorFunctionError(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponseConstructorFunctionRedirect(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionCloneForJS(JSC::ExecState*); |
| #if ENABLE(READABLE_STREAM_API) |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionStartConsumingStream(JSC::ExecState*); |
| #endif |
| #if ENABLE(READABLE_STREAM_API) |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionConsumeChunk(JSC::ExecState*); |
| #endif |
| #if ENABLE(READABLE_STREAM_API) |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionFinishConsumingStream(JSC::ExecState*); |
| #endif |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionConsume(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionIsLoading(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionSetStatus(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionInitializeWith(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionCreateReadableStreamSource(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionIsDisturbed(JSC::ExecState*); |
| |
| // Attributes |
| |
| JSC::EncodedJSValue jsFetchResponseType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsFetchResponseUrl(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsFetchResponseRedirected(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsFetchResponseStatus(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsFetchResponseOk(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsFetchResponseStatusText(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsFetchResponseHeaders(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsFetchResponseConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSFetchResponseConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| |
| class JSFetchResponsePrototype : public JSC::JSNonFinalObject { |
| public: |
| typedef JSC::JSNonFinalObject Base; |
| static JSFetchResponsePrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) |
| { |
| JSFetchResponsePrototype* ptr = new (NotNull, JSC::allocateCell<JSFetchResponsePrototype>(vm.heap)) JSFetchResponsePrototype(vm, globalObject, structure); |
| ptr->finishCreation(vm); |
| return ptr; |
| } |
| |
| DECLARE_INFO; |
| static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| { |
| return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| } |
| |
| private: |
| JSFetchResponsePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| : JSC::JSNonFinalObject(vm, structure) |
| { |
| } |
| |
| void finishCreation(JSC::VM&); |
| }; |
| |
| typedef JSBuiltinConstructor<JSFetchResponse> JSFetchResponseConstructor; |
| |
| /* Hash table for constructor */ |
| |
| static const HashTableValue JSFetchResponseConstructorTableValues[] = |
| { |
| { "error", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsFetchResponseConstructorFunctionError), (intptr_t) (0) } }, |
| { "redirect", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsFetchResponseConstructorFunctionRedirect), (intptr_t) (1) } }, |
| }; |
| |
| template<> JSValue JSFetchResponseConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| { |
| UNUSED_PARAM(vm); |
| return globalObject.functionPrototype(); |
| } |
| |
| template<> void JSFetchResponseConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| { |
| putDirect(vm, vm.propertyNames->prototype, JSFetchResponse::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("Response"))), ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum); |
| reifyStaticProperties(vm, JSFetchResponseConstructorTableValues, *this); |
| } |
| |
| template<> FunctionExecutable* JSFetchResponseConstructor::initializeExecutable(VM& vm) |
| { |
| return fetchResponseInitializeFetchResponseCodeGenerator(vm); |
| } |
| |
| template<> const ClassInfo JSFetchResponseConstructor::s_info = { "Response", &Base::s_info, 0, CREATE_METHOD_TABLE(JSFetchResponseConstructor) }; |
| |
| /* Hash table for prototype */ |
| |
| static const HashTableValue JSFetchResponsePrototypeTableValues[] = |
| { |
| { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchResponseConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFetchResponseConstructor) } }, |
| { "type", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchResponseType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "url", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchResponseUrl), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "redirected", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchResponseRedirected), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "status", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchResponseStatus), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "ok", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchResponseOk), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "statusText", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchResponseStatusText), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "headers", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchResponseHeaders), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "body", ReadOnly | Accessor | Builtin, NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(fetchResponseBodyCodeGenerator), (intptr_t) (0) } }, |
| { "bodyUsed", ReadOnly | Accessor | Builtin, NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(fetchResponseBodyUsedCodeGenerator), (intptr_t) (0) } }, |
| { "arrayBuffer", JSC::Builtin, NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(fetchResponseArrayBufferCodeGenerator), (intptr_t) (0) } }, |
| { "blob", JSC::Builtin, NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(fetchResponseBlobCodeGenerator), (intptr_t) (0) } }, |
| { "formData", JSC::Builtin, NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(fetchResponseFormDataCodeGenerator), (intptr_t) (0) } }, |
| { "json", JSC::Builtin, NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(fetchResponseJsonCodeGenerator), (intptr_t) (0) } }, |
| { "text", JSC::Builtin, NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(fetchResponseTextCodeGenerator), (intptr_t) (0) } }, |
| { "clone", JSC::Builtin, NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(fetchResponseCloneCodeGenerator), (intptr_t) (0) } }, |
| }; |
| |
| const ClassInfo JSFetchResponsePrototype::s_info = { "ResponsePrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSFetchResponsePrototype) }; |
| |
| void JSFetchResponsePrototype::finishCreation(VM& vm) |
| { |
| Base::finishCreation(vm); |
| reifyStaticProperties(vm, JSFetchResponsePrototypeTableValues, *this); |
| JSVMClientData& clientData = *static_cast<JSVMClientData*>(vm.clientData); |
| putDirect(vm, clientData.builtinNames().cloneForJSPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionCloneForJS), ReadOnly | DontEnum); |
| putDirect(vm, clientData.builtinNames().startConsumingStreamPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionStartConsumingStream), ReadOnly | DontEnum); |
| putDirect(vm, clientData.builtinNames().consumeChunkPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionConsumeChunk), ReadOnly | DontEnum); |
| putDirect(vm, clientData.builtinNames().finishConsumingStreamPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionFinishConsumingStream), ReadOnly | DontEnum); |
| putDirect(vm, clientData.builtinNames().consumePrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionConsume), ReadOnly | DontEnum); |
| putDirect(vm, clientData.builtinNames().isLoadingPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionIsLoading), ReadOnly | DontEnum); |
| putDirect(vm, clientData.builtinNames().setStatusPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionSetStatus), ReadOnly | DontEnum); |
| putDirect(vm, clientData.builtinNames().initializeWithPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionInitializeWith), ReadOnly | DontEnum); |
| putDirect(vm, clientData.builtinNames().createReadableStreamSourcePrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionCreateReadableStreamSource), ReadOnly | DontEnum); |
| putDirect(vm, clientData.builtinNames().isDisturbedPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsFetchResponsePrototypeFunctionIsDisturbed), ReadOnly | DontEnum); |
| } |
| |
| const ClassInfo JSFetchResponse::s_info = { "Response", &Base::s_info, 0, CREATE_METHOD_TABLE(JSFetchResponse) }; |
| |
| JSFetchResponse::JSFetchResponse(Structure* structure, JSDOMGlobalObject& globalObject, Ref<FetchResponse>&& impl) |
| : JSDOMWrapper<FetchResponse>(structure, globalObject, WTFMove(impl)) |
| { |
| } |
| |
| JSObject* JSFetchResponse::createPrototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return JSFetchResponsePrototype::create(vm, globalObject, JSFetchResponsePrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); |
| } |
| |
| JSObject* JSFetchResponse::prototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return getDOMPrototype<JSFetchResponse>(vm, globalObject); |
| } |
| |
| void JSFetchResponse::destroy(JSC::JSCell* cell) |
| { |
| JSFetchResponse* thisObject = static_cast<JSFetchResponse*>(cell); |
| thisObject->JSFetchResponse::~JSFetchResponse(); |
| } |
| |
| EncodedJSValue jsFetchResponseType(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSFetchResponse*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Response", "type"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.type()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsFetchResponseUrl(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSFetchResponse*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Response", "url"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.url()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsFetchResponseRedirected(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSFetchResponse*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Response", "redirected"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.redirected()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsFetchResponseStatus(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSFetchResponse*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Response", "status"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsNumber(impl.status()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsFetchResponseOk(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSFetchResponse*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Response", "ok"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.ok()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsFetchResponseStatusText(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSFetchResponse*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Response", "statusText"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.statusText()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsFetchResponseHeaders(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSFetchResponse*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Response", "headers"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.headers()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsFetchResponseConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSFetchResponsePrototype* domObject = jsDynamicCast<JSFetchResponsePrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) |
| return throwVMTypeError(state, throwScope); |
| return JSValue::encode(JSFetchResponse::getConstructor(state->vm(), domObject->globalObject())); |
| } |
| |
| bool setJSFetchResponseConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSValue value = JSValue::decode(encodedValue); |
| JSFetchResponsePrototype* domObject = jsDynamicCast<JSFetchResponsePrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) { |
| throwVMTypeError(state, throwScope); |
| return false; |
| } |
| // Shadowing a built-in constructor |
| return domObject->putDirect(state->vm(), state->propertyNames().constructor, value); |
| } |
| |
| JSValue JSFetchResponse::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| { |
| return getDOMConstructor<JSFetchResponseConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponseConstructorFunctionError(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| if (!context) |
| return JSValue::encode(jsUndefined()); |
| JSValue result = toJSNewlyCreated(state, jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject()), FetchResponse::error(*context)); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponseConstructorFunctionRedirect(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCode ec = 0; |
| auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| if (!context) |
| return JSValue::encode(jsUndefined()); |
| auto url = state->uncheckedArgument(0).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto status = state->argument(1).isUndefined() ? 302 : convert<uint16_t>(*state, state->uncheckedArgument(1), NormalConversion); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| JSValue result = toJSNewlyCreated(state, jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject()), FetchResponse::redirect(*context, WTFMove(url), WTFMove(status), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionCloneForJS(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "cloneForJS"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJSNewlyCreated(state, castedThis->globalObject(), impl.cloneForJS()); |
| return JSValue::encode(result); |
| } |
| |
| #if ENABLE(READABLE_STREAM_API) |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionStartConsumingStream(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "startConsumingStream"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| auto type = convert<uint16_t>(*state, state->uncheckedArgument(0), NormalConversion); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| impl.startConsumingStream(WTFMove(type)); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| #endif |
| |
| #if ENABLE(READABLE_STREAM_API) |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionConsumeChunk(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "consumeChunk"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| auto chunk = toUint8Array(state->uncheckedArgument(0)); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| if (UNLIKELY(!chunk)) |
| return throwArgumentTypeError(*state, throwScope, 0, "chunk", "Response", "consumeChunk", "Uint8Array"); |
| impl.consumeChunk(chunk.releaseNonNull()); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| #endif |
| |
| #if ENABLE(READABLE_STREAM_API) |
| static EncodedJSValue jsFetchResponsePrototypeFunctionFinishConsumingStreamPromise(ExecState*, Ref<DeferredPromise>&&); |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionFinishConsumingStream(ExecState* state) |
| { |
| ASSERT(state); |
| return JSValue::encode(callPromiseFunction<jsFetchResponsePrototypeFunctionFinishConsumingStreamPromise, PromiseExecutionScope::WindowOrWorker>(*state)); |
| } |
| |
| static inline EncodedJSValue jsFetchResponsePrototypeFunctionFinishConsumingStreamPromise(ExecState* state, Ref<DeferredPromise>&& promise) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "finishConsumingStream"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| impl.finishConsumingStream(WTFMove(promise)); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| #endif |
| |
| static EncodedJSValue jsFetchResponsePrototypeFunctionConsumePromise(ExecState*, Ref<DeferredPromise>&&); |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionConsume(ExecState* state) |
| { |
| ASSERT(state); |
| return JSValue::encode(callPromiseFunction<jsFetchResponsePrototypeFunctionConsumePromise, PromiseExecutionScope::WindowOrWorker>(*state)); |
| } |
| |
| static inline EncodedJSValue jsFetchResponsePrototypeFunctionConsumePromise(ExecState* state, Ref<DeferredPromise>&& promise) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "consume"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| auto type = convert<uint16_t>(*state, state->uncheckedArgument(0), NormalConversion); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| impl.consume(WTFMove(type), WTFMove(promise)); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionIsLoading(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "isLoading"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.isLoading()); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionSetStatus(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "setStatus"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 2)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCode ec = 0; |
| auto status = convert<uint16_t>(*state, state->uncheckedArgument(0), NormalConversion); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto statusText = state->uncheckedArgument(1).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| impl.setStatus(WTFMove(status), WTFMove(statusText), ec); |
| setDOMException(state, throwScope, ec); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionInitializeWith(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "initializeWith"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| auto body = state->uncheckedArgument(0); |
| impl.initializeWith(*state, WTFMove(body)); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionCreateReadableStreamSource(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "createReadableStreamSource"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJSNewlyCreated(state, castedThis->globalObject(), impl.createReadableStreamSource()); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsFetchResponsePrototypeFunctionIsDisturbed(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSFetchResponse*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Response", "isDisturbed"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSFetchResponse::info()); |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.isDisturbed()); |
| return JSValue::encode(result); |
| } |
| |
| void JSFetchResponse::visitChildren(JSCell* cell, SlotVisitor& visitor) |
| { |
| auto* thisObject = jsCast<JSFetchResponse*>(cell); |
| ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
| Base::visitChildren(thisObject, visitor); |
| } |
| |
| bool JSFetchResponseOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor) |
| { |
| auto* jsFetchResponse = jsCast<JSFetchResponse*>(handle.slot()->asCell()); |
| if (jsFetchResponse->wrapped().hasPendingActivity()) |
| return true; |
| UNUSED_PARAM(visitor); |
| return false; |
| } |
| |
| void JSFetchResponseOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| { |
| auto* jsFetchResponse = jsCast<JSFetchResponse*>(handle.slot()->asCell()); |
| auto& world = *static_cast<DOMWrapperWorld*>(context); |
| uncacheWrapper(world, &jsFetchResponse->wrapped(), jsFetchResponse); |
| } |
| |
| #if ENABLE(BINDING_INTEGRITY) |
| #if PLATFORM(WIN) |
| #pragma warning(disable: 4483) |
| extern "C" { extern void (*const __identifier("??_7FetchResponse@WebCore@@6B@")[])(); } |
| #else |
| extern "C" { extern void* _ZTVN7WebCore13FetchResponseE[]; } |
| #endif |
| #endif |
| |
| JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<FetchResponse>&& impl) |
| { |
| |
| #if ENABLE(BINDING_INTEGRITY) |
| void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
| #if PLATFORM(WIN) |
| void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7FetchResponse@WebCore@@6B@")); |
| #else |
| void* expectedVTablePointer = &_ZTVN7WebCore13FetchResponseE[2]; |
| #if COMPILER(CLANG) |
| // If this fails FetchResponse does not have a vtable, so you need to add the |
| // ImplementationLacksVTable attribute to the interface definition |
| static_assert(__is_polymorphic(FetchResponse), "FetchResponse is not polymorphic"); |
| #endif |
| #endif |
| // If you hit this assertion you either have a use after free bug, or |
| // FetchResponse has subclasses. If FetchResponse has subclasses that get passed |
| // to toJS() we currently require FetchResponse you to opt out of binding hardening |
| // by adding the SkipVTableValidation attribute to the interface IDL definition |
| RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
| #endif |
| return createWrapper<FetchResponse>(globalObject, WTFMove(impl)); |
| } |
| |
| JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, FetchResponse& impl) |
| { |
| return wrap(state, globalObject, impl); |
| } |
| |
| FetchResponse* JSFetchResponse::toWrapped(JSC::JSValue value) |
| { |
| if (auto* wrapper = jsDynamicCast<JSFetchResponse*>(value)) |
| return &wrapper->wrapped(); |
| return nullptr; |
| } |
| |
| } |
| |
| #endif // ENABLE(FETCH_API) |