зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1248865 - Change ArrayBuffer to use ClassSpec. r=bz
This commit is contained in:
Родитель
bc8b0b30ea
Коммит
d3d6b4b949
|
@ -92,7 +92,7 @@
|
|||
real(RuntimeError, 21, InitViaClassSpec, ERROR_CLASP(JSEXN_WASMRUNTIMEERROR)) \
|
||||
real(Iterator, 22, InitLegacyIteratorClass,OCLASP(PropertyIterator)) \
|
||||
real(StopIteration, 23, InitStopIterationClass, OCLASP(StopIteration)) \
|
||||
real(ArrayBuffer, 24, InitArrayBufferClass, &js::ArrayBufferObject::protoClass) \
|
||||
real(ArrayBuffer, 24, InitViaClassSpec, OCLASP(ArrayBuffer)) \
|
||||
real(Int8Array, 25, InitViaClassSpec, TYPED_ARRAY_CLASP(Int8)) \
|
||||
real(Uint8Array, 26, InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8)) \
|
||||
real(Int16Array, 27, InitViaClassSpec, TYPED_ARRAY_CLASP(Int16)) \
|
||||
|
|
|
@ -99,12 +99,31 @@ js::ToClampedIndex(JSContext* cx, HandleValue v, uint32_t length, uint32_t* out)
|
|||
* ArrayBufferObject (base)
|
||||
*/
|
||||
|
||||
const Class ArrayBufferObject::protoClass = {
|
||||
"ArrayBufferPrototype",
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_ArrayBuffer)
|
||||
static const ClassSpec ArrayBufferObjectProtoClassSpec = {
|
||||
DELEGATED_CLASSSPEC(ArrayBufferObject::class_.spec),
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
ClassSpec::IsDelegated
|
||||
};
|
||||
|
||||
const ClassOps ArrayBufferObject::classOps_ = {
|
||||
static const Class ArrayBufferObjectProtoClass = {
|
||||
"ArrayBufferPrototype",
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_ArrayBuffer),
|
||||
JS_NULL_CLASS_OPS,
|
||||
&ArrayBufferObjectProtoClassSpec
|
||||
};
|
||||
|
||||
static JSObject*
|
||||
CreateArrayBufferPrototype(JSContext* cx, JSProtoKey key)
|
||||
{
|
||||
return cx->global()->createBlankPrototype(cx, &ArrayBufferObjectProtoClass);
|
||||
}
|
||||
|
||||
static const ClassOps ArrayBufferObjectClassOps = {
|
||||
nullptr, /* addProperty */
|
||||
nullptr, /* delProperty */
|
||||
nullptr, /* getProperty */
|
||||
|
@ -119,6 +138,38 @@ const ClassOps ArrayBufferObject::classOps_ = {
|
|||
ArrayBufferObject::trace,
|
||||
};
|
||||
|
||||
static const JSFunctionSpec static_functions[] = {
|
||||
JS_FN("isView", ArrayBufferObject::fun_isView, 1, 0),
|
||||
JS_SELF_HOSTED_FN("slice", "ArrayBufferStaticSlice", 3, 0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
static const JSPropertySpec static_properties[] = {
|
||||
JS_SELF_HOSTED_SYM_GET(species, "ArrayBufferSpecies", 0),
|
||||
JS_PS_END
|
||||
};
|
||||
|
||||
|
||||
static const JSFunctionSpec prototype_functions[] = {
|
||||
JS_SELF_HOSTED_FN("slice", "ArrayBufferSlice", 2, 0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
static const JSPropertySpec prototype_properties[] = {
|
||||
JS_PSG("byteLength", ArrayBufferObject::byteLengthGetter, 0),
|
||||
JS_STRING_SYM_PS(toStringTag, "ArrayBuffer", JSPROP_READONLY),
|
||||
JS_PS_END
|
||||
};
|
||||
|
||||
static const ClassSpec ArrayBufferObjectClassSpec = {
|
||||
GenericCreateConstructor<ArrayBufferObject::class_constructor, 1, gc::AllocKind::FUNCTION>,
|
||||
CreateArrayBufferPrototype,
|
||||
static_functions,
|
||||
static_properties,
|
||||
prototype_functions,
|
||||
prototype_properties
|
||||
};
|
||||
|
||||
static const ClassExtension ArrayBufferObjectClassExtension = {
|
||||
nullptr, /* weakmapKeyDelegateOp */
|
||||
ArrayBufferObject::objectMoved
|
||||
|
@ -130,27 +181,11 @@ const Class ArrayBufferObject::class_ = {
|
|||
JSCLASS_HAS_RESERVED_SLOTS(RESERVED_SLOTS) |
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_ArrayBuffer) |
|
||||
JSCLASS_BACKGROUND_FINALIZE,
|
||||
&ArrayBufferObject::classOps_,
|
||||
JS_NULL_CLASS_SPEC,
|
||||
&ArrayBufferObjectClassOps,
|
||||
&ArrayBufferObjectClassSpec,
|
||||
&ArrayBufferObjectClassExtension
|
||||
};
|
||||
|
||||
const JSFunctionSpec ArrayBufferObject::jsfuncs[] = {
|
||||
JS_SELF_HOSTED_FN("slice", "ArrayBufferSlice", 2,0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
const JSFunctionSpec ArrayBufferObject::jsstaticfuncs[] = {
|
||||
JS_FN("isView", ArrayBufferObject::fun_isView, 1, 0),
|
||||
JS_SELF_HOSTED_FN("slice", "ArrayBufferStaticSlice", 3,0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
const JSPropertySpec ArrayBufferObject::jsstaticprops[] = {
|
||||
JS_SELF_HOSTED_SYM_GET(species, "ArrayBufferSpecies", 0),
|
||||
JS_PS_END
|
||||
};
|
||||
|
||||
bool
|
||||
js::IsArrayBuffer(HandleValue v)
|
||||
{
|
||||
|
@ -1886,62 +1921,3 @@ js::GetArrayBufferLengthAndData(JSObject* obj, uint32_t* length, bool* isSharedM
|
|||
*data = AsArrayBuffer(obj).dataPointer();
|
||||
*isSharedMemory = false;
|
||||
}
|
||||
|
||||
JSObject*
|
||||
js::InitArrayBufferClass(JSContext* cx, HandleObject obj)
|
||||
{
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, obj);
|
||||
|
||||
Rooted<GlobalObject*> global(cx, cx->compartment()->maybeGlobal());
|
||||
if (global->isStandardClassResolved(JSProto_ArrayBuffer))
|
||||
return &global->getPrototype(JSProto_ArrayBuffer).toObject();
|
||||
|
||||
RootedNativeObject arrayBufferProto(cx, global->createBlankPrototype(cx, &ArrayBufferObject::protoClass));
|
||||
if (!arrayBufferProto)
|
||||
return nullptr;
|
||||
|
||||
RootedFunction ctor(cx, global->createConstructor(cx, ArrayBufferObject::class_constructor,
|
||||
cx->names().ArrayBuffer, 1));
|
||||
if (!ctor)
|
||||
return nullptr;
|
||||
|
||||
if (!LinkConstructorAndPrototype(cx, ctor, arrayBufferProto))
|
||||
return nullptr;
|
||||
|
||||
RootedId byteLengthId(cx, NameToId(cx->names().byteLength));
|
||||
RootedAtom atom(cx, IdToFunctionName(cx, byteLengthId, "get"));
|
||||
if (!atom)
|
||||
return nullptr;
|
||||
unsigned attrs = JSPROP_SHARED | JSPROP_GETTER;
|
||||
JSObject* getter =
|
||||
NewNativeFunction(cx, ArrayBufferObject::byteLengthGetter, 0, atom);
|
||||
if (!getter)
|
||||
return nullptr;
|
||||
|
||||
if (!NativeDefineProperty(cx, arrayBufferProto, byteLengthId, UndefinedHandleValue,
|
||||
JS_DATA_TO_FUNC_PTR(GetterOp, getter), nullptr, attrs))
|
||||
return nullptr;
|
||||
|
||||
if (!JS_DefineFunctions(cx, ctor, ArrayBufferObject::jsstaticfuncs))
|
||||
return nullptr;
|
||||
|
||||
if (!JS_DefineProperties(cx, ctor, ArrayBufferObject::jsstaticprops))
|
||||
return nullptr;
|
||||
|
||||
if (!JS_DefineFunctions(cx, arrayBufferProto, ArrayBufferObject::jsfuncs))
|
||||
return nullptr;
|
||||
|
||||
if (!DefineToStringTag(cx, arrayBufferProto, cx->names().ArrayBuffer))
|
||||
return nullptr;
|
||||
|
||||
if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_ArrayBuffer,
|
||||
ctor, arrayBufferProto))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return arrayBufferProto;
|
||||
}
|
||||
|
||||
|
|
|
@ -131,8 +131,6 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared
|
|||
static bool byteLengthGetterImpl(JSContext* cx, const CallArgs& args);
|
||||
static bool fun_slice_impl(JSContext* cx, const CallArgs& args);
|
||||
|
||||
static const ClassOps classOps_;
|
||||
|
||||
public:
|
||||
static const uint8_t DATA_SLOT = 0;
|
||||
static const uint8_t BYTE_LENGTH_SLOT = 1;
|
||||
|
@ -232,11 +230,6 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared
|
|||
|
||||
static const Class class_;
|
||||
|
||||
static const Class protoClass;
|
||||
static const JSFunctionSpec jsfuncs[];
|
||||
static const JSFunctionSpec jsstaticfuncs[];
|
||||
static const JSPropertySpec jsstaticprops[];
|
||||
|
||||
static bool byteLengthGetter(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
static bool fun_slice(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
@ -635,9 +628,6 @@ class WeakCacheBase<InnerViewTable>
|
|||
}
|
||||
};
|
||||
|
||||
extern JSObject*
|
||||
InitArrayBufferClass(JSContext* cx, HandleObject obj);
|
||||
|
||||
} // namespace js
|
||||
|
||||
template <>
|
||||
|
|
Загрузка…
Ссылка в новой задаче