Bug 898356 Part 8 -- Rename from Datum to TypedObject (or typedObj) r=sfink

This commit is contained in:
Nicholas D. Matsakis 2014-02-12 11:46:51 -05:00
parent d5cd75c9f8
commit 1d8aa6f55b
15 changed files with 515 additions and 504 deletions

View File

@ -39,14 +39,14 @@ extern const JSFunctionSpec Int32x4Methods[];
bool Type32x4##Lane##lane(JSContext *cx, unsigned argc, Value *vp) { \
static const char *laneNames[] = {"lane 0", "lane 1", "lane 2", "lane3"}; \
CallArgs args = CallArgsFromVp(argc, vp); \
if(!args.thisv().isObject() || !args.thisv().toObject().is<TypedDatum>()) { \
if(!args.thisv().isObject() || !args.thisv().toObject().is<TypedObject>()) { \
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, \
X4TypeDescr::class_.name, laneNames[lane], \
InformalValueTypeName(args.thisv())); \
return false; \
} \
TypedDatum &datum = args.thisv().toObject().as<TypedDatum>(); \
TypeDescr &descr = datum.typeDescr(); \
TypedObject &typedObj = args.thisv().toObject().as<TypedObject>(); \
TypeDescr &descr = typedObj.typeDescr(); \
if (descr.kind() != TypeDescr::X4 || \
descr.as<X4TypeDescr>().type() != Type32x4::type) \
{ \
@ -55,7 +55,7 @@ extern const JSFunctionSpec Int32x4Methods[];
InformalValueTypeName(args.thisv())); \
return false; \
} \
Type32x4::Elem *data = reinterpret_cast<Type32x4::Elem *>(datum.typedMem()); \
Type32x4::Elem *data = reinterpret_cast<Type32x4::Elem *>(typedObj.typedMem()); \
Type32x4::setReturn(args, data[lane]); \
return true; \
}
@ -72,14 +72,14 @@ extern const JSFunctionSpec Int32x4Methods[];
#define SIGN_MASK(Type32x4) \
bool Type32x4##SignMask(JSContext *cx, unsigned argc, Value *vp) { \
CallArgs args = CallArgsFromVp(argc, vp); \
if(!args.thisv().isObject() || !args.thisv().toObject().is<TypedDatum>()) { \
if(!args.thisv().isObject() || !args.thisv().toObject().is<TypedObject>()) { \
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, \
X4TypeDescr::class_.name, "signMask", \
InformalValueTypeName(args.thisv())); \
return false; \
} \
TypedDatum &datum = args.thisv().toObject().as<TypedDatum>(); \
TypeDescr &descr = datum.typeDescr(); \
TypedObject &typedObj = args.thisv().toObject().as<TypedObject>(); \
TypeDescr &descr = typedObj.typeDescr(); \
if (descr.kind() != TypeDescr::X4 || \
descr.as<X4TypeDescr>().type() != Type32x4::type) \
{ \
@ -88,7 +88,7 @@ extern const JSFunctionSpec Int32x4Methods[];
InformalValueTypeName(args.thisv())); \
return false; \
} \
Type32x4::Elem *data = reinterpret_cast<Type32x4::Elem *>(datum.typedMem()); \
Type32x4::Elem *data = reinterpret_cast<Type32x4::Elem *>(typedObj.typedMem()); \
int32_t mx = data[0] < 0.0 ? 1 : 0; \
int32_t my = data[1] < 0.0 ? 1 : 0; \
int32_t mz = data[2] < 0.0 ? 1 : 0; \
@ -124,15 +124,15 @@ class Int32x4Defn {
public:
static const X4TypeDescr::Type type = X4TypeDescr::TYPE_INT32;
static const JSFunctionSpec TypeDescriptorMethods[];
static const JSPropertySpec TypedDatumProperties[];
static const JSFunctionSpec TypedDatumMethods[];
static const JSPropertySpec TypedObjectProperties[];
static const JSFunctionSpec TypedObjectMethods[];
};
class Float32x4Defn {
public:
static const X4TypeDescr::Type type = X4TypeDescr::TYPE_FLOAT32;
static const JSFunctionSpec TypeDescriptorMethods[];
static const JSPropertySpec TypedDatumProperties[];
static const JSFunctionSpec TypedDatumMethods[];
static const JSPropertySpec TypedObjectProperties[];
static const JSFunctionSpec TypedObjectMethods[];
};
} // namespace js
@ -143,7 +143,7 @@ const JSFunctionSpec js::Float32x4Defn::TypeDescriptorMethods[] = {
JS_FS_END
};
const JSPropertySpec js::Float32x4Defn::TypedDatumProperties[] = {
const JSPropertySpec js::Float32x4Defn::TypedObjectProperties[] = {
JS_PSG("x", Float32x4Lane0, JSPROP_PERMANENT),
JS_PSG("y", Float32x4Lane1, JSPROP_PERMANENT),
JS_PSG("z", Float32x4Lane2, JSPROP_PERMANENT),
@ -152,7 +152,7 @@ const JSPropertySpec js::Float32x4Defn::TypedDatumProperties[] = {
JS_PS_END
};
const JSFunctionSpec js::Float32x4Defn::TypedDatumMethods[] = {
const JSFunctionSpec js::Float32x4Defn::TypedObjectMethods[] = {
JS_SELF_HOSTED_FN("toSource", "X4ToSource", 0, 0),
JS_FS_END
};
@ -164,7 +164,7 @@ const JSFunctionSpec js::Int32x4Defn::TypeDescriptorMethods[] = {
JS_FS_END,
};
const JSPropertySpec js::Int32x4Defn::TypedDatumProperties[] = {
const JSPropertySpec js::Int32x4Defn::TypedObjectProperties[] = {
JS_PSG("x", Int32x4Lane0, JSPROP_PERMANENT),
JS_PSG("y", Int32x4Lane1, JSPROP_PERMANENT),
JS_PSG("z", Int32x4Lane2, JSPROP_PERMANENT),
@ -173,7 +173,7 @@ const JSPropertySpec js::Int32x4Defn::TypedDatumProperties[] = {
JS_PS_END
};
const JSFunctionSpec js::Int32x4Defn::TypedDatumMethods[] = {
const JSFunctionSpec js::Int32x4Defn::TypedObjectMethods[] = {
JS_SELF_HOSTED_FN("toSource", "X4ToSource", 0, 0),
JS_FS_END
};
@ -218,8 +218,8 @@ CreateX4Class(JSContext *cx, Handle<GlobalObject*> global)
return nullptr;
if (!LinkConstructorAndPrototype(cx, x4, proto) ||
!DefinePropertiesAndBrand(cx, proto, T::TypedDatumProperties,
T::TypedDatumMethods))
!DefinePropertiesAndBrand(cx, proto, T::TypedObjectProperties,
T::TypedObjectMethods))
{
return nullptr;
}
@ -246,7 +246,7 @@ X4TypeDescr::call(JSContext *cx, unsigned argc, Value *vp)
}
Rooted<X4TypeDescr*> descr(cx, &args.callee().as<X4TypeDescr>());
Rooted<TypedDatum*> result(cx, TypedDatum::createZeroed(cx, descr, 0));
Rooted<TypedObject*> result(cx, TypedObject::createZeroed(cx, descr, 0));
if (!result)
return false;
@ -366,9 +366,9 @@ js_InitSIMDClass(JSContext *cx, HandleObject obj)
template<typename V>
static bool
ObjectIsVector(JSObject &obj) {
if (!obj.is<TypedDatum>())
if (!obj.is<TypedObject>())
return false;
TypeDescr &typeRepr = obj.as<TypedDatum>().typeDescr();
TypeDescr &typeRepr = obj.as<TypedObject>().typeDescr();
if (typeRepr.kind() != TypeDescr::X4)
return false;
return typeRepr.as<X4TypeDescr>().type() == V::type;
@ -381,7 +381,7 @@ js::Create(JSContext *cx, typename V::Elem *data)
Rooted<TypeDescr*> typeDescr(cx, &V::GetTypeDescr(*cx->global()));
JS_ASSERT(typeDescr);
Rooted<TypedDatum *> result(cx, TypedDatum::createZeroed(cx, typeDescr, 0));
Rooted<TypedObject *> result(cx, TypedObject::createZeroed(cx, typeDescr, 0));
if (!result)
return nullptr;
@ -533,7 +533,7 @@ Func(JSContext *cx, unsigned argc, Value *vp)
}
typename V::Elem *val =
reinterpret_cast<typename V::Elem *>(
args[0].toObject().as<TypedDatum>().typedMem());
args[0].toObject().as<TypedObject>().typedMem());
typename Vret::Elem result[Vret::lanes];
for (int32_t i = 0; i < Vret::lanes; i++)
result[i] = Op::apply(val[i], 0);
@ -555,10 +555,10 @@ Func(JSContext *cx, unsigned argc, Value *vp)
typename V::Elem *left =
reinterpret_cast<typename V::Elem *>(
args[0].toObject().as<TypedDatum>().typedMem());
args[0].toObject().as<TypedObject>().typedMem());
typename V::Elem *right =
reinterpret_cast<typename V::Elem *>(
args[1].toObject().as<TypedDatum>().typedMem());
args[1].toObject().as<TypedObject>().typedMem());
typename Vret::Elem result[Vret::lanes];
for (int32_t i = 0; i < Vret::lanes; i++)
@ -592,7 +592,7 @@ FuncWith(JSContext *cx, unsigned argc, Value *vp)
typename V::Elem *val =
reinterpret_cast<typename V::Elem *>(
args[0].toObject().as<TypedDatum>().typedMem());
args[0].toObject().as<TypedObject>().typedMem());
typename Vret::Elem result[Vret::lanes];
for (int32_t i = 0; i < Vret::lanes; i++) {
@ -628,7 +628,7 @@ FuncShuffle(JSContext *cx, unsigned argc, Value *vp)
typename V::Elem *val =
reinterpret_cast<typename V::Elem *>(
args[0].toObject().as<TypedDatum>().typedMem());
args[0].toObject().as<TypedObject>().typedMem());
typename Vret::Elem result[Vret::lanes];
for (int32_t i = 0; i < Vret::lanes; i++) {
typename Vret::Elem arg1;
@ -651,10 +651,10 @@ FuncShuffle(JSContext *cx, unsigned argc, Value *vp)
}
typename V::Elem *val1 =
reinterpret_cast<typename V::Elem *>(
args[0].toObject().as<TypedDatum>().typedMem());
args[0].toObject().as<TypedObject>().typedMem());
typename V::Elem *val2 =
reinterpret_cast<typename V::Elem *>(
args[1].toObject().as<TypedDatum>().typedMem());
args[1].toObject().as<TypedObject>().typedMem());
typename Vret::Elem result[Vret::lanes];
for (int32_t i = 0; i < Vret::lanes; i++) {
typename Vret::Elem arg2;
@ -691,7 +691,7 @@ FuncConvert(JSContext *cx, unsigned argc, Value *vp)
}
typename V::Elem *val =
reinterpret_cast<typename V::Elem *>(
args[0].toObject().as<TypedDatum>().typedMem());
args[0].toObject().as<TypedObject>().typedMem());
typename Vret::Elem result[Vret::lanes];
for (int32_t i = 0; i < Vret::lanes; i++)
result[i] = static_cast<typename Vret::Elem>(val[i]);
@ -718,7 +718,7 @@ FuncConvertBits(JSContext *cx, unsigned argc, Value *vp)
}
typename Vret::Elem *val =
reinterpret_cast<typename Vret::Elem *>(
args[0].toObject().as<TypedDatum>().typedMem());
args[0].toObject().as<TypedObject>().typedMem());
RootedObject obj(cx, Create<Vret>(cx, val));
if (!obj)
@ -813,11 +813,11 @@ Float32x4Clamp(JSContext *cx, unsigned argc, Value *vp)
return false;
}
float *val = reinterpret_cast<float *>(
args[0].toObject().as<TypedDatum>().typedMem());
args[0].toObject().as<TypedObject>().typedMem());
float *lowerLimit = reinterpret_cast<float *>(
args[1].toObject().as<TypedDatum>().typedMem());
args[1].toObject().as<TypedObject>().typedMem());
float *upperLimit = reinterpret_cast<float *>(
args[2].toObject().as<TypedDatum>().typedMem());
args[2].toObject().as<TypedObject>().typedMem());
float result[Float32x4::lanes];
result[0] = val[0] < lowerLimit[0] ? lowerLimit[0] : val[0];
@ -850,11 +850,11 @@ Int32x4Select(JSContext *cx, unsigned argc, Value *vp)
return false;
}
int32_t *val = reinterpret_cast<int32_t *>(
args[0].toObject().as<TypedDatum>().typedMem());
args[0].toObject().as<TypedObject>().typedMem());
int32_t *tv = reinterpret_cast<int32_t *>(
args[1].toObject().as<TypedDatum>().typedMem());
args[1].toObject().as<TypedObject>().typedMem());
int32_t *fv = reinterpret_cast<int32_t *>(
args[2].toObject().as<TypedDatum>().typedMem());
args[2].toObject().as<TypedObject>().typedMem());
int32_t tr[Int32x4::lanes];
for (int32_t i = 0; i < Int32x4::lanes; i++)
tr[i] = And<int32_t, Int32x4>::apply(val[i], tv[i]);

File diff suppressed because it is too large Load Diff

View File

@ -57,23 +57,33 @@
* engine and are not exposed to end users (though self-hosted code
* sometimes accesses them).
*
* - Typed datums, objects, and handles:
* - Typed objects:
*
* A typed object is an instance of a type object. A handle is a
* relocatable pointer that points into other typed objects. Both of them
* are basically represented the same way, though they have distinct
* js::Class entries. They are both subtypes of `TypedDatum`.
* A typed object is an instance of a *type object* (note the past
* participle). There is one class for *transparent* typed objects and
* one for *opaque* typed objects. These classes are equivalent in
* basically every way, except that requesting the backing buffer of
* an opaque typed object yields null. We use distinct js::Classes to
* avoid the need for an extra slot in every typed object.
*
* Both typed objects and handles are non-native objects that fully
* override the property accessors etc. The overridden accessor
* Note that whether a typed object is opaque is not directly
* connected to its type. That is, opaque types are *always*
* represented by opaque typed objects, but you may have opaque typed
* objects for transparent types too. This can occur for two reasons:
* (1) a transparent type may be embedded within an opaque type or (2)
* users can choose to convert transparent typed objects into opaque
* ones to avoid giving access to the buffer itself.
*
* Typed objects (no matter their class) are non-native objects that
* fully override the property accessors etc. The overridden accessor
* methods are the same in each and are defined in methods of
* TypedDatum.
* TypedObject.
*
* Typed datums may be attached or unattached. An unattached typed
* datum has no memory associated with it; it is basically a null
* pointer. This can only happen when a new handle is created, since
* typed object instances are always associated with memory at the
* point of creation.
* Typed objects may be attached or unattached. An unattached typed
* object has no memory associated with it; it is basically a null
* pointer. When first created, objects are always attached, but they
* can become unattached if their buffer is neutered (note that this
* implies that typed objects of opaque types can never be unattached).
*
* When a new typed object instance is created, fresh memory is
* allocated and set as that typed object's private field. The object
@ -254,21 +264,21 @@ typedef Handle<StructTypeDescr*> HandleStructTypeDescr;
* Base type for typed objects and handles. Basically any type whose
* contents consist of typed memory.
*/
class TypedDatum : public ArrayBufferViewObject
class TypedObject : public ArrayBufferViewObject
{
private:
static const bool IsTypedDatumClass = true;
static const bool IsTypedObjectClass = true;
template<class T>
static bool obj_getArrayElement(JSContext *cx,
Handle<TypedDatum*> datum,
Handle<TypedObject*> typedObj,
Handle<TypeDescr*> typeDescr,
uint32_t index,
MutableHandleValue vp);
template<class T>
static bool obj_setArrayElement(JSContext *cx,
Handle<TypedDatum*> datum,
Handle<TypedObject*> typedObj,
Handle<TypeDescr*> typeDescr,
uint32_t index,
MutableHandleValue vp);
@ -356,7 +366,7 @@ class TypedDatum : public ArrayBufferViewObject
static size_t dataOffset();
// Helper for createUnattached()
static TypedDatum *createUnattachedWithClass(JSContext *cx,
static TypedObject *createUnattachedWithClass(JSContext *cx,
const Class *clasp,
HandleTypeDescr type,
int32_t length);
@ -369,27 +379,27 @@ class TypedDatum : public ArrayBufferViewObject
// Arguments:
// - type: type object for resulting object
// - length: 0 unless this is an array, otherwise the length
static TypedDatum *createUnattached(JSContext *cx, HandleTypeDescr type,
static TypedObject *createUnattached(JSContext *cx, HandleTypeDescr type,
int32_t length);
// Creates a datum that aliases the memory pointed at by `owner`
// at the given offset. The datum will be a handle iff type is a
// Creates a typedObj that aliases the memory pointed at by `owner`
// at the given offset. The typedObj will be a handle iff type is a
// handle and a typed object otherwise.
static TypedDatum *createDerived(JSContext *cx,
static TypedObject *createDerived(JSContext *cx,
HandleSizedTypeDescr type,
Handle<TypedDatum*> typedContents,
Handle<TypedObject*> typedContents,
size_t offset);
// Creates a new typed object whose memory is freshly allocated
// and initialized with zeroes (or, in the case of references, an
// appropriate default value).
static TypedDatum *createZeroed(JSContext *cx,
static TypedObject *createZeroed(JSContext *cx,
HandleTypeDescr typeObj,
int32_t length);
// User-accessible constructor (`new TypeDescriptor(...)`)
// used for sized types. Note that the callee here is the *type descriptor*,
// not the datum.
// not the typedObj.
static bool constructSized(JSContext *cx, unsigned argc, Value *vp);
// As `constructSized`, but for unsized array types.
@ -398,22 +408,22 @@ class TypedDatum : public ArrayBufferViewObject
// Use this method when `buffer` is the owner of the memory.
void attach(ArrayBufferObject &buffer, int32_t offset);
// Otherwise, use this to attach to memory referenced by another datum.
void attach(TypedDatum &datum, int32_t offset);
// Otherwise, use this to attach to memory referenced by another typedObj.
void attach(TypedObject &typedObj, int32_t offset);
// Invoked when array buffer is transferred elsewhere
void neuter(JSContext *cx);
int32_t offset() const {
return getReservedSlot(JS_DATUM_SLOT_BYTEOFFSET).toInt32();
return getReservedSlot(JS_TYPEDOBJ_SLOT_BYTEOFFSET).toInt32();
}
ArrayBufferObject &owner() const {
return getReservedSlot(JS_DATUM_SLOT_OWNER).toObject().as<ArrayBufferObject>();
return getReservedSlot(JS_TYPEDOBJ_SLOT_OWNER).toObject().as<ArrayBufferObject>();
}
TypeDescr &typeDescr() const {
return getReservedSlot(JS_DATUM_SLOT_TYPE_DESCR).toObject().as<TypeDescr>();
return getReservedSlot(JS_TYPEDOBJ_SLOT_TYPE_DESCR).toObject().as<TypeDescr>();
}
TypeRepresentation *typeRepresentation() const {
@ -425,7 +435,7 @@ class TypedDatum : public ArrayBufferViewObject
}
size_t length() const {
return getReservedSlot(JS_DATUM_SLOT_LENGTH).toInt32();
return getReservedSlot(JS_TYPEDOBJ_SLOT_LENGTH).toInt32();
}
size_t size() const {
@ -456,9 +466,9 @@ class TypedDatum : public ArrayBufferViewObject
}
};
typedef Handle<TypedDatum*> HandleTypedDatum;
typedef Handle<TypedObject*> HandleTypedObject;
class TransparentTypedObject : public TypedDatum
class TransparentTypedObject : public TypedObject
{
public:
static const Class class_;
@ -466,7 +476,7 @@ class TransparentTypedObject : public TypedDatum
typedef Handle<TransparentTypedObject*> HandleTransparentTypedObject;
class OpaqueTypedObject : public TypedDatum
class OpaqueTypedObject : public TypedObject
{
public:
static const Class class_;
@ -481,20 +491,20 @@ class OpaqueTypedObject : public TypedDatum
bool NewOpaqueTypedObject(JSContext *cx, unsigned argc, Value *vp);
/*
* Usage: NewDerivedTypedDatum(typeObj, owner, offset)
* Usage: NewDerivedTypedObject(typeObj, owner, offset)
*
* Constructs a new, unattached instance of `Handle`.
*/
bool NewDerivedTypedDatum(JSContext *cx, unsigned argc, Value *vp);
bool NewDerivedTypedObject(JSContext *cx, unsigned argc, Value *vp);
/*
* Usage: AttachDatum(datum, newDatum, newOffset)
* Usage: AttachTypedObject(typedObj, newDatum, newOffset)
*
* Moves `datum` to point at the memory referenced by `newDatum` with
* Moves `typedObj` to point at the memory referenced by `newDatum` with
* the offset `newOffset`.
*/
bool AttachDatum(ThreadSafeContext *cx, unsigned argc, Value *vp);
extern const JSJitInfo AttachDatumJitInfo;
bool AttachTypedObject(ThreadSafeContext *cx, unsigned argc, Value *vp);
extern const JSJitInfo AttachTypedObjectJitInfo;
/*
* Usage: ObjectIsTypeDescr(obj)
@ -521,13 +531,13 @@ bool ObjectIsTransparentTypedObject(ThreadSafeContext *cx, unsigned argc, Value
extern const JSJitInfo ObjectIsTransparentTypedObjectJitInfo;
/*
* Usage: DatumIsAttached(obj)
* Usage: TypedObjectIsAttached(obj)
*
* Given a TypedDatum `obj`, returns true if `obj` is
* Given a TypedObject `obj`, returns true if `obj` is
* "attached" (i.e., its data pointer is nullptr).
*/
bool DatumIsAttached(ThreadSafeContext *cx, unsigned argc, Value *vp);
extern const JSJitInfo DatumIsAttachedJitInfo;
bool TypedObjectIsAttached(ThreadSafeContext *cx, unsigned argc, Value *vp);
extern const JSJitInfo TypedObjectIsAttachedJitInfo;
/*
* Usage: ClampToUint8(v)
@ -665,7 +675,7 @@ JS_FOR_EACH_REFERENCE_TYPE_REPR(JS_STORE_REFERENCE_CLASS_DEFN)
JS_FOR_EACH_REFERENCE_TYPE_REPR(JS_LOAD_REFERENCE_CLASS_DEFN)
inline bool
IsTypedDatumClass(const Class *class_)
IsTypedObjectClass(const Class *class_)
{
return class_ == &TransparentTypedObject::class_ ||
class_ == &OpaqueTypedObject::class_;
@ -704,9 +714,9 @@ JSObject::is<js::TypeDescr>() const
template <>
inline bool
JSObject::is<js::TypedDatum>() const
JSObject::is<js::TypedObject>() const
{
return IsTypedDatumClass(getClass());
return IsTypedObjectClass(getClass());
}
#endif /* builtin_TypedObject_h */

View File

@ -29,23 +29,23 @@
// Typed object slots
#define DATUM_BYTEOFFSET(obj) \
TO_INT32(UnsafeGetReservedSlot(obj, JS_DATUM_SLOT_BYTEOFFSET))
#define DATUM_BYTELENGTH(obj) \
TO_INT32(UnsafeGetReservedSlot(obj, JS_DATUM_SLOT_BYTELENGTH))
#define DATUM_TYPE_DESCR(obj) \
UnsafeGetReservedSlot(obj, JS_DATUM_SLOT_TYPE_DESCR)
#define DATUM_OWNER(obj) \
UnsafeGetReservedSlot(obj, JS_DATUM_SLOT_OWNER)
#define DATUM_LENGTH(obj) \
TO_INT32(UnsafeGetReservedSlot(obj, JS_DATUM_SLOT_LENGTH))
#define TYPEDOBJ_BYTEOFFSET(obj) \
TO_INT32(UnsafeGetReservedSlot(obj, JS_TYPEDOBJ_SLOT_BYTEOFFSET))
#define TYPEDOBJ_BYTELENGTH(obj) \
TO_INT32(UnsafeGetReservedSlot(obj, JS_TYPEDOBJ_SLOT_BYTELENGTH))
#define TYPEDOBJ_TYPE_DESCR(obj) \
UnsafeGetReservedSlot(obj, JS_TYPEDOBJ_SLOT_TYPE_DESCR)
#define TYPEDOBJ_OWNER(obj) \
UnsafeGetReservedSlot(obj, JS_TYPEDOBJ_SLOT_OWNER)
#define TYPEDOBJ_LENGTH(obj) \
TO_INT32(UnsafeGetReservedSlot(obj, JS_TYPEDOBJ_SLOT_LENGTH))
#define HAS_PROPERTY(obj, prop) \
callFunction(std_Object_hasOwnProperty, obj, prop)
function DATUM_TYPE_REPR(obj) {
function TYPEDOBJ_TYPE_REPR(obj) {
// Eventually this will be a slot on typed objects
return DESCR_TYPE_REPR(DATUM_TYPE_DESCR(obj));
return DESCR_TYPE_REPR(TYPEDOBJ_TYPE_DESCR(obj));
}
///////////////////////////////////////////////////////////////////////////
@ -139,7 +139,7 @@ function DescrToSource(descr) {
// TypedObjectPointers are internal structs used to represent a
// pointer into typed object memory. They pull together:
// - descr: the type descriptor
// - datum: the typed object that contains the allocated block of memory
// - typedObj: the typed object that contains the allocated block of memory
// - offset: an offset into that typed object
//
// They are basically equivalent to a typed object, except that they
@ -152,20 +152,20 @@ function DescrToSource(descr) {
// they mutate the receiver in place, because it makes for prettier
// code.
function TypedObjectPointer(descr, datum, offset) {
function TypedObjectPointer(descr, typedObj, offset) {
assert(IsObject(descr) && ObjectIsTypeDescr(descr), "Not descr");
assert(IsObject(datum) && ObjectIsTypedDatum(datum), "Not datum");
assert(IsObject(typedObj) && ObjectIsTypedObject(typedObj), "Not typedObj");
assert(TO_INT32(offset) === offset, "offset not int");
this.descr = descr;
this.datum = datum;
this.typedObj = typedObj;
this.offset = offset;
}
MakeConstructible(TypedObjectPointer, {});
TypedObjectPointer.fromTypedDatum = function(typed) {
return new TypedObjectPointer(DATUM_TYPE_DESCR(typed), typed, 0);
TypedObjectPointer.fromTypedObject = function(typed) {
return new TypedObjectPointer(TYPEDOBJ_TYPE_DESCR(typed), typed, 0);
}
#ifdef DEBUG
@ -175,12 +175,12 @@ TypedObjectPointer.prototype.toString = function() {
#endif
TypedObjectPointer.prototype.copy = function() {
return new TypedObjectPointer(this.descr, this.datum, this.offset);
return new TypedObjectPointer(this.descr, this.typedObj, this.offset);
};
TypedObjectPointer.prototype.reset = function(inPtr) {
this.descr = inPtr.descr;
this.datum = inPtr.datum;
this.typedObj = inPtr.typedObj;
this.offset = inPtr.offset;
return this;
};
@ -203,7 +203,7 @@ TypedObjectPointer.prototype.length = function() {
return DESCR_SIZED_ARRAY_LENGTH(this.descr);
case JS_TYPEREPR_UNSIZED_ARRAY_KIND:
return this.datum.length;
return this.typedObj.length;
}
assert(false, "Invalid kind for length");
return false;
@ -228,7 +228,7 @@ TypedObjectPointer.prototype.moveTo = function(propName) {
return this.moveToArray(propName, DESCR_SIZED_ARRAY_LENGTH(this.descr));
case JS_TYPEREPR_UNSIZED_ARRAY_KIND:
return this.moveToArray(propName, this.datum.length);
return this.moveToArray(propName, this.typedObj.length);
case JS_TYPEREPR_STRUCT_KIND:
if (HAS_PROPERTY(this.descr.fieldTypes, propName))
@ -244,7 +244,7 @@ TypedObjectPointer.prototype.moveToArray = function(propName, length) {
// For an array, property must be an element. Note that we take
// the length as an argument rather than loading it from the descriptor.
// This is because this same helper is used for *unsized arrays*, where
// the length is drawn from the datum, and *sized arrays*, where the
// the length is drawn from the typedObj, and *sized arrays*, where the
// length is drawn from the type.
var index = TO_INT32(propName);
if (index === propName && index >= 0 && index < length)
@ -322,9 +322,9 @@ TypedObjectPointer.prototype.moveToFieldIndex = function(index) {
// Reifies the value referenced by the pointer, meaning that it
// returns a new object pointing at the value. If the value is
// a scalar, it will return a JS number, but otherwise the reified
// result will be a datum of the same class as the ptr's datum.
// result will be a typedObj of the same class as the ptr's typedObj.
TypedObjectPointer.prototype.get = function() {
assert(DatumIsAttached(this.datum), "get() called with unattached datum");
assert(TypedObjectIsAttached(this.typedObj), "get() called with unattached typedObj");
switch (this.kind()) {
case JS_TYPEREPR_SCALAR_KIND:
@ -351,36 +351,36 @@ TypedObjectPointer.prototype.get = function() {
TypedObjectPointer.prototype.getDerived = function() {
assert(!TypeDescrIsSimpleType(this.descr),
"getDerived() used with simple type");
return NewDerivedTypedDatum(this.descr, this.datum, this.offset);
return NewDerivedTypedObject(this.descr, this.typedObj, this.offset);
}
TypedObjectPointer.prototype.getScalar = function() {
var type = DESCR_TYPE(this.descr);
switch (type) {
case JS_SCALARTYPEREPR_INT8:
return Load_int8(this.datum, this.offset);
return Load_int8(this.typedObj, this.offset);
case JS_SCALARTYPEREPR_UINT8:
case JS_SCALARTYPEREPR_UINT8_CLAMPED:
return Load_uint8(this.datum, this.offset);
return Load_uint8(this.typedObj, this.offset);
case JS_SCALARTYPEREPR_INT16:
return Load_int16(this.datum, this.offset);
return Load_int16(this.typedObj, this.offset);
case JS_SCALARTYPEREPR_UINT16:
return Load_uint16(this.datum, this.offset);
return Load_uint16(this.typedObj, this.offset);
case JS_SCALARTYPEREPR_INT32:
return Load_int32(this.datum, this.offset);
return Load_int32(this.typedObj, this.offset);
case JS_SCALARTYPEREPR_UINT32:
return Load_uint32(this.datum, this.offset);
return Load_uint32(this.typedObj, this.offset);
case JS_SCALARTYPEREPR_FLOAT32:
return Load_float32(this.datum, this.offset);
return Load_float32(this.typedObj, this.offset);
case JS_SCALARTYPEREPR_FLOAT64:
return Load_float64(this.datum, this.offset);
return Load_float64(this.typedObj, this.offset);
}
assert(false, "Unhandled scalar type: " + type);
@ -391,13 +391,13 @@ TypedObjectPointer.prototype.getReference = function() {
var type = DESCR_TYPE(this.descr);
switch (type) {
case JS_REFERENCETYPEREPR_ANY:
return Load_Any(this.datum, this.offset);
return Load_Any(this.typedObj, this.offset);
case JS_REFERENCETYPEREPR_OBJECT:
return Load_Object(this.datum, this.offset);
return Load_Object(this.typedObj, this.offset);
case JS_REFERENCETYPEREPR_STRING:
return Load_string(this.datum, this.offset);
return Load_string(this.typedObj, this.offset);
}
assert(false, "Unhandled scalar type: " + type);
@ -408,17 +408,17 @@ TypedObjectPointer.prototype.getX4 = function() {
var type = DESCR_TYPE(this.descr);
switch (type) {
case JS_X4TYPEREPR_FLOAT32:
var x = Load_float32(this.datum, this.offset + 0);
var y = Load_float32(this.datum, this.offset + 4);
var z = Load_float32(this.datum, this.offset + 8);
var w = Load_float32(this.datum, this.offset + 12);
var x = Load_float32(this.typedObj, this.offset + 0);
var y = Load_float32(this.typedObj, this.offset + 4);
var z = Load_float32(this.typedObj, this.offset + 8);
var w = Load_float32(this.typedObj, this.offset + 12);
return GetFloat32x4TypeDescr()(x, y, z, w);
case JS_X4TYPEREPR_INT32:
var x = Load_int32(this.datum, this.offset + 0);
var y = Load_int32(this.datum, this.offset + 4);
var z = Load_int32(this.datum, this.offset + 8);
var w = Load_int32(this.datum, this.offset + 12);
var x = Load_int32(this.typedObj, this.offset + 0);
var y = Load_int32(this.typedObj, this.offset + 4);
var z = Load_int32(this.typedObj, this.offset + 8);
var w = Load_int32(this.typedObj, this.offset + 12);
return GetInt32x4TypeDescr()(x, y, z, w);
}
@ -435,19 +435,19 @@ TypedObjectPointer.prototype.getX4 = function() {
// to `typeRepr` as needed. This is the most general entry point and
// works for any type.
TypedObjectPointer.prototype.set = function(fromValue) {
assert(DatumIsAttached(this.datum), "set() called with unattached datum");
assert(TypedObjectIsAttached(this.typedObj), "set() called with unattached typedObj");
// Fast path: `fromValue` is a typed object with same type
// representation as the destination. In that case, we can just do a
// memcpy.
if (IsObject(fromValue) && ObjectIsTypedDatum(fromValue)) {
if (IsObject(fromValue) && ObjectIsTypedObject(fromValue)) {
var typeRepr = DESCR_TYPE_REPR(this.descr);
if (!typeRepr.variable && DATUM_TYPE_REPR(fromValue) === typeRepr) {
if (!DatumIsAttached(fromValue))
if (!typeRepr.variable && TYPEDOBJ_TYPE_REPR(fromValue) === typeRepr) {
if (!TypedObjectIsAttached(fromValue))
ThrowError(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED);
var size = DESCR_SIZE(this.descr);
Memcpy(this.datum, this.offset, fromValue, 0, size);
Memcpy(this.typedObj, this.offset, fromValue, 0, size);
return;
}
}
@ -471,7 +471,7 @@ TypedObjectPointer.prototype.set = function(fromValue) {
break;
case JS_TYPEREPR_UNSIZED_ARRAY_KIND:
if (this.setArray(fromValue, this.datum.length))
if (this.setArray(fromValue, this.typedObj.length))
return;
break;
@ -523,38 +523,38 @@ TypedObjectPointer.prototype.setScalar = function(fromValue) {
var type = DESCR_TYPE(this.descr);
switch (type) {
case JS_SCALARTYPEREPR_INT8:
return Store_int8(this.datum, this.offset,
return Store_int8(this.typedObj, this.offset,
TO_INT32(fromValue) & 0xFF);
case JS_SCALARTYPEREPR_UINT8:
return Store_uint8(this.datum, this.offset,
return Store_uint8(this.typedObj, this.offset,
TO_UINT32(fromValue) & 0xFF);
case JS_SCALARTYPEREPR_UINT8_CLAMPED:
var v = ClampToUint8(+fromValue);
return Store_int8(this.datum, this.offset, v);
return Store_int8(this.typedObj, this.offset, v);
case JS_SCALARTYPEREPR_INT16:
return Store_int16(this.datum, this.offset,
return Store_int16(this.typedObj, this.offset,
TO_INT32(fromValue) & 0xFFFF);
case JS_SCALARTYPEREPR_UINT16:
return Store_uint16(this.datum, this.offset,
return Store_uint16(this.typedObj, this.offset,
TO_UINT32(fromValue) & 0xFFFF);
case JS_SCALARTYPEREPR_INT32:
return Store_int32(this.datum, this.offset,
return Store_int32(this.typedObj, this.offset,
TO_INT32(fromValue));
case JS_SCALARTYPEREPR_UINT32:
return Store_uint32(this.datum, this.offset,
return Store_uint32(this.typedObj, this.offset,
TO_UINT32(fromValue));
case JS_SCALARTYPEREPR_FLOAT32:
return Store_float32(this.datum, this.offset, +fromValue);
return Store_float32(this.typedObj, this.offset, +fromValue);
case JS_SCALARTYPEREPR_FLOAT64:
return Store_float64(this.datum, this.offset, +fromValue);
return Store_float64(this.typedObj, this.offset, +fromValue);
}
assert(false, "Unhandled scalar type: " + type);
@ -565,14 +565,14 @@ TypedObjectPointer.prototype.setReference = function(fromValue) {
var type = DESCR_TYPE(this.descr);
switch (type) {
case JS_REFERENCETYPEREPR_ANY:
return Store_Any(this.datum, this.offset, fromValue);
return Store_Any(this.typedObj, this.offset, fromValue);
case JS_REFERENCETYPEREPR_OBJECT:
var value = (fromValue === null ? fromValue : ToObject(fromValue));
return Store_Object(this.datum, this.offset, value);
return Store_Object(this.typedObj, this.offset, value);
case JS_REFERENCETYPEREPR_STRING:
return Store_string(this.datum, this.offset, ToString(fromValue));
return Store_string(this.typedObj, this.offset, ToString(fromValue));
}
assert(false, "Unhandled scalar type: " + type);
@ -597,50 +597,50 @@ TypedObjectPointer.prototype.setX4 = function(fromValue) {
// Wrapper for use from C++ code.
function ConvertAndCopyTo(destDescr,
destDatum,
destTypedObj,
destOffset,
fromValue)
{
assert(IsObject(destDescr) && ObjectIsTypeDescr(destDescr),
"ConvertAndCopyTo: not type obj");
assert(IsObject(destDatum) && ObjectIsTypedDatum(destDatum),
"ConvertAndCopyTo: not type datum");
assert(IsObject(destTypedObj) && ObjectIsTypedObject(destTypedObj),
"ConvertAndCopyTo: not type typedObj");
if (!DatumIsAttached(destDatum))
if (!TypedObjectIsAttached(destTypedObj))
ThrowError(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED);
var ptr = new TypedObjectPointer(destDescr, destDatum, destOffset);
var ptr = new TypedObjectPointer(destDescr, destTypedObj, destOffset);
ptr.set(fromValue);
}
// Wrapper for use from C++ code.
function Reify(sourceDescr,
sourceDatum,
sourceTypedObj,
sourceOffset) {
assert(IsObject(sourceDescr) && ObjectIsTypeDescr(sourceDescr),
"Reify: not type obj");
assert(IsObject(sourceDatum) && ObjectIsTypedDatum(sourceDatum),
"Reify: not type datum");
assert(IsObject(sourceTypedObj) && ObjectIsTypedObject(sourceTypedObj),
"Reify: not type typedObj");
if (!DatumIsAttached(sourceDatum))
if (!TypedObjectIsAttached(sourceTypedObj))
ThrowError(JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED);
var ptr = new TypedObjectPointer(sourceDescr, sourceDatum, sourceOffset);
var ptr = new TypedObjectPointer(sourceDescr, sourceTypedObj, sourceOffset);
return ptr.get();
}
function FillTypedArrayWithValue(destArray, fromValue) {
assert(IsObject(handle) && ObjectIsTypedDatum(destArray),
assert(IsObject(handle) && ObjectIsTypedObject(destArray),
"FillTypedArrayWithValue: not typed handle");
var descr = DATUM_TYPE_DESCR(destArray);
var descr = TYPEDOBJ_TYPE_DESCR(destArray);
var length = DESCR_SIZED_ARRAY_LENGTH(descr);
if (length === 0)
return;
// Use convert and copy to to produce the first element:
var ptr = TypedObjectPointer.fromTypedDatum(destArray);
var ptr = TypedObjectPointer.fromTypedObject(destArray);
ptr.moveToElem(0);
ptr.set(fromValue);
@ -681,7 +681,7 @@ function TypeDescrEquivalent(otherDescr) {
//
// Warning: user exposed!
function TypedArrayRedimension(newArrayType) {
if (!IsObject(this) || !ObjectIsTypedDatum(this))
if (!IsObject(this) || !ObjectIsTypedObject(this))
ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
if (!IsObject(newArrayType) || !ObjectIsTypeDescr(newArrayType))
@ -689,7 +689,7 @@ function TypedArrayRedimension(newArrayType) {
// Peel away the outermost array layers from the type of `this` to find
// the core element type. In the process, count the number of elements.
var oldArrayType = DATUM_TYPE_DESCR(this);
var oldArrayType = TYPEDOBJ_TYPE_DESCR(this);
var oldArrayReprKind = DESCR_KIND(oldArrayType);
var oldElementType = oldArrayType;
var oldElementCount = 1;
@ -734,7 +734,7 @@ function TypedArrayRedimension(newArrayType) {
"Byte sizes should be equal");
// Rewrap the data from `this` in a new type.
return NewDerivedTypedDatum(newArrayType, this, 0);
return NewDerivedTypedObject(newArrayType, this, 0);
}
///////////////////////////////////////////////////////////////////////////
@ -753,13 +753,13 @@ function X4ProtoString(type) {
}
function X4ToSource() {
if (!IsObject(this) || !ObjectIsTypedDatum(this))
if (!IsObject(this) || !ObjectIsTypedObject(this))
ThrowError(JSMSG_INCOMPATIBLE_PROTO, "X4", "toSource", typeof this);
if (DESCR_KIND(this) != JS_TYPEREPR_X4_KIND)
ThrowError(JSMSG_INCOMPATIBLE_PROTO, "X4", "toSource", typeof this);
var descr = DATUM_TYPE_DESCR(this);
var descr = TYPEDOBJ_TYPE_DESCR(this);
var type = DESCR_TYPE(descr);
return X4ProtoString(type)+"("+this.x+", "+this.y+", "+this.z+", "+this.w+")";
}
@ -789,15 +789,15 @@ function ArrayShorthand(...dims) {
// typed object, it returns null. Otherwise it throws.
//
// Warning: user exposed!
function StorageOfTypedDatum(obj) {
function StorageOfTypedObject(obj) {
if (IsObject(obj)) {
if (ObjectIsOpaqueTypedObject(obj))
return null;
if (ObjectIsTransparentTypedObject(obj))
return { buffer: DATUM_OWNER(obj),
byteLength: DATUM_BYTELENGTH(obj),
byteOffset: DATUM_BYTEOFFSET(obj) };
return { buffer: TYPEDOBJ_OWNER(obj),
byteLength: TYPEDOBJ_BYTELENGTH(obj),
byteOffset: TYPEDOBJ_BYTEOFFSET(obj) };
}
ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
@ -808,9 +808,9 @@ function StorageOfTypedDatum(obj) {
// It returns the type of its argument.
//
// Warning: user exposed!
function TypeOfTypedDatum(obj) {
if (IsObject(obj) && ObjectIsTypedDatum(obj))
return DATUM_TYPE_DESCR(obj);
function TypeOfTypedObject(obj) {
if (IsObject(obj) && ObjectIsTypedObject(obj))
return TYPEDOBJ_TYPE_DESCR(obj);
// Note: Do not create bindings for `Any`, `String`, etc in
// Utilities.js, but rather access them through
@ -829,8 +829,8 @@ function TypeOfTypedDatum(obj) {
}
}
function ObjectIsTypedDatum(obj) {
assert(IsObject(obj), "ObjectIsTypedDatum invoked with non-object")
function ObjectIsTypedObject(obj) {
assert(IsObject(obj), "ObjectIsTypedObject invoked with non-object")
return ObjectIsTransparentTypedObject(obj) || ObjectIsOpaqueTypedObject(obj);
}
@ -877,7 +877,7 @@ function TypedObjectArrayTypeFrom(a, b, c) {
if (!IsObject(this) || !ObjectIsTypeDescr(this))
ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
var untypedInput = !IsObject(a) || !ObjectIsTypedDatum(a);
var untypedInput = !IsObject(a) || !ObjectIsTypedObject(a);
// for untyped input array, the expectation (in terms of error
// reporting for invalid parameters) is no-depth, despite
@ -907,9 +907,9 @@ function TypedObjectArrayTypeFrom(a, b, c) {
// Warning: user exposed!
function TypedArrayMap(a, b) {
if (!IsObject(this) || !ObjectIsTypedDatum(this))
if (!IsObject(this) || !ObjectIsTypedObject(this))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
var thisType = DATUM_TYPE_DESCR(this);
var thisType = TYPEDOBJ_TYPE_DESCR(this);
if (!TypeDescrIsArrayType(thisType))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
@ -927,9 +927,9 @@ function TypedArrayMap(a, b) {
// Warning: user exposed!
function TypedArrayReduce(a, b) {
// Arguments: func, [initial]
if (!IsObject(this) || !ObjectIsTypedDatum(this))
if (!IsObject(this) || !ObjectIsTypedObject(this))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
var thisType = DATUM_TYPE_DESCR(this);
var thisType = TYPEDOBJ_TYPE_DESCR(this);
if (!TypeDescrIsArrayType(thisType))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
@ -943,9 +943,9 @@ function TypedArrayReduce(a, b) {
// Warning: user exposed!
function TypedArrayScatter(a, b, c, d) {
// Arguments: outputArrayType, indices, defaultValue, conflictFunction
if (!IsObject(this) || !ObjectIsTypedDatum(this))
if (!IsObject(this) || !ObjectIsTypedObject(this))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
var thisType = DATUM_TYPE_DESCR(this);
var thisType = TYPEDOBJ_TYPE_DESCR(this);
if (!TypeDescrIsArrayType(thisType))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
@ -961,9 +961,9 @@ function TypedArrayScatter(a, b, c, d) {
// Warning: user exposed!
function TypedArrayFilter(func) {
// Arguments: predicate
if (!IsObject(this) || !ObjectIsTypedDatum(this))
if (!IsObject(this) || !ObjectIsTypedObject(this))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
var thisType = DATUM_TYPE_DESCR(this);
var thisType = TYPEDOBJ_TYPE_DESCR(this);
if (!TypeDescrIsArrayType(thisType))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
@ -1225,14 +1225,14 @@ function MapUntypedSeqImpl(inArray, outputType, maybeFunc) {
// Implements |map| and |from| methods for typed |inArray|.
function MapTypedSeqImpl(inArray, depth, outputType, func) {
assert(IsObject(outputType) && ObjectIsTypeDescr(outputType), "2. Map/From called on non-type-object outputType");
assert(IsObject(inArray) && ObjectIsTypedDatum(inArray), "Map/From called on non-object or untyped input array.");
assert(IsObject(inArray) && ObjectIsTypedObject(inArray), "Map/From called on non-object or untyped input array.");
assert(TypeDescrIsArrayType(outputType), "Map/From called on non array-type outputType");
if (depth <= 0 || TO_INT32(depth) !== depth)
ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
// Compute iteration space for input and output and check for compatibility.
var inputType = TypeOfTypedDatum(inArray);
var inputType = TypeOfTypedObject(inArray);
var [inIterationSpace, inGrainType, _] =
ComputeIterationSpace(inputType, depth, inArray.length);
if (!IsObject(inGrainType) || !ObjectIsTypeDescr(inGrainType))
@ -1313,7 +1313,7 @@ function MapTypedSeqImpl(inArray, depth, outputType, func) {
}
function ReduceTypedSeqImpl(array, outputType, func, initial) {
assert(IsObject(array) && ObjectIsTypedDatum(array), "Reduce called on non-object or untyped input array.");
assert(IsObject(array) && ObjectIsTypedObject(array), "Reduce called on non-object or untyped input array.");
assert(IsObject(outputType) && ObjectIsTypeDescr(outputType), "Reduce called on non-type-object outputType");
var start, value;
@ -1354,7 +1354,7 @@ function ReduceTypedSeqImpl(array, outputType, func, initial) {
}
function ScatterTypedSeqImpl(array, outputType, indices, defaultValue, conflictFunc) {
assert(IsObject(array) && ObjectIsTypedDatum(array), "Scatter called on non-object or untyped input array.");
assert(IsObject(array) && ObjectIsTypedObject(array), "Scatter called on non-object or untyped input array.");
assert(IsObject(outputType) && ObjectIsTypeDescr(outputType), "Scatter called on non-type-object outputType");
assert(TypeDescrIsSizedArrayType(outputType), "Scatter called on non-sized array type");
assert(conflictFunc === undefined || typeof conflictFunc === "function", "Scatter called with invalid conflictFunc");
@ -1384,10 +1384,10 @@ function ScatterTypedSeqImpl(array, outputType, indices, defaultValue, conflictF
}
function FilterTypedSeqImpl(array, func) {
assert(IsObject(array) && ObjectIsTypedDatum(array), "Filter called on non-object or untyped input array.");
assert(IsObject(array) && ObjectIsTypedObject(array), "Filter called on non-object or untyped input array.");
assert(typeof func === "function", "Filter called with non-function predicate");
var arrayType = TypeOfTypedDatum(array);
var arrayType = TypeOfTypedObject(array);
if (!TypeDescrIsArrayType(arrayType))
ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);

View File

@ -103,25 +103,25 @@
#define JS_X4TYPEREPR_FLOAT32 1
///////////////////////////////////////////////////////////////////////////
// Slots for datums (base class of all typed objects)
// Slots for typed objects
#define JS_DATUM_SLOT_BYTEOFFSET 0
#define JS_DATUM_SLOT_BYTELENGTH 1
#define JS_DATUM_SLOT_OWNER 2
#define JS_DATUM_SLOT_NEXT_VIEW 3
#define JS_DATUM_SLOT_NEXT_BUFFER 4
#define JS_TYPEDOBJ_SLOT_BYTEOFFSET 0
#define JS_TYPEDOBJ_SLOT_BYTELENGTH 1
#define JS_TYPEDOBJ_SLOT_OWNER 2
#define JS_TYPEDOBJ_SLOT_NEXT_VIEW 3
#define JS_TYPEDOBJ_SLOT_NEXT_BUFFER 4
#define JS_DATAVIEW_SLOTS 5 // Number of slots for data views
#define JS_DATUM_SLOT_LENGTH 5 // Length of array (see (*) below)
#define JS_DATUM_SLOT_TYPE_DESCR 6 // For typed objects, type descr
#define JS_TYPEDOBJ_SLOT_LENGTH 5 // Length of array (see (*) below)
#define JS_TYPEDOBJ_SLOT_TYPE_DESCR 6 // For typed objects, type descr
#define JS_DATUM_SLOT_DATA 7 // private slot, based on alloc kind
#define JS_DATUM_SLOTS 7 // Number of slots for typed objs
#define JS_TYPEDOBJ_SLOT_DATA 7 // private slot, based on alloc kind
#define JS_TYPEDOBJ_SLOTS 7 // Number of slots for typed objs
// (*) The JS_DATUM_SLOT_LENGTH slot stores the length for datums of
// (*) The JS_TYPEDOBJ_SLOT_LENGTH slot stores the length for typed objects of
// sized and unsized array type. The slot contains 0 for non-arrays.
// The slot also contains 0 for *unattached* datums, no matter what
// The slot also contains 0 for *unattached* typed objects, no matter what
// type they have.
#endif

View File

@ -213,7 +213,7 @@ class X4TypeDescr : public SizedTypeDescr
macro_(X4TypeDescr::TYPE_INT32, int32_t, int32) \
macro_(X4TypeDescr::TYPE_FLOAT32, float, float32)
bool IsTypedDatumClass(const Class *clasp); // Defined in TypedArrayObject.h
bool IsTypedObjectClass(const Class *clasp); // Defined in TypedArrayObject.h
} // namespace js

View File

@ -4088,7 +4088,7 @@ CodeGenerator::visitNeuterCheck(LNeuterCheck *lir)
{
Register obj = ToRegister(lir->object());
Register temp = ToRegister(lir->temp());
masm.loadPtr(Address(obj, TypedDatum::dataOffset()), temp);
masm.loadPtr(Address(obj, TypedObject::dataOffset()), temp);
masm.testPtr(temp, temp);
if (!bailoutIf(Assembler::Zero, lir->snapshot()))
return false;
@ -4100,7 +4100,7 @@ CodeGenerator::visitTypedObjectElements(LTypedObjectElements *lir)
{
Register obj = ToRegister(lir->object());
Register out = ToRegister(lir->output());
masm.loadPtr(Address(obj, TypedDatum::dataOffset()), out);
masm.loadPtr(Address(obj, TypedObject::dataOffset()), out);
return true;
}

View File

@ -6632,7 +6632,7 @@ IonBuilder::checkTypedObjectIndexInBounds(size_t elemSize,
// then we still need to check if the object was neutered.
*canBeNeutered = true;
} else {
MInstruction *lengthValue = MLoadFixedSlot::New(alloc(), obj, JS_DATUM_SLOT_LENGTH);
MInstruction *lengthValue = MLoadFixedSlot::New(alloc(), obj, JS_TYPEDOBJ_SLOT_LENGTH);
current->add(lengthValue);
MInstruction *length32 = MTruncateToInt32::New(alloc(), lengthValue);
@ -6763,7 +6763,7 @@ IonBuilder::pushDerivedTypedObject(bool *emitted,
MDefinition *owner, *ownerOffset;
loadTypedObjectData(obj, offset, canBeNeutered, &owner, &ownerOffset);
// Create the derived datum.
// Create the derived typed object.
MInstruction *derivedTypedObj = MNewDerivedTypedObject::New(alloc(),
derivedTypeDescrs,
derivedTypeObj,
@ -9829,7 +9829,7 @@ IonBuilder::loadTypedObjectType(MDefinition *typedObj)
return typedObj->toNewDerivedTypedObject()->type();
MInstruction *load = MLoadFixedSlot::New(alloc(), typedObj,
JS_DATUM_SLOT_TYPE_DESCR);
JS_TYPEDOBJ_SLOT_TYPE_DESCR);
current->add(load);
return load;
}

View File

@ -82,18 +82,18 @@ jit::ParallelWriteGuard(ForkJoinContext *cx, JSObject *object)
JS_ASSERT(ForkJoinContext::current() == cx);
if (object->is<TypedDatum>()) {
TypedDatum &datum = object->as<TypedDatum>();
if (object->is<TypedObject>()) {
TypedObject &typedObj = object->as<TypedObject>();
// Note: check target region based on `datum`, not the owner.
// This is because `datum` may point to some subregion of the
// Note: check target region based on `typedObj`, not the owner.
// This is because `typedObj` may point to some subregion of the
// owner and we only care if that *subregion* is within the
// target region, not the entire owner.
if (IsInTargetRegion(cx, &datum))
if (IsInTargetRegion(cx, &typedObj))
return true;
// Also check whether owner is thread-local.
ArrayBufferObject &owner = datum.owner();
ArrayBufferObject &owner = typedObj.owner();
return cx->isThreadLocal(&owner);
}
@ -101,7 +101,7 @@ jit::ParallelWriteGuard(ForkJoinContext *cx, JSObject *object)
return cx->isThreadLocal(object);
}
// Check that |object| (which must be a typed datum) maps
// Check that |object| (which must be a typed typedObj) maps
// to memory in the target region.
//
// For efficiency, we assume that all handles which the user has
@ -110,10 +110,10 @@ jit::ParallelWriteGuard(ForkJoinContext *cx, JSObject *object)
// it. This invariant is maintained by the PJS APIs, where the target
// region and handles are always elements of the same output array.
bool
jit::IsInTargetRegion(ForkJoinContext *cx, TypedDatum *datum)
jit::IsInTargetRegion(ForkJoinContext *cx, TypedObject *typedObj)
{
JS_ASSERT(datum->is<TypedDatum>()); // in case JIT supplies something bogus
uint8_t *typedMem = datum->typedMem();
JS_ASSERT(typedObj->is<TypedObject>()); // in case JIT supplies something bogus
uint8_t *typedMem = typedObj->typedMem();
return (typedMem >= cx->targetRegionStart &&
typedMem < cx->targetRegionEnd);
}

View File

@ -12,14 +12,14 @@
namespace js {
class TypedDatum; // subclass of JSObject* defined in builtin/TypedObject.h
class TypedObject; // subclass of JSObject* defined in builtin/TypedObject.h
namespace jit {
ForkJoinContext *ForkJoinContextPar();
JSObject *NewGCThingPar(ForkJoinContext *cx, gc::AllocKind allocKind);
bool ParallelWriteGuard(ForkJoinContext *cx, JSObject *object);
bool IsInTargetRegion(ForkJoinContext *cx, TypedDatum *object);
bool IsInTargetRegion(ForkJoinContext *cx, TypedObject *object);
bool CheckOverRecursedPar(ForkJoinContext *cx);
bool InterruptCheckPar(ForkJoinContext *cx);

View File

@ -961,10 +961,10 @@ CreateDerivedTypedObj(JSContext *cx, HandleObject descr,
HandleObject owner, int32_t offset)
{
JS_ASSERT(descr->is<SizedTypeDescr>());
JS_ASSERT(owner->is<TypedDatum>());
JS_ASSERT(owner->is<TypedObject>());
Rooted<SizedTypeDescr*> descr1(cx, &descr->as<SizedTypeDescr>());
Rooted<TypedDatum*> owner1(cx, &owner->as<TypedDatum>());
return TypedDatum::createDerived(cx, descr1, owner1, offset);
Rooted<TypedObject*> owner1(cx, &owner->as<TypedObject>());
return TypedObject::createDerived(cx, descr1, owner1, offset);
}
JSString *

View File

@ -2171,11 +2171,11 @@ intrinsic_SetForkJoinTargetRegionPar(ForkJoinContext *cx, unsigned argc, Value *
CallArgs args = CallArgsFromVp(argc, vp);
JS_ASSERT(argc == 3);
JS_ASSERT(args[0].isObject() && args[0].toObject().is<TypedDatum>());
JS_ASSERT(args[0].isObject() && args[0].toObject().is<TypedObject>());
JS_ASSERT(args[1].isInt32());
JS_ASSERT(args[2].isInt32());
uint8_t *mem = args[0].toObject().as<TypedDatum>().typedMem();
uint8_t *mem = args[0].toObject().as<TypedObject>().typedMem();
int32_t start = args[1].toInt32();
int32_t end = args[2].toInt32();

View File

@ -701,21 +701,21 @@ static const JSFunctionSpec intrinsic_functions[] = {
JS_FN("NewOpaqueTypedObject",
js::NewOpaqueTypedObject,
1, 0),
JS_FN("NewDerivedTypedDatum",
js::NewDerivedTypedDatum,
JS_FN("NewDerivedTypedObject",
js::NewDerivedTypedObject,
3, 0),
JS_FNINFO("AttachDatum",
JSNativeThreadSafeWrapper<js::AttachDatum>,
&js::AttachDatumJitInfo, 5, 0),
JS_FNINFO("AttachTypedObject",
JSNativeThreadSafeWrapper<js::AttachTypedObject>,
&js::AttachTypedObjectJitInfo, 5, 0),
JS_FNINFO("ObjectIsTypeDescr",
JSNativeThreadSafeWrapper<js::ObjectIsTypeDescr>,
&js::ObjectIsTypeDescrJitInfo, 5, 0),
JS_FNINFO("ObjectIsTransparentTypedObject",
JSNativeThreadSafeWrapper<js::ObjectIsTransparentTypedObject>,
&js::ObjectIsTransparentTypedObjectJitInfo, 5, 0),
JS_FNINFO("DatumIsAttached",
JSNativeThreadSafeWrapper<js::DatumIsAttached>,
&js::DatumIsAttachedJitInfo, 1, 0),
JS_FNINFO("TypedObjectIsAttached",
JSNativeThreadSafeWrapper<js::TypedObjectIsAttached>,
&js::TypedObjectIsAttachedJitInfo, 1, 0),
JS_FNINFO("ObjectIsOpaqueTypedObject",
JSNativeThreadSafeWrapper<js::ObjectIsOpaqueTypedObject>,
&js::ObjectIsOpaqueTypedObjectJitInfo, 5, 0),

View File

@ -2640,7 +2640,7 @@ ArrayBufferViewObject::neuter(JSContext *cx)
else if (is<TypedArrayObject>())
as<TypedArrayObject>().neuter(cx);
else
as<TypedDatum>().neuter(cx);
as<TypedObject>().neuter(cx);
}
// this default implementation is only valid for integer types

View File

@ -224,23 +224,23 @@ class ArrayBufferViewObject : public JSObject
{
protected:
/* Offset of view in underlying ArrayBufferObject */
static const size_t BYTEOFFSET_SLOT = JS_DATUM_SLOT_BYTEOFFSET;
static const size_t BYTEOFFSET_SLOT = JS_TYPEDOBJ_SLOT_BYTEOFFSET;
/* Byte length of view */
static const size_t BYTELENGTH_SLOT = JS_DATUM_SLOT_BYTELENGTH;
static const size_t BYTELENGTH_SLOT = JS_TYPEDOBJ_SLOT_BYTELENGTH;
/* Underlying ArrayBufferObject */
static const size_t BUFFER_SLOT = JS_DATUM_SLOT_OWNER;
static const size_t BUFFER_SLOT = JS_TYPEDOBJ_SLOT_OWNER;
/* ArrayBufferObjects point to a linked list of views, chained through this slot */
static const size_t NEXT_VIEW_SLOT = JS_DATUM_SLOT_NEXT_VIEW;
static const size_t NEXT_VIEW_SLOT = JS_TYPEDOBJ_SLOT_NEXT_VIEW;
/*
* When ArrayBufferObjects are traced during GC, they construct a linked
* list of ArrayBufferObjects with more than one view, chained through this
* slot of the first view of each ArrayBufferObject.
*/
static const size_t NEXT_BUFFER_SLOT = JS_DATUM_SLOT_NEXT_BUFFER;
static const size_t NEXT_BUFFER_SLOT = JS_TYPEDOBJ_SLOT_NEXT_BUFFER;
public:
JSObject *bufferObject() const {
@ -279,10 +279,10 @@ class TypedArrayObject : public ArrayBufferViewObject
protected:
// Typed array properties stored in slots, beyond those shared by all
// ArrayBufferViews.
static const size_t LENGTH_SLOT = JS_DATUM_SLOT_LENGTH;
static const size_t TYPE_SLOT = JS_DATUM_SLOT_TYPE_DESCR;
static const size_t RESERVED_SLOTS = JS_DATUM_SLOTS;
static const size_t DATA_SLOT = JS_DATUM_SLOT_DATA;
static const size_t LENGTH_SLOT = JS_TYPEDOBJ_SLOT_LENGTH;
static const size_t TYPE_SLOT = JS_TYPEDOBJ_SLOT_TYPE_DESCR;
static const size_t RESERVED_SLOTS = JS_TYPEDOBJ_SLOTS;
static const size_t DATA_SLOT = JS_TYPEDOBJ_SLOT_DATA;
public:
static const Class classes[ScalarTypeDescr::TYPE_MAX];
@ -419,7 +419,7 @@ TypedArrayShift(ArrayBufferView::ViewType viewType)
class DataViewObject : public ArrayBufferViewObject
{
static const size_t RESERVED_SLOTS = JS_DATAVIEW_SLOTS;
static const size_t DATA_SLOT = JS_DATUM_SLOT_DATA;
static const size_t DATA_SLOT = JS_TYPEDOBJ_SLOT_DATA;
private:
static const Class protoClass;
@ -581,7 +581,7 @@ inline bool
JSObject::is<js::ArrayBufferViewObject>() const
{
return is<js::DataViewObject>() || is<js::TypedArrayObject>() ||
IsTypedDatumClass(getClass());
IsTypedObjectClass(getClass());
}
#endif /* vm_TypedArrayObject_h */