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 | #include "JSText.h" |
23 | |
24 | #include "Document.h" |
25 | #include "JSDOMAttribute.h" |
26 | #include "JSDOMBinding.h" |
27 | #include "JSDOMConstructor.h" |
28 | #include "JSDOMConvertInterface.h" |
29 | #include "JSDOMConvertNullable.h" |
30 | #include "JSDOMConvertNumbers.h" |
31 | #include "JSDOMConvertStrings.h" |
32 | #include "JSDOMExceptionHandling.h" |
33 | #include "JSDOMGlobalObject.h" |
34 | #include "JSDOMOperation.h" |
35 | #include "JSDOMWrapperCache.h" |
36 | #include "JSHTMLSlotElement.h" |
37 | #include "JSText.h" |
38 | #include "RuntimeEnabledFeatures.h" |
39 | #include "ScriptExecutionContext.h" |
40 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
41 | #include <JavaScriptCore/JSCInlines.h> |
42 | #include <wtf/GetPtr.h> |
43 | #include <wtf/PointerPreparations.h> |
44 | #include <wtf/URL.h> |
45 | |
46 | |
47 | namespace WebCore { |
48 | using namespace JSC; |
49 | |
50 | // Functions |
51 | |
52 | JSC::EncodedJSValue JSC_HOST_CALL jsTextPrototypeFunctionSplitText(JSC::ExecState*); |
53 | |
54 | // Attributes |
55 | |
56 | JSC::EncodedJSValue jsTextConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
57 | bool setJSTextConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
58 | JSC::EncodedJSValue jsTextWholeText(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
59 | JSC::EncodedJSValue jsTextAssignedSlot(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
60 | |
61 | class JSTextPrototype : public JSC::JSNonFinalObject { |
62 | public: |
63 | using Base = JSC::JSNonFinalObject; |
64 | static JSTextPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
65 | { |
66 | JSTextPrototype* ptr = new (NotNull, JSC::allocateCell<JSTextPrototype>(vm.heap)) JSTextPrototype(vm, globalObject, structure); |
67 | ptr->finishCreation(vm); |
68 | return ptr; |
69 | } |
70 | |
71 | DECLARE_INFO; |
72 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
73 | { |
74 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
75 | } |
76 | |
77 | private: |
78 | JSTextPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
79 | : JSC::JSNonFinalObject(vm, structure) |
80 | { |
81 | } |
82 | |
83 | void finishCreation(JSC::VM&); |
84 | }; |
85 | |
86 | using JSTextConstructor = JSDOMConstructor<JSText>; |
87 | |
88 | template<> EncodedJSValue JSC_HOST_CALL JSTextConstructor::construct(ExecState* state) |
89 | { |
90 | VM& vm = state->vm(); |
91 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
92 | UNUSED_PARAM(throwScope); |
93 | auto* castedThis = jsCast<JSTextConstructor*>(state->jsCallee()); |
94 | ASSERT(castedThis); |
95 | auto* context = castedThis->scriptExecutionContext(); |
96 | if (UNLIKELY(!context)) |
97 | return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "Text" ); |
98 | ASSERT(context->isDocument()); |
99 | auto& document = downcast<Document>(*context); |
100 | auto data = state->argument(0).isUndefined() ? emptyString() : convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
101 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
102 | auto object = Text::create(document, WTFMove(data)); |
103 | return JSValue::encode(toJSNewlyCreated<IDLInterface<Text>>(*state, *castedThis->globalObject(), WTFMove(object))); |
104 | } |
105 | |
106 | template<> JSValue JSTextConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
107 | { |
108 | return JSCharacterData::getConstructor(vm, &globalObject); |
109 | } |
110 | |
111 | template<> void JSTextConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
112 | { |
113 | putDirect(vm, vm.propertyNames->prototype, JSText::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
114 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Text"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
115 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
116 | } |
117 | |
118 | template<> const ClassInfo JSTextConstructor::s_info = { "Text" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextConstructor) }; |
119 | |
120 | /* Hash table for prototype */ |
121 | |
122 | static const HashTableValue JSTextPrototypeTableValues[] = |
123 | { |
124 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTextConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTextConstructor) } }, |
125 | { "wholeText" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTextWholeText), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
126 | { "assignedSlot" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTextAssignedSlot), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
127 | { "splitText" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTextPrototypeFunctionSplitText), (intptr_t) (1) } }, |
128 | }; |
129 | |
130 | const ClassInfo JSTextPrototype::s_info = { "TextPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTextPrototype) }; |
131 | |
132 | void JSTextPrototype::finishCreation(VM& vm) |
133 | { |
134 | Base::finishCreation(vm); |
135 | reifyStaticProperties(vm, JSText::info(), JSTextPrototypeTableValues, *this); |
136 | bool hasDisabledRuntimeProperties = false; |
137 | if (!RuntimeEnabledFeatures::sharedFeatures().shadowDOMEnabled()) { |
138 | hasDisabledRuntimeProperties = true; |
139 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("assignedSlot" ), strlen("assignedSlot" )); |
140 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
141 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
142 | } |
143 | if (hasDisabledRuntimeProperties && structure()->isDictionary()) |
144 | flattenDictionaryObject(vm); |
145 | } |
146 | |
147 | const ClassInfo JSText::s_info = { "Text" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSText) }; |
148 | |
149 | JSText::JSText(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Text>&& impl) |
150 | : JSCharacterData(structure, globalObject, WTFMove(impl)) |
151 | { |
152 | } |
153 | |
154 | void JSText::finishCreation(VM& vm) |
155 | { |
156 | Base::finishCreation(vm); |
157 | ASSERT(inherits(vm, info())); |
158 | |
159 | } |
160 | |
161 | JSObject* JSText::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
162 | { |
163 | return JSTextPrototype::create(vm, &globalObject, JSTextPrototype::createStructure(vm, &globalObject, JSCharacterData::prototype(vm, globalObject))); |
164 | } |
165 | |
166 | JSObject* JSText::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
167 | { |
168 | return getDOMPrototype<JSText>(vm, globalObject); |
169 | } |
170 | |
171 | JSValue JSText::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
172 | { |
173 | return getDOMConstructor<JSTextConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
174 | } |
175 | |
176 | template<> inline JSText* IDLAttribute<JSText>::cast(ExecState& state, EncodedJSValue thisValue) |
177 | { |
178 | return jsDynamicCast<JSText*>(state.vm(), JSValue::decode(thisValue)); |
179 | } |
180 | |
181 | template<> inline JSText* IDLOperation<JSText>::cast(ExecState& state) |
182 | { |
183 | return jsDynamicCast<JSText*>(state.vm(), state.thisValue()); |
184 | } |
185 | |
186 | EncodedJSValue jsTextConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
187 | { |
188 | VM& vm = state->vm(); |
189 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
190 | auto* prototype = jsDynamicCast<JSTextPrototype*>(vm, JSValue::decode(thisValue)); |
191 | if (UNLIKELY(!prototype)) |
192 | return throwVMTypeError(state, throwScope); |
193 | return JSValue::encode(JSText::getConstructor(state->vm(), prototype->globalObject())); |
194 | } |
195 | |
196 | bool setJSTextConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
197 | { |
198 | VM& vm = state->vm(); |
199 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
200 | auto* prototype = jsDynamicCast<JSTextPrototype*>(vm, JSValue::decode(thisValue)); |
201 | if (UNLIKELY(!prototype)) { |
202 | throwVMTypeError(state, throwScope); |
203 | return false; |
204 | } |
205 | // Shadowing a built-in constructor |
206 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
207 | } |
208 | |
209 | static inline JSValue jsTextWholeTextGetter(ExecState& state, JSText& thisObject, ThrowScope& throwScope) |
210 | { |
211 | UNUSED_PARAM(throwScope); |
212 | UNUSED_PARAM(state); |
213 | auto& impl = thisObject.wrapped(); |
214 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.wholeText()); |
215 | return result; |
216 | } |
217 | |
218 | EncodedJSValue jsTextWholeText(ExecState* state, EncodedJSValue thisValue, PropertyName) |
219 | { |
220 | return IDLAttribute<JSText>::get<jsTextWholeTextGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "wholeText" ); |
221 | } |
222 | |
223 | static inline JSValue jsTextAssignedSlotGetter(ExecState& state, JSText& thisObject, ThrowScope& throwScope) |
224 | { |
225 | UNUSED_PARAM(throwScope); |
226 | UNUSED_PARAM(state); |
227 | auto& impl = thisObject.wrapped(); |
228 | JSValue result = toJS<IDLNullable<IDLInterface<HTMLSlotElement>>>(state, *thisObject.globalObject(), throwScope, impl.assignedSlotForBindings()); |
229 | return result; |
230 | } |
231 | |
232 | EncodedJSValue jsTextAssignedSlot(ExecState* state, EncodedJSValue thisValue, PropertyName) |
233 | { |
234 | return IDLAttribute<JSText>::get<jsTextAssignedSlotGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "assignedSlot" ); |
235 | } |
236 | |
237 | static inline JSC::EncodedJSValue jsTextPrototypeFunctionSplitTextBody(JSC::ExecState* state, typename IDLOperation<JSText>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
238 | { |
239 | UNUSED_PARAM(state); |
240 | UNUSED_PARAM(throwScope); |
241 | auto& impl = castedThis->wrapped(); |
242 | if (UNLIKELY(state->argumentCount() < 1)) |
243 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
244 | auto offset = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
245 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
246 | return JSValue::encode(toJS<IDLInterface<Text>>(*state, *castedThis->globalObject(), throwScope, impl.splitText(WTFMove(offset)))); |
247 | } |
248 | |
249 | EncodedJSValue JSC_HOST_CALL jsTextPrototypeFunctionSplitText(ExecState* state) |
250 | { |
251 | return IDLOperation<JSText>::call<jsTextPrototypeFunctionSplitTextBody>(*state, "splitText" ); |
252 | } |
253 | |
254 | void JSText::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
255 | { |
256 | auto* thisObject = jsCast<JSText*>(cell); |
257 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
258 | if (thisObject->scriptExecutionContext()) |
259 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
260 | Base::heapSnapshot(cell, builder); |
261 | } |
262 | |
263 | |
264 | } |
265 | |