Bug 1573844 - Remove js::Class definition and alias JSClass to it r=tcampbell,mccr8

JSClass contained void* members corresponding to the internal pointer members of js::Class. This stores the internal members in JSClass and removes js::Class.

This leaves js::Class aliased to JSClass while we remove references to it. I also aliased Jsvalify and Valueify into global scope temporarily to make this compile. These get removed in the following patches.

I had to remove a few functions which now don't compile with js::Class being the same type as JSClass.

Differential Revision: https://phabricator.services.mozilla.com/D41983

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jon Coppeard 2019-08-15 08:32:22 +00:00
Родитель 9da24241a7
Коммит 66fc30ba53
17 изменённых файлов: 107 добавлений и 145 удалений

Просмотреть файл

@ -83,17 +83,9 @@ inline bool IsDOMClass(const JSClass* clasp) {
return clasp->flags & JSCLASS_IS_DOMJSCLASS;
}
inline bool IsDOMClass(const js::Class* clasp) {
return IsDOMClass(Jsvalify(clasp));
}
// Return true if the JSClass is used for non-proxy DOM objects.
inline bool IsNonProxyDOMClass(const js::Class* clasp) {
return IsDOMClass(clasp) && !clasp->isProxy();
}
inline bool IsNonProxyDOMClass(const JSClass* clasp) {
return IsNonProxyDOMClass(js::Valueify(clasp));
return IsDOMClass(clasp) && !clasp->isProxy();
}
// Returns true if the JSClass is used for DOM interface and interface
@ -102,10 +94,6 @@ inline bool IsDOMIfaceAndProtoClass(const JSClass* clasp) {
return clasp->flags & JSCLASS_IS_DOMIFACEANDPROTOJSCLASS;
}
inline bool IsDOMIfaceAndProtoClass(const js::Class* clasp) {
return IsDOMIfaceAndProtoClass(Jsvalify(clasp));
}
static_assert(DOM_OBJECT_SLOT == 0,
"DOM_OBJECT_SLOT doesn't match the proxy private slot. "
"Expect bad things");

Просмотреть файл

@ -452,10 +452,6 @@ struct DOMJSClass {
return reinterpret_cast<const DOMJSClass*>(base);
}
static const DOMJSClass* FromJSClass(const js::Class* base) {
return FromJSClass(Jsvalify(base));
}
const JSClass* ToJSClass() const { return Jsvalify(&mBase); }
};
@ -491,9 +487,6 @@ struct DOMIfaceAndProtoJSClass {
MOZ_ASSERT(base->flags & JSCLASS_IS_DOMIFACEANDPROTOJSCLASS);
return reinterpret_cast<const DOMIfaceAndProtoJSClass*>(base);
}
static const DOMIfaceAndProtoJSClass* FromJSClass(const js::Class* base) {
return FromJSClass(Jsvalify(base));
}
const JSClass* ToJSClass() const { return Jsvalify(&mBase); }
};

Просмотреть файл

@ -20,7 +20,7 @@
/*
* A JSClass acts as a vtable for JS objects that allows JSAPI clients to
* control various aspects of the behavior of an object like property lookup.
* js::Class is an engine-private extension that allows more control over
* It contains some engine-private extensions that allows more control over
* object behavior and, e.g., allows custom slow layout.
*/
@ -29,7 +29,6 @@ struct JSFunctionSpec;
namespace js {
struct Class;
class Shape;
// This is equal to JSFunction::class_. Use it in places where you don't want
@ -493,10 +492,10 @@ typedef void (*JSTraceOp)(JSTracer* trc, JSObject* obj);
typedef size_t (*JSObjectMovedOp)(JSObject* obj, JSObject* old);
/* js::Class operation signatures. */
namespace js {
/* Internal / friend API operation signatures. */
typedef bool (*LookupPropertyOp)(JSContext* cx, JS::HandleObject obj,
JS::HandleId id, JS::MutableHandleObject objp,
JS::MutableHandle<JS::PropertyResult> propp);
@ -573,50 +572,6 @@ typedef bool (*GetElementsOp)(JSContext* cx, JS::HandleObject obj,
uint32_t begin, uint32_t end,
ElementAdder* adder);
// The special treatment of |finalize| and |trace| is necessary because if we
// assign either of those hooks to a local variable and then call it -- as is
// done with the other hooks -- the GC hazard analysis gets confused.
#define JS_CLASS_MEMBERS \
const char* name; \
uint32_t flags; \
const JSClassOps* cOps; \
\
JSAddPropertyOp getAddProperty() const { \
return cOps ? cOps->addProperty : nullptr; \
} \
JSDeletePropertyOp getDelProperty() const { \
return cOps ? cOps->delProperty : nullptr; \
} \
JSEnumerateOp getEnumerate() const { \
return cOps ? cOps->enumerate : nullptr; \
} \
JSNewEnumerateOp getNewEnumerate() const { \
return cOps ? cOps->newEnumerate : nullptr; \
} \
JSResolveOp getResolve() const { return cOps ? cOps->resolve : nullptr; } \
JSMayResolveOp getMayResolve() const { \
return cOps ? cOps->mayResolve : nullptr; \
} \
JSNative getCall() const { return cOps ? cOps->call : nullptr; } \
JSHasInstanceOp getHasInstance() const { \
return cOps ? cOps->hasInstance : nullptr; \
} \
JSNative getConstruct() const { return cOps ? cOps->construct : nullptr; } \
\
bool hasFinalize() const { return cOps && cOps->finalize; } \
bool hasTrace() const { return cOps && cOps->trace; } \
\
bool isTrace(JSTraceOp trace) const { return cOps && cOps->trace == trace; } \
\
void doFinalize(JSFreeOp* fop, JSObject* obj) const { \
MOZ_ASSERT(cOps && cOps->finalize); \
cOps->finalize(fop, obj); \
} \
void doTrace(JSTracer* trc, JSObject* obj) const { \
MOZ_ASSERT(cOps && cOps->trace); \
cOps->trace(trc, obj); \
}
/** Callback for the creation of constructor and prototype objects. */
typedef JSObject* (*ClassObjectCreationOp)(JSContext* cx, JSProtoKey key);
@ -708,31 +663,6 @@ struct MOZ_STATIC_CLASS ObjectOps {
// Classes, objects, and properties.
typedef void (*JSClassInternal)();
struct MOZ_STATIC_CLASS JSClassOps {
/* Function pointer members (may be null). */
JSAddPropertyOp addProperty;
JSDeletePropertyOp delProperty;
JSEnumerateOp enumerate;
JSNewEnumerateOp newEnumerate;
JSResolveOp resolve;
JSMayResolveOp mayResolve;
JSFinalizeOp finalize;
JSNative call;
JSHasInstanceOp hasInstance;
JSNative construct;
JSTraceOp trace;
};
#define JS_NULL_CLASS_OPS nullptr
struct JSClass {
JS_CLASS_MEMBERS;
void* reserved[3];
};
// Objects have private slot.
static const uint32_t JSCLASS_HAS_PRIVATE = 1 << 0;
@ -842,18 +772,72 @@ static const uint32_t JSCLASS_CACHED_PROTO_MASK =
((JSProtoKey)(((clasp)->flags >> JSCLASS_CACHED_PROTO_SHIFT) & \
JSCLASS_CACHED_PROTO_MASK))
// Initializer for unused members of statically initialized JSClass structs.
#define JSCLASS_NO_INTERNAL_MEMBERS \
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
#define JSCLASS_NO_OPTIONAL_MEMBERS 0, 0, 0, 0, 0, JSCLASS_NO_INTERNAL_MEMBERS
struct MOZ_STATIC_CLASS JSClassOps {
/* Function pointer members (may be null). */
JSAddPropertyOp addProperty;
JSDeletePropertyOp delProperty;
JSEnumerateOp enumerate;
JSNewEnumerateOp newEnumerate;
JSResolveOp resolve;
JSMayResolveOp mayResolve;
JSFinalizeOp finalize;
JSNative call;
JSHasInstanceOp hasInstance;
JSNative construct;
JSTraceOp trace;
};
namespace js {
#define JS_NULL_CLASS_OPS nullptr
struct MOZ_STATIC_CLASS Class {
JS_CLASS_MEMBERS;
const ClassSpec* spec;
const ClassExtension* ext;
const ObjectOps* oOps;
struct JSClass {
const char* name;
uint32_t flags;
const JSClassOps* cOps;
const js::ClassSpec* spec;
const js::ClassExtension* ext;
const js::ObjectOps* oOps;
// Public accessors:
JSAddPropertyOp getAddProperty() const {
return cOps ? cOps->addProperty : nullptr;
}
JSDeletePropertyOp getDelProperty() const {
return cOps ? cOps->delProperty : nullptr;
}
JSEnumerateOp getEnumerate() const {
return cOps ? cOps->enumerate : nullptr;
}
JSNewEnumerateOp getNewEnumerate() const {
return cOps ? cOps->newEnumerate : nullptr;
}
JSResolveOp getResolve() const { return cOps ? cOps->resolve : nullptr; }
JSMayResolveOp getMayResolve() const {
return cOps ? cOps->mayResolve : nullptr;
}
JSNative getCall() const { return cOps ? cOps->call : nullptr; }
JSHasInstanceOp getHasInstance() const {
return cOps ? cOps->hasInstance : nullptr;
}
JSNative getConstruct() const { return cOps ? cOps->construct : nullptr; }
bool hasFinalize() const { return cOps && cOps->finalize; }
bool hasTrace() const { return cOps && cOps->trace; }
bool isTrace(JSTraceOp trace) const { return cOps && cOps->trace == trace; }
// The special treatment of |finalize| and |trace| is necessary because if we
// assign either of those hooks to a local variable and then call it -- as is
// done with the other hooks -- the GC hazard analysis gets confused.
void doFinalize(JSFreeOp* fop, JSObject* obj) const {
MOZ_ASSERT(cOps && cOps->finalize);
cOps->finalize(fop, obj);
}
void doTrace(JSTracer* trc, JSObject* obj) const {
MOZ_ASSERT(cOps && cOps->trace);
cOps->trace(trc, obj);
}
/*
* Objects of this class aren't native objects. They don't have Shapes that
@ -889,7 +873,9 @@ struct MOZ_STATIC_CLASS Class {
bool isWrappedNative() const { return flags & JSCLASS_IS_WRAPPED_NATIVE; }
static size_t offsetOfFlags() { return offsetof(Class, flags); }
static size_t offsetOfFlags() { return offsetof(JSClass, flags); }
// Internal / friend API accessors:
bool specDefined() const { return spec ? spec->defined() : false; }
JSProtoKey specInheritanceProtoKey() const {
@ -898,10 +884,10 @@ struct MOZ_STATIC_CLASS Class {
bool specShouldDefineConstructor() const {
return spec ? spec->shouldDefineConstructor() : true;
}
ClassObjectCreationOp specCreateConstructorHook() const {
js::ClassObjectCreationOp specCreateConstructorHook() const {
return spec ? spec->createConstructor : nullptr;
}
ClassObjectCreationOp specCreatePrototypeHook() const {
js::ClassObjectCreationOp specCreatePrototypeHook() const {
return spec ? spec->createPrototype : nullptr;
}
const JSFunctionSpec* specConstructorFunctions() const {
@ -916,7 +902,7 @@ struct MOZ_STATIC_CLASS Class {
const JSPropertySpec* specPrototypeProperties() const {
return spec ? spec->prototypeProperties : nullptr;
}
FinishClassInitOp specFinishInitHook() const {
js::FinishClassInitOp specFinishInitHook() const {
return spec ? spec->finishInit : nullptr;
}
@ -924,28 +910,28 @@ struct MOZ_STATIC_CLASS Class {
return ext ? ext->objectMovedOp : nullptr;
}
LookupPropertyOp getOpsLookupProperty() const {
js::LookupPropertyOp getOpsLookupProperty() const {
return oOps ? oOps->lookupProperty : nullptr;
}
DefinePropertyOp getOpsDefineProperty() const {
js::DefinePropertyOp getOpsDefineProperty() const {
return oOps ? oOps->defineProperty : nullptr;
}
HasPropertyOp getOpsHasProperty() const {
js::HasPropertyOp getOpsHasProperty() const {
return oOps ? oOps->hasProperty : nullptr;
}
GetPropertyOp getOpsGetProperty() const {
js::GetPropertyOp getOpsGetProperty() const {
return oOps ? oOps->getProperty : nullptr;
}
SetPropertyOp getOpsSetProperty() const {
js::SetPropertyOp getOpsSetProperty() const {
return oOps ? oOps->setProperty : nullptr;
}
GetOwnPropertyOp getOpsGetOwnPropertyDescriptor() const {
js::GetOwnPropertyOp getOpsGetOwnPropertyDescriptor() const {
return oOps ? oOps->getOwnPropertyDescriptor : nullptr;
}
DeletePropertyOp getOpsDeleteProperty() const {
js::DeletePropertyOp getOpsDeleteProperty() const {
return oOps ? oOps->deleteProperty : nullptr;
}
GetElementsOp getOpsGetElements() const {
js::GetElementsOp getOpsGetElements() const {
return oOps ? oOps->getElements : nullptr;
}
JSFunToStringOp getOpsFunToString() const {
@ -953,14 +939,12 @@ struct MOZ_STATIC_CLASS Class {
}
};
static_assert(offsetof(JSClass, name) == offsetof(Class, name),
"Class and JSClass must be consistent");
static_assert(offsetof(JSClass, flags) == offsetof(Class, flags),
"Class and JSClass must be consistent");
static_assert(offsetof(JSClass, cOps) == offsetof(Class, cOps),
"Class and JSClass must be consistent");
static_assert(sizeof(JSClass) == sizeof(Class),
"Class and JSClass must be consistent");
// Initializer for unused members of statically initialized JSClass structs.
#define JSCLASS_NO_INTERNAL_MEMBERS \
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
#define JSCLASS_NO_OPTIONAL_MEMBERS 0, 0, 0, 0, 0, JSCLASS_NO_INTERNAL_MEMBERS
namespace js {
static MOZ_ALWAYS_INLINE const JSClass* Jsvalify(const Class* c) {
return (const JSClass*)c;
@ -1006,4 +990,8 @@ JS_FRIEND_API bool HasObjectMovedOp(JSObject* obj);
} /* namespace js */
// Alias these into global scope for now.
using js::Jsvalify;
using js::Valueify;
#endif /* js_Class_h */

Просмотреть файл

@ -26,6 +26,7 @@ typedef uint8_t jsbytecode;
class JSAtom;
struct JSContext;
struct JSClass;
class JSFunction;
class JSFreeOp;
class JSObject;
@ -35,6 +36,7 @@ class JSString;
namespace js {
class TempAllocPolicy;
using Class = JSClass;
}; // namespace js
namespace JS {

Просмотреть файл

@ -1048,7 +1048,9 @@ pub static SIMPLE_GLOBAL_CLASS: JSClass = JSClass {
name: b"Global\0" as *const u8 as *const _,
flags: (JSCLASS_IS_GLOBAL | ((JSCLASS_GLOBAL_SLOT_COUNT & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)) as u32,
cOps: &SIMPLE_GLOBAL_CLASS_OPS as *const JSClassOps,
reserved: [0 as *mut _; 3]
spec: 0 as *mut _,
ext: 0 as *mut _,
oOps: 0 as *mut _
};
#[inline]

Просмотреть файл

@ -87,5 +87,7 @@ static CLASS: JSClass = JSClass {
name: b"EventTargetPrototype\0" as *const u8 as *const libc::c_char,
flags: 0,
cOps: 0 as *const _,
reserved: [0 as *mut _; 3]
spec: 0 as *mut _,
ext: 0 as *mut _,
oOps: 0 as *mut _
};

Просмотреть файл

@ -53,5 +53,7 @@ static CLASS: JSClass = JSClass {
name: b"EventTargetPrototype\0" as *const u8 as *const libc::c_char,
flags: 0 | JSCLASS_FOREGROUND_FINALIZE,
cOps: &CLASS_OPS as *const JSClassOps,
reserved: [0 as *mut _; 3]
spec: 0 as *mut _,
ext: 0 as *mut _,
oOps: 0 as *mut _
};

Просмотреть файл

@ -15,7 +15,6 @@
namespace js {
struct Class;
class GlobalObject;
class StringBuffer;

Просмотреть файл

@ -1058,22 +1058,22 @@ JSObject* InitTypedObjectModuleObject(JSContext* cx,
template <>
inline bool JSObject::is<js::SimpleTypeDescr>() const {
return IsSimpleTypeDescrClass(getClass());
return js::IsSimpleTypeDescrClass(getClass());
}
template <>
inline bool JSObject::is<js::ComplexTypeDescr>() const {
return IsComplexTypeDescrClass(getClass());
return js::IsComplexTypeDescrClass(getClass());
}
template <>
inline bool JSObject::is<js::TypeDescr>() const {
return IsTypeDescrClass(getClass());
return js::IsTypeDescrClass(getClass());
}
template <>
inline bool JSObject::is<js::TypedObject>() const {
return IsTypedObjectClass(getClass());
return js::IsTypedObjectClass(getClass());
}
template <>

Просмотреть файл

@ -14,7 +14,6 @@
namespace js {
struct Class;
class GlobalObject;
extern const Class IntlClass;

Просмотреть файл

@ -26,7 +26,6 @@ struct JSContext;
namespace js {
class GlobalObject;
struct Class;
enum class DebuggerEnvironmentType { Declarative, With, Object };

Просмотреть файл

@ -15,8 +15,6 @@ class JSFatInlineString;
namespace js {
struct Class;
// Allocate a new GC thing that's not a JSObject or a string.
//
// After a successful allocation the caller must fully initialize the thing

Просмотреть файл

@ -15,7 +15,6 @@
namespace js {
struct Class;
class GlobalObject;
typedef double (*UnaryFunType)(double);

Просмотреть файл

@ -411,7 +411,6 @@ static_assert(ObjectElements::VALUES_PER_HEADER * sizeof(HeapSlot) ==
extern HeapSlot* const emptyObjectElements;
extern HeapSlot* const emptyObjectElementsShared;
struct Class;
class AutoCheckShapeConsistency;
class GCMarker;
class Shape;

Просмотреть файл

@ -52,7 +52,6 @@ class TempAllocator;
class AutoClearTypeInferenceStateOnOOM;
class AutoSweepBase;
class AutoSweepObjectGroup;
struct Class;
class CompilerConstraintList;
class HeapTypeSetKey;
class LifoAlloc;

Просмотреть файл

@ -14,9 +14,6 @@
#include "js/TypeDecls.h"
namespace js {
struct Class;
}
%}
interface nsIXPConnectWrappedNative;

Просмотреть файл

@ -29,10 +29,6 @@ class nsIException;
class nsIRunnable;
class nsWrapperCache;
namespace js {
struct Class;
} // namespace js
namespace mozilla {
class JSGCThingParticipant : public nsCycleCollectionParticipant {