| 1 | /* |
| 2 | This file is part of the WebKit open source project. |
| 3 | This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Library General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Library General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Library General Public License |
| 16 | along with this library; see the file COPYING.LIB. If not, write to |
| 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | |
| 23 | #if ENABLE(STREAMS_API) |
| 24 | |
| 25 | #include "JSWritableStream.h" |
| 26 | |
| 27 | #include "JSDOMAttribute.h" |
| 28 | #include "JSDOMBinding.h" |
| 29 | #include "JSDOMBuiltinConstructor.h" |
| 30 | #include "JSDOMExceptionHandling.h" |
| 31 | #include "JSDOMOperation.h" |
| 32 | #include "JSDOMWrapperCache.h" |
| 33 | #include "WritableStreamBuiltins.h" |
| 34 | #include <JavaScriptCore/FunctionPrototype.h> |
| 35 | #include <JavaScriptCore/JSCInlines.h> |
| 36 | #include <wtf/GetPtr.h> |
| 37 | #include <wtf/PointerPreparations.h> |
| 38 | |
| 39 | |
| 40 | namespace WebCore { |
| 41 | using namespace JSC; |
| 42 | |
| 43 | // Functions |
| 44 | |
| 45 | |
| 46 | // Attributes |
| 47 | |
| 48 | JSC::EncodedJSValue jsWritableStreamConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 49 | bool setJSWritableStreamConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 50 | |
| 51 | class JSWritableStreamPrototype : public JSC::JSNonFinalObject { |
| 52 | public: |
| 53 | using Base = JSC::JSNonFinalObject; |
| 54 | static JSWritableStreamPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 55 | { |
| 56 | JSWritableStreamPrototype* ptr = new (NotNull, JSC::allocateCell<JSWritableStreamPrototype>(vm.heap)) JSWritableStreamPrototype(vm, globalObject, structure); |
| 57 | ptr->finishCreation(vm); |
| 58 | return ptr; |
| 59 | } |
| 60 | |
| 61 | DECLARE_INFO; |
| 62 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 63 | { |
| 64 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 65 | } |
| 66 | |
| 67 | private: |
| 68 | JSWritableStreamPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 69 | : JSC::JSNonFinalObject(vm, structure) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | void finishCreation(JSC::VM&); |
| 74 | }; |
| 75 | |
| 76 | using JSWritableStreamConstructor = JSDOMBuiltinConstructor<JSWritableStream>; |
| 77 | |
| 78 | template<> JSValue JSWritableStreamConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 79 | { |
| 80 | UNUSED_PARAM(vm); |
| 81 | return globalObject.functionPrototype(); |
| 82 | } |
| 83 | |
| 84 | template<> void JSWritableStreamConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 85 | { |
| 86 | putDirect(vm, vm.propertyNames->prototype, JSWritableStream::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 87 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("WritableStream"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 88 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 89 | } |
| 90 | |
| 91 | template<> FunctionExecutable* JSWritableStreamConstructor::initializeExecutable(VM& vm) |
| 92 | { |
| 93 | return writableStreamInitializeWritableStreamCodeGenerator(vm); |
| 94 | } |
| 95 | |
| 96 | template<> const ClassInfo JSWritableStreamConstructor::s_info = { "WritableStream" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWritableStreamConstructor) }; |
| 97 | |
| 98 | /* Hash table for prototype */ |
| 99 | |
| 100 | static const HashTableValue JSWritableStreamPrototypeTableValues[] = |
| 101 | { |
| 102 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsWritableStreamConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWritableStreamConstructor) } }, |
| 103 | { "closed" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(writableStreamClosedCodeGenerator), (intptr_t) (0) } }, |
| 104 | { "ready" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(writableStreamReadyCodeGenerator), (intptr_t) (0) } }, |
| 105 | { "state" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor | JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(writableStreamStateCodeGenerator), (intptr_t) (0) } }, |
| 106 | { "abort" , static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(writableStreamAbortCodeGenerator), (intptr_t) (0) } }, |
| 107 | { "close" , static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(writableStreamCloseCodeGenerator), (intptr_t) (0) } }, |
| 108 | { "write" , static_cast<unsigned>(JSC::PropertyAttribute::Builtin), NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(writableStreamWriteCodeGenerator), (intptr_t) (1) } }, |
| 109 | }; |
| 110 | |
| 111 | const ClassInfo JSWritableStreamPrototype::s_info = { "WritableStreamPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWritableStreamPrototype) }; |
| 112 | |
| 113 | void JSWritableStreamPrototype::finishCreation(VM& vm) |
| 114 | { |
| 115 | Base::finishCreation(vm); |
| 116 | reifyStaticProperties(vm, JSWritableStream::info(), JSWritableStreamPrototypeTableValues, *this); |
| 117 | } |
| 118 | |
| 119 | const ClassInfo JSWritableStream::s_info = { "WritableStream" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWritableStream) }; |
| 120 | |
| 121 | JSWritableStream::JSWritableStream(Structure* structure, JSDOMGlobalObject& globalObject) |
| 122 | : JSDOMObject(structure, globalObject) { } |
| 123 | |
| 124 | void JSWritableStream::finishCreation(VM& vm) |
| 125 | { |
| 126 | Base::finishCreation(vm); |
| 127 | ASSERT(inherits(vm, info())); |
| 128 | |
| 129 | } |
| 130 | |
| 131 | JSObject* JSWritableStream::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 132 | { |
| 133 | return JSWritableStreamPrototype::create(vm, &globalObject, JSWritableStreamPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
| 134 | } |
| 135 | |
| 136 | JSObject* JSWritableStream::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 137 | { |
| 138 | return getDOMPrototype<JSWritableStream>(vm, globalObject); |
| 139 | } |
| 140 | |
| 141 | JSValue JSWritableStream::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 142 | { |
| 143 | return getDOMConstructor<JSWritableStreamConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 144 | } |
| 145 | |
| 146 | void JSWritableStream::destroy(JSC::JSCell* cell) |
| 147 | { |
| 148 | JSWritableStream* thisObject = static_cast<JSWritableStream*>(cell); |
| 149 | thisObject->JSWritableStream::~JSWritableStream(); |
| 150 | } |
| 151 | |
| 152 | template<> inline JSWritableStream* IDLAttribute<JSWritableStream>::cast(ExecState& state, EncodedJSValue thisValue) |
| 153 | { |
| 154 | return jsDynamicCast<JSWritableStream*>(state.vm(), JSValue::decode(thisValue)); |
| 155 | } |
| 156 | |
| 157 | template<> inline JSWritableStream* IDLOperation<JSWritableStream>::cast(ExecState& state) |
| 158 | { |
| 159 | return jsDynamicCast<JSWritableStream*>(state.vm(), state.thisValue()); |
| 160 | } |
| 161 | |
| 162 | EncodedJSValue jsWritableStreamConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 163 | { |
| 164 | VM& vm = state->vm(); |
| 165 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 166 | auto* prototype = jsDynamicCast<JSWritableStreamPrototype*>(vm, JSValue::decode(thisValue)); |
| 167 | if (UNLIKELY(!prototype)) |
| 168 | return throwVMTypeError(state, throwScope); |
| 169 | return JSValue::encode(JSWritableStream::getConstructor(state->vm(), prototype->globalObject())); |
| 170 | } |
| 171 | |
| 172 | bool setJSWritableStreamConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 173 | { |
| 174 | VM& vm = state->vm(); |
| 175 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 176 | auto* prototype = jsDynamicCast<JSWritableStreamPrototype*>(vm, JSValue::decode(thisValue)); |
| 177 | if (UNLIKELY(!prototype)) { |
| 178 | throwVMTypeError(state, throwScope); |
| 179 | return false; |
| 180 | } |
| 181 | // Shadowing a built-in constructor |
| 182 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | } |
| 187 | |
| 188 | #endif // ENABLE(STREAMS_API) |
| 189 | |