darling-JavaScriptCore/runtime/ClassInfo.h

216 lines
8.5 KiB
C
Raw Normal View History

2017-08-12 16:48:01 +00:00
/*
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
2020-08-29 13:27:11 +00:00
* Copyright (C) 2003-2019 Apple Inc. All rights reserved.
2017-08-12 16:48:01 +00:00
*
* 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.
*
*/
#pragma once
#include "ConstructData.h"
2020-08-29 13:27:11 +00:00
#include "JSCast.h"
#include <wtf/PtrTag.h>
2017-08-12 16:48:01 +00:00
2018-01-03 05:16:05 +00:00
namespace WTF {
class PrintStream;
};
2017-08-12 16:48:01 +00:00
namespace JSC {
class HeapAnalyzer;
2017-08-12 16:48:01 +00:00
class JSArrayBufferView;
2018-01-03 05:16:05 +00:00
class Snippet;
2017-08-12 16:48:01 +00:00
struct HashTable;
#define METHOD_TABLE_ENTRY(method) \
WTF_VTBL_FUNCPTR_PTRAUTH_STR("MethodTable." #method) method
2020-08-29 13:27:11 +00:00
2017-08-12 16:48:01 +00:00
struct MethodTable {
2020-08-29 13:27:11 +00:00
using DestroyFunctionPtr = void (*)(JSCell*);
DestroyFunctionPtr METHOD_TABLE_ENTRY(destroy);
2020-08-29 13:27:11 +00:00
using VisitChildrenFunctionPtr = void (*)(JSCell*, SlotVisitor&);
VisitChildrenFunctionPtr METHOD_TABLE_ENTRY(visitChildren);
2017-08-12 16:48:01 +00:00
using GetCallDataFunctionPtr = CallData (*)(JSCell*);
GetCallDataFunctionPtr METHOD_TABLE_ENTRY(getCallData);
2017-08-12 16:48:01 +00:00
using GetConstructDataFunctionPtr = CallData (*)(JSCell*);
GetConstructDataFunctionPtr METHOD_TABLE_ENTRY(getConstructData);
2017-08-12 16:48:01 +00:00
using PutFunctionPtr = bool (*)(JSCell*, JSGlobalObject*, PropertyName propertyName, JSValue, PutPropertySlot&);
PutFunctionPtr METHOD_TABLE_ENTRY(put);
2017-08-12 16:48:01 +00:00
using PutByIndexFunctionPtr = bool (*)(JSCell*, JSGlobalObject*, unsigned propertyName, JSValue, bool shouldThrow);
PutByIndexFunctionPtr METHOD_TABLE_ENTRY(putByIndex);
2017-08-12 16:48:01 +00:00
using DeletePropertyFunctionPtr = bool (*)(JSCell*, JSGlobalObject*, PropertyName, DeletePropertySlot&);
DeletePropertyFunctionPtr METHOD_TABLE_ENTRY(deleteProperty);
2017-08-12 16:48:01 +00:00
using DeletePropertyByIndexFunctionPtr = bool (*)(JSCell*, JSGlobalObject*, unsigned);
DeletePropertyByIndexFunctionPtr METHOD_TABLE_ENTRY(deletePropertyByIndex);
2017-08-12 16:48:01 +00:00
using GetOwnPropertySlotFunctionPtr = bool (*)(JSObject*, JSGlobalObject*, PropertyName, PropertySlot&);
GetOwnPropertySlotFunctionPtr METHOD_TABLE_ENTRY(getOwnPropertySlot);
2017-08-12 16:48:01 +00:00
using GetOwnPropertySlotByIndexFunctionPtr = bool (*)(JSObject*, JSGlobalObject*, unsigned, PropertySlot&);
GetOwnPropertySlotByIndexFunctionPtr METHOD_TABLE_ENTRY(getOwnPropertySlotByIndex);
2017-08-12 16:48:01 +00:00
using DoPutPropertySecurityCheckFunctionPtr = void (*)(JSObject*, JSGlobalObject*, PropertyName, PutPropertySlot&);
DoPutPropertySecurityCheckFunctionPtr METHOD_TABLE_ENTRY(doPutPropertySecurityCheck);
2017-08-12 16:48:01 +00:00
using ToThisFunctionPtr = JSValue (*)(JSCell*, JSGlobalObject*, ECMAMode);
ToThisFunctionPtr METHOD_TABLE_ENTRY(toThis);
2017-08-12 16:48:01 +00:00
using DefaultValueFunctionPtr = JSValue (*)(const JSObject*, JSGlobalObject*, PreferredPrimitiveType);
DefaultValueFunctionPtr METHOD_TABLE_ENTRY(defaultValue);
2017-08-12 16:48:01 +00:00
using GetOwnPropertyNamesFunctionPtr = void (*)(JSObject*, JSGlobalObject*, PropertyNameArray&, DontEnumPropertiesMode);
GetOwnPropertyNamesFunctionPtr METHOD_TABLE_ENTRY(getOwnPropertyNames);
GetOwnPropertyNamesFunctionPtr METHOD_TABLE_ENTRY(getOwnSpecialPropertyNames);
2017-08-12 16:48:01 +00:00
using GetEnumerableLengthFunctionPtr = uint32_t (*)(JSGlobalObject*, JSObject*);
GetEnumerableLengthFunctionPtr METHOD_TABLE_ENTRY(getEnumerableLength);
2017-08-12 16:48:01 +00:00
2020-08-29 13:27:11 +00:00
using ClassNameFunctionPtr = String (*)(const JSObject*, VM&);
ClassNameFunctionPtr METHOD_TABLE_ENTRY(className);
2017-08-12 16:48:01 +00:00
using ToStringNameFunctionPtr = String (*)(const JSObject*, JSGlobalObject*);
ToStringNameFunctionPtr METHOD_TABLE_ENTRY(toStringName);
2017-08-12 16:48:01 +00:00
using CustomHasInstanceFunctionPtr = bool (*)(JSObject*, JSGlobalObject*, JSValue);
CustomHasInstanceFunctionPtr METHOD_TABLE_ENTRY(customHasInstance);
2017-08-12 16:48:01 +00:00
using DefineOwnPropertyFunctionPtr = bool (*)(JSObject*, JSGlobalObject*, PropertyName, const PropertyDescriptor&, bool);
DefineOwnPropertyFunctionPtr METHOD_TABLE_ENTRY(defineOwnProperty);
2017-08-12 16:48:01 +00:00
using PreventExtensionsFunctionPtr = bool (*)(JSObject*, JSGlobalObject*);
PreventExtensionsFunctionPtr METHOD_TABLE_ENTRY(preventExtensions);
2017-08-12 16:48:01 +00:00
using IsExtensibleFunctionPtr = bool (*)(JSObject*, JSGlobalObject*);
IsExtensibleFunctionPtr METHOD_TABLE_ENTRY(isExtensible);
2017-08-12 16:48:01 +00:00
using SetPrototypeFunctionPtr = bool (*)(JSObject*, JSGlobalObject*, JSValue, bool shouldThrowIfCantSet);
SetPrototypeFunctionPtr METHOD_TABLE_ENTRY(setPrototype);
2017-08-12 16:48:01 +00:00
using GetPrototypeFunctionPtr = JSValue (*)(JSObject*, JSGlobalObject*);
GetPrototypeFunctionPtr METHOD_TABLE_ENTRY(getPrototype);
2017-08-12 16:48:01 +00:00
2020-08-29 13:27:11 +00:00
using DumpToStreamFunctionPtr = void (*)(const JSCell*, PrintStream&);
DumpToStreamFunctionPtr METHOD_TABLE_ENTRY(dumpToStream);
2017-08-12 16:48:01 +00:00
using AnalyzeHeapFunctionPtr = void (*)(JSCell*, HeapAnalyzer&);
AnalyzeHeapFunctionPtr METHOD_TABLE_ENTRY(analyzeHeap);
2017-08-12 16:48:01 +00:00
2020-08-29 13:27:11 +00:00
using EstimatedSizeFunctionPtr = size_t (*)(JSCell*, VM&);
EstimatedSizeFunctionPtr METHOD_TABLE_ENTRY(estimatedSize);
2017-08-12 16:48:01 +00:00
2020-08-29 13:27:11 +00:00
using VisitOutputConstraintsPtr = void (*)(JSCell*, SlotVisitor&);
VisitOutputConstraintsPtr METHOD_TABLE_ENTRY(visitOutputConstraints);
2017-08-12 16:48:01 +00:00
};
#define CREATE_MEMBER_CHECKER(member) \
template <typename T> \
struct MemberCheck##member { \
struct Fallback { \
void member(...); \
}; \
struct Derived : T, Fallback { }; \
template <typename U, U> struct Check; \
typedef char Yes[2]; \
typedef char No[1]; \
template <typename U> \
static No &func(Check<void (Fallback::*)(...), &U::member>*); \
template <typename U> \
static Yes &func(...); \
enum { has = sizeof(func<Derived>(0)) == sizeof(Yes) }; \
}
#define HAS_MEMBER_NAMED(klass, name) (MemberCheck##name<klass>::has)
#define CREATE_METHOD_TABLE(ClassName) \
JSCastingHelpers::InheritsTraits<ClassName>::typeRange, \
{ \
2017-08-12 16:48:01 +00:00
&ClassName::destroy, \
&ClassName::visitChildren, \
&ClassName::getCallData, \
&ClassName::getConstructData, \
&ClassName::put, \
&ClassName::putByIndex, \
&ClassName::deleteProperty, \
&ClassName::deletePropertyByIndex, \
&ClassName::getOwnPropertySlot, \
&ClassName::getOwnPropertySlotByIndex, \
2020-08-29 13:27:11 +00:00
&ClassName::doPutPropertySecurityCheck, \
2017-08-12 16:48:01 +00:00
&ClassName::toThis, \
&ClassName::defaultValue, \
&ClassName::getOwnPropertyNames, \
&ClassName::getOwnSpecialPropertyNames, \
2017-08-12 16:48:01 +00:00
&ClassName::getEnumerableLength, \
&ClassName::className, \
&ClassName::toStringName, \
&ClassName::customHasInstance, \
&ClassName::defineOwnProperty, \
&ClassName::preventExtensions, \
&ClassName::isExtensible, \
&ClassName::setPrototype, \
&ClassName::getPrototype, \
&ClassName::dumpToStream, \
&ClassName::analyzeHeap, \
2017-08-12 16:48:01 +00:00
&ClassName::estimatedSize, \
2020-08-29 13:27:11 +00:00
&ClassName::visitOutputConstraints, \
2017-08-12 16:48:01 +00:00
}, \
ClassName::TypedArrayStorageType, \
sizeof(ClassName),
2017-08-12 16:48:01 +00:00
struct ClassInfo {
using CheckJSCastSnippetFunctionPtr = Ref<Snippet> (*)(void);
2017-08-12 16:48:01 +00:00
// A string denoting the class name. Example: "Window".
const char* className;
// Pointer to the class information of the base class.
// nullptrif there is none.
const ClassInfo* parentClass;
const HashTable* staticPropHashTable;
CheckJSCastSnippetFunctionPtr checkSubClassSnippet;
const Optional<JSTypeRange> inheritsJSTypeRange; // This is range of JSTypes for doing inheritance checking. Has the form: [firstJSType, lastJSType] (inclusive).
MethodTable methodTable;
const TypedArrayType typedArrayStorageType;
const unsigned staticClassSize;
2017-08-12 16:48:01 +00:00
2018-01-03 05:16:05 +00:00
static ptrdiff_t offsetOfParentClass()
{
return OBJECT_OFFSETOF(ClassInfo, parentClass);
}
2017-08-12 16:48:01 +00:00
bool isSubClassOf(const ClassInfo* other) const
{
for (const ClassInfo* ci = this; ci; ci = ci->parentClass) {
if (ci == other)
return true;
}
return false;
}
2018-01-03 05:16:05 +00:00
JS_EXPORT_PRIVATE void dump(PrintStream&) const;
2017-08-12 16:48:01 +00:00
JS_EXPORT_PRIVATE bool hasStaticSetterOrReadonlyProperties() const;
};
} // namespace JSC