blob: 83cc8db9bbfe323e9f2a14855ce67a32c4e1a632 [file] [log] [blame]
/*
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"
#include "JSMutationObserver.h"
#include "ExceptionCode.h"
#include "JSDOMBinding.h"
#include "JSDOMConstructor.h"
#include "JSDOMConvert.h"
#include "JSMutationRecord.h"
#include "JSNode.h"
#include "MutationRecord.h"
#include <runtime/Error.h>
#include <runtime/FunctionPrototype.h>
#include <runtime/JSArray.h>
#include <wtf/GetPtr.h>
using namespace JSC;
namespace WebCore {
template<> Optional<MutationObserver::Init> convertDictionary<MutationObserver::Init>(ExecState& state, JSValue value)
{
VM& vm = state.vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
if (value.isUndefinedOrNull())
return MutationObserver::Init { false, { }, { }, false, { }, { }, { } };
auto* object = value.getObject();
if (UNLIKELY(!object || object->type() == RegExpObjectType)) {
throwTypeError(&state, throwScope);
return Nullopt;
}
auto childList = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "childList")), false);
RETURN_IF_EXCEPTION(throwScope, Nullopt);
auto attributes = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "attributes")));
RETURN_IF_EXCEPTION(throwScope, Nullopt);
auto characterData = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "characterData")));
RETURN_IF_EXCEPTION(throwScope, Nullopt);
auto subtree = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "subtree")), false);
RETURN_IF_EXCEPTION(throwScope, Nullopt);
auto attributeOldValue = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "attributeOldValue")));
RETURN_IF_EXCEPTION(throwScope, Nullopt);
auto characterDataOldValue = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "characterDataOldValue")));
RETURN_IF_EXCEPTION(throwScope, Nullopt);
auto attributeFilter = convertOptional<Vector<String>>(state, object->get(&state, Identifier::fromString(&state, "attributeFilter")));
return MutationObserver::Init { WTFMove(childList), WTFMove(attributes), WTFMove(characterData), WTFMove(subtree), WTFMove(attributeOldValue), WTFMove(characterDataOldValue), WTFMove(attributeFilter) };
}
// Functions
JSC::EncodedJSValue JSC_HOST_CALL jsMutationObserverPrototypeFunctionObserve(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsMutationObserverPrototypeFunctionTakeRecords(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsMutationObserverPrototypeFunctionDisconnect(JSC::ExecState*);
// Attributes
JSC::EncodedJSValue jsMutationObserverConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
bool setJSMutationObserverConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
class JSMutationObserverPrototype : public JSC::JSNonFinalObject {
public:
typedef JSC::JSNonFinalObject Base;
static JSMutationObserverPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
{
JSMutationObserverPrototype* ptr = new (NotNull, JSC::allocateCell<JSMutationObserverPrototype>(vm.heap)) JSMutationObserverPrototype(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:
JSMutationObserverPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
typedef JSDOMConstructor<JSMutationObserver> JSMutationObserverConstructor;
template<> JSC::EncodedJSValue JSC_HOST_CALL JSMutationObserverConstructor::construct(JSC::ExecState* exec)
{
ASSERT(exec);
return constructJSMutationObserver(*exec);
}
template<> JSValue JSMutationObserverConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSMutationObserverConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->prototype, JSMutationObserver::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("MutationObserver"))), ReadOnly | DontEnum);
putDirect(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum);
}
template<> const ClassInfo JSMutationObserverConstructor::s_info = { "MutationObserver", &Base::s_info, 0, CREATE_METHOD_TABLE(JSMutationObserverConstructor) };
/* Hash table for prototype */
static const HashTableValue JSMutationObserverPrototypeTableValues[] =
{
{ "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMutationObserverConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMutationObserverConstructor) } },
{ "observe", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsMutationObserverPrototypeFunctionObserve), (intptr_t) (2) } },
{ "takeRecords", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsMutationObserverPrototypeFunctionTakeRecords), (intptr_t) (0) } },
{ "disconnect", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsMutationObserverPrototypeFunctionDisconnect), (intptr_t) (0) } },
};
const ClassInfo JSMutationObserverPrototype::s_info = { "MutationObserverPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSMutationObserverPrototype) };
void JSMutationObserverPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSMutationObserverPrototypeTableValues, *this);
}
const ClassInfo JSMutationObserver::s_info = { "MutationObserver", &Base::s_info, 0, CREATE_METHOD_TABLE(JSMutationObserver) };
JSMutationObserver::JSMutationObserver(Structure* structure, JSDOMGlobalObject& globalObject, Ref<MutationObserver>&& impl)
: JSDOMWrapper<MutationObserver>(structure, globalObject, WTFMove(impl))
{
}
JSObject* JSMutationObserver::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
return JSMutationObserverPrototype::create(vm, globalObject, JSMutationObserverPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
}
JSObject* JSMutationObserver::prototype(VM& vm, JSGlobalObject* globalObject)
{
return getDOMPrototype<JSMutationObserver>(vm, globalObject);
}
void JSMutationObserver::destroy(JSC::JSCell* cell)
{
JSMutationObserver* thisObject = static_cast<JSMutationObserver*>(cell);
thisObject->JSMutationObserver::~JSMutationObserver();
}
EncodedJSValue jsMutationObserverConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSMutationObserverPrototype* domObject = jsDynamicCast<JSMutationObserverPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!domObject))
return throwVMTypeError(state, throwScope);
return JSValue::encode(JSMutationObserver::getConstructor(state->vm(), domObject->globalObject()));
}
bool setJSMutationObserverConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSValue value = JSValue::decode(encodedValue);
JSMutationObserverPrototype* domObject = jsDynamicCast<JSMutationObserverPrototype*>(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 JSMutationObserver::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSMutationObserverConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
EncodedJSValue JSC_HOST_CALL jsMutationObserverPrototypeFunctionObserve(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSMutationObserver*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "MutationObserver", "observe");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSMutationObserver::info());
auto& impl = castedThis->wrapped();
if (UNLIKELY(state->argumentCount() < 2))
return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
ExceptionCode ec = 0;
auto target = JSNode::toWrapped(state->uncheckedArgument(0));
if (UNLIKELY(!target))
return throwArgumentTypeError(*state, throwScope, 0, "target", "MutationObserver", "observe", "Node");
auto options = convertDictionary<MutationObserver::Init>(*state, state->uncheckedArgument(1));
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
impl.observe(*target, options.value(), ec);
setDOMException(state, throwScope, ec);
return JSValue::encode(jsUndefined());
}
EncodedJSValue JSC_HOST_CALL jsMutationObserverPrototypeFunctionTakeRecords(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSMutationObserver*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "MutationObserver", "takeRecords");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSMutationObserver::info());
auto& impl = castedThis->wrapped();
JSValue result = jsArray(state, castedThis->globalObject(), impl.takeRecords());
return JSValue::encode(result);
}
EncodedJSValue JSC_HOST_CALL jsMutationObserverPrototypeFunctionDisconnect(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSMutationObserver*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "MutationObserver", "disconnect");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSMutationObserver::info());
auto& impl = castedThis->wrapped();
impl.disconnect();
return JSValue::encode(jsUndefined());
}
void JSMutationObserverOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
auto* jsMutationObserver = jsCast<JSMutationObserver*>(handle.slot()->asCell());
auto& world = *static_cast<DOMWrapperWorld*>(context);
uncacheWrapper(world, &jsMutationObserver->wrapped(), jsMutationObserver);
}
JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<MutationObserver>&& impl)
{
#if COMPILER(CLANG)
// If you hit this failure the interface definition has the ImplementationLacksVTable
// attribute. You should remove that attribute. If the class has subclasses
// that may be passed through this toJS() function you should use the SkipVTableValidation
// attribute to MutationObserver.
static_assert(!__is_polymorphic(MutationObserver), "MutationObserver is polymorphic but the IDL claims it is not");
#endif
return createWrapper<MutationObserver>(globalObject, WTFMove(impl));
}
JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, MutationObserver& impl)
{
return wrap(state, globalObject, impl);
}
MutationObserver* JSMutationObserver::toWrapped(JSC::JSValue value)
{
if (auto* wrapper = jsDynamicCast<JSMutationObserver*>(value))
return &wrapper->wrapped();
return nullptr;
}
}