зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1595745 - Part 11: Change TypedObject to use ClassSpec. r=mgaudet
Differential Revision: https://phabricator.services.mozilla.com/D52667 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8d8f78e33b
Коммит
4be8805674
|
@ -102,8 +102,7 @@
|
|||
REAL_IF_INTL(PluralRules, InitViaClassSpec, OCLASP(PluralRules)) \
|
||||
REAL_IF_INTL(RelativeTimeFormat, InitViaClassSpec, \
|
||||
OCLASP(RelativeTimeFormat)) \
|
||||
REAL_IF_BDATA(TypedObject, InitTypedObjectModuleObject, \
|
||||
OCLASP(TypedObjectModule)) \
|
||||
REAL_IF_BDATA(TypedObject, InitViaClassSpec, OCLASP(TypedObjectModule)) \
|
||||
REAL(Reflect, InitViaClassSpec, CLASP(Reflect)) \
|
||||
REAL(WeakSet, InitViaClassSpec, OCLASP(WeakSet)) \
|
||||
REAL(TypedArray, InitViaClassSpec, \
|
||||
|
|
|
@ -40,8 +40,10 @@ using mozilla::PointerRangeSize;
|
|||
using namespace js;
|
||||
|
||||
const JSClass js::TypedObjectModuleObject::class_ = {
|
||||
"TypedObject", JSCLASS_HAS_RESERVED_SLOTS(SlotCount) |
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_TypedObject)};
|
||||
"TypedObject",
|
||||
JSCLASS_HAS_RESERVED_SLOTS(SlotCount) |
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_TypedObject),
|
||||
JS_NULL_CLASS_OPS, &classSpec_};
|
||||
|
||||
static const JSFunctionSpec TypedObjectMethods[] = {
|
||||
JS_SELF_HOSTED_FN("objectType", "TypeOfTypedObject", 1, 0), JS_FS_END};
|
||||
|
@ -1363,31 +1365,28 @@ static JSObject* DefineMetaTypeDescr(JSContext* cx, const char* name,
|
|||
return ctor;
|
||||
}
|
||||
|
||||
static JSObject* CreateTypedObjectModuleObject(JSContext* cx, JSProtoKey key) {
|
||||
Handle<GlobalObject*> global = cx->global();
|
||||
RootedObject objProto(cx,
|
||||
GlobalObject::getOrCreateObjectPrototype(cx, global));
|
||||
if (!objProto) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return NewObjectWithGivenProto<TypedObjectModuleObject>(cx, objProto,
|
||||
SingletonObject);
|
||||
}
|
||||
|
||||
/* The initialization strategy for TypedObjects is mildly unusual
|
||||
* compared to other classes. Because all of the types are members
|
||||
* of a single global, `TypedObject`, we basically make the
|
||||
* initializer for the `TypedObject` class populate the
|
||||
* `TypedObject` global (which is referred to as "module" herein).
|
||||
*/
|
||||
/* static */
|
||||
bool GlobalObject::initTypedObjectModule(JSContext* cx,
|
||||
Handle<GlobalObject*> global) {
|
||||
RootedObject objProto(cx,
|
||||
GlobalObject::getOrCreateObjectPrototype(cx, global));
|
||||
if (!objProto) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Rooted<TypedObjectModuleObject*> module(cx);
|
||||
module = NewObjectWithGivenProto<TypedObjectModuleObject>(cx, objProto,
|
||||
SingletonObject);
|
||||
if (!module) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!JS_DefineFunctions(cx, module, TypedObjectMethods)) {
|
||||
return false;
|
||||
}
|
||||
static bool TypedObjectModuleObjectClassFinish(JSContext* cx, HandleObject ctor,
|
||||
HandleObject proto) {
|
||||
Handle<TypedObjectModuleObject*> module = ctor.as<TypedObjectModuleObject>();
|
||||
Handle<GlobalObject*> global = cx->global();
|
||||
|
||||
// uint8, uint16, any, etc
|
||||
|
||||
|
@ -1475,22 +1474,17 @@ bool GlobalObject::initTypedObjectModule(JSContext* cx,
|
|||
return false;
|
||||
}
|
||||
|
||||
// Everything is setup, install module on the global object:
|
||||
RootedValue moduleValue(cx, ObjectValue(*module));
|
||||
if (!DefineDataProperty(cx, global, cx->names().TypedObject, moduleValue,
|
||||
JSPROP_RESOLVING)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global->setConstructor(JSProto_TypedObject, moduleValue);
|
||||
|
||||
return module;
|
||||
return true;
|
||||
}
|
||||
|
||||
JSObject* js::InitTypedObjectModuleObject(JSContext* cx,
|
||||
Handle<GlobalObject*> global) {
|
||||
return GlobalObject::getOrCreateTypedObjectModule(cx, global);
|
||||
}
|
||||
const ClassSpec TypedObjectModuleObject::classSpec_ = {
|
||||
CreateTypedObjectModuleObject,
|
||||
nullptr,
|
||||
TypedObjectMethods,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
TypedObjectModuleObjectClassFinish};
|
||||
|
||||
/******************************************************************************
|
||||
* Typed objects
|
||||
|
|
|
@ -94,8 +94,6 @@
|
|||
|
||||
namespace js {
|
||||
|
||||
class GlobalObject;
|
||||
|
||||
/*
|
||||
* Helper method for converting a double into other scalar
|
||||
* types in the same way that JavaScript would. In particular,
|
||||
|
@ -535,6 +533,9 @@ class TypedObjectModuleObject : public NativeObject {
|
|||
};
|
||||
|
||||
static const JSClass class_;
|
||||
|
||||
private:
|
||||
static const ClassSpec classSpec_;
|
||||
};
|
||||
|
||||
/* Base type for transparent and opaque typed objects. */
|
||||
|
@ -1051,9 +1052,6 @@ inline bool TypedObject::opaque() const {
|
|||
return IsOpaqueTypedObjectClass(getClass());
|
||||
}
|
||||
|
||||
JSObject* InitTypedObjectModuleObject(JSContext* cx,
|
||||
JS::Handle<GlobalObject*> global);
|
||||
|
||||
} // namespace js
|
||||
|
||||
template <>
|
||||
|
|
|
@ -455,9 +455,7 @@ class GlobalObject : public NativeObject {
|
|||
|
||||
static JSObject* getOrCreateTypedObjectModule(JSContext* cx,
|
||||
Handle<GlobalObject*> global) {
|
||||
return getOrCreateObject(cx, global,
|
||||
APPLICATION_SLOTS + JSProto_TypedObject,
|
||||
initTypedObjectModule);
|
||||
return getOrCreateConstructor(cx, JSProto_TypedObject);
|
||||
}
|
||||
|
||||
static TypeDescr* getOrCreateScalarTypeDescr(JSContext* cx,
|
||||
|
|
Загрузка…
Ссылка в новой задаче