From 1d8aa6f55b71510bfcb12fbe061c6bb58634ca16 Mon Sep 17 00:00:00 2001 From: "Nicholas D. Matsakis" Date: Wed, 12 Feb 2014 11:46:51 -0500 Subject: [PATCH] Bug 898356 Part 8 -- Rename from Datum to TypedObject (or typedObj) r=sfink --- js/src/builtin/SIMD.cpp | 74 ++-- js/src/builtin/TypedObject.cpp | 521 +++++++++++++------------- js/src/builtin/TypedObject.h | 104 ++--- js/src/builtin/TypedObject.js | 210 +++++------ js/src/builtin/TypedObjectConstants.h | 24 +- js/src/builtin/TypedObjectSimple.h | 2 +- js/src/jit/CodeGenerator.cpp | 4 +- js/src/jit/IonBuilder.cpp | 6 +- js/src/jit/ParallelFunctions.cpp | 20 +- js/src/jit/ParallelFunctions.h | 4 +- js/src/jit/VMFunctions.cpp | 6 +- js/src/vm/ForkJoin.cpp | 4 +- js/src/vm/SelfHosting.cpp | 16 +- js/src/vm/TypedArrayObject.cpp | 2 +- js/src/vm/TypedArrayObject.h | 22 +- 15 files changed, 515 insertions(+), 504 deletions(-) diff --git a/js/src/builtin/SIMD.cpp b/js/src/builtin/SIMD.cpp index 89f1fd51d19..413d0f44b98 100644 --- a/js/src/builtin/SIMD.cpp +++ b/js/src/builtin/SIMD.cpp @@ -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()) { \ + if(!args.thisv().isObject() || !args.thisv().toObject().is()) { \ 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(); \ - TypeDescr &descr = datum.typeDescr(); \ + TypedObject &typedObj = args.thisv().toObject().as(); \ + TypeDescr &descr = typedObj.typeDescr(); \ if (descr.kind() != TypeDescr::X4 || \ descr.as().type() != Type32x4::type) \ { \ @@ -55,7 +55,7 @@ extern const JSFunctionSpec Int32x4Methods[]; InformalValueTypeName(args.thisv())); \ return false; \ } \ - Type32x4::Elem *data = reinterpret_cast(datum.typedMem()); \ + Type32x4::Elem *data = reinterpret_cast(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()) { \ + if(!args.thisv().isObject() || !args.thisv().toObject().is()) { \ JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, \ X4TypeDescr::class_.name, "signMask", \ InformalValueTypeName(args.thisv())); \ return false; \ } \ - TypedDatum &datum = args.thisv().toObject().as(); \ - TypeDescr &descr = datum.typeDescr(); \ + TypedObject &typedObj = args.thisv().toObject().as(); \ + TypeDescr &descr = typedObj.typeDescr(); \ if (descr.kind() != TypeDescr::X4 || \ descr.as().type() != Type32x4::type) \ { \ @@ -88,7 +88,7 @@ extern const JSFunctionSpec Int32x4Methods[]; InformalValueTypeName(args.thisv())); \ return false; \ } \ - Type32x4::Elem *data = reinterpret_cast(datum.typedMem()); \ + Type32x4::Elem *data = reinterpret_cast(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 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 descr(cx, &args.callee().as()); - Rooted result(cx, TypedDatum::createZeroed(cx, descr, 0)); + Rooted result(cx, TypedObject::createZeroed(cx, descr, 0)); if (!result) return false; @@ -366,9 +366,9 @@ js_InitSIMDClass(JSContext *cx, HandleObject obj) template static bool ObjectIsVector(JSObject &obj) { - if (!obj.is()) + if (!obj.is()) return false; - TypeDescr &typeRepr = obj.as().typeDescr(); + TypeDescr &typeRepr = obj.as().typeDescr(); if (typeRepr.kind() != TypeDescr::X4) return false; return typeRepr.as().type() == V::type; @@ -381,7 +381,7 @@ js::Create(JSContext *cx, typename V::Elem *data) Rooted typeDescr(cx, &V::GetTypeDescr(*cx->global())); JS_ASSERT(typeDescr); - Rooted result(cx, TypedDatum::createZeroed(cx, typeDescr, 0)); + Rooted 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( - args[0].toObject().as().typedMem()); + args[0].toObject().as().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( - args[0].toObject().as().typedMem()); + args[0].toObject().as().typedMem()); typename V::Elem *right = reinterpret_cast( - args[1].toObject().as().typedMem()); + args[1].toObject().as().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( - args[0].toObject().as().typedMem()); + args[0].toObject().as().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( - args[0].toObject().as().typedMem()); + args[0].toObject().as().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( - args[0].toObject().as().typedMem()); + args[0].toObject().as().typedMem()); typename V::Elem *val2 = reinterpret_cast( - args[1].toObject().as().typedMem()); + args[1].toObject().as().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( - args[0].toObject().as().typedMem()); + args[0].toObject().as().typedMem()); typename Vret::Elem result[Vret::lanes]; for (int32_t i = 0; i < Vret::lanes; i++) result[i] = static_cast(val[i]); @@ -718,7 +718,7 @@ FuncConvertBits(JSContext *cx, unsigned argc, Value *vp) } typename Vret::Elem *val = reinterpret_cast( - args[0].toObject().as().typedMem()); + args[0].toObject().as().typedMem()); RootedObject obj(cx, Create(cx, val)); if (!obj) @@ -813,11 +813,11 @@ Float32x4Clamp(JSContext *cx, unsigned argc, Value *vp) return false; } float *val = reinterpret_cast( - args[0].toObject().as().typedMem()); + args[0].toObject().as().typedMem()); float *lowerLimit = reinterpret_cast( - args[1].toObject().as().typedMem()); + args[1].toObject().as().typedMem()); float *upperLimit = reinterpret_cast( - args[2].toObject().as().typedMem()); + args[2].toObject().as().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( - args[0].toObject().as().typedMem()); + args[0].toObject().as().typedMem()); int32_t *tv = reinterpret_cast( - args[1].toObject().as().typedMem()); + args[1].toObject().as().typedMem()); int32_t *fv = reinterpret_cast( - args[2].toObject().as().typedMem()); + args[2].toObject().as().typedMem()); int32_t tr[Int32x4::lanes]; for (int32_t i = 0; i < Int32x4::lanes; i++) tr[i] = And::apply(val[i], tv[i]); diff --git a/js/src/builtin/TypedObject.cpp b/js/src/builtin/TypedObject.cpp index 67c69f37592..c68d1664c0c 100644 --- a/js/src/builtin/TypedObject.cpp +++ b/js/src/builtin/TypedObject.cpp @@ -43,8 +43,8 @@ const Class js::TypedObjectModuleObject::class_ = { }; static const JSFunctionSpec TypedObjectMethods[] = { - JS_SELF_HOSTED_FN("objectType", "TypeOfTypedDatum", 1, 0), - JS_SELF_HOSTED_FN("storage", "StorageOfTypedDatum", 1, 0), + JS_SELF_HOSTED_FN("objectType", "TypeOfTypedObject", 1, 0), + JS_SELF_HOSTED_FN("storage", "StorageOfTypedObject", 1, 0), JS_FS_END }; @@ -69,7 +69,7 @@ ToObjectIf(HandleValue value) } /* - * Overwrites the contents of `datum` at offset `offset` with `val` + * Overwrites the contents of `typedObj` at offset `offset` with `val` * converted to the type `typeObj`. This is done by delegating to * self-hosted code. This is used for assignments and initializations. * @@ -83,7 +83,7 @@ ToObjectIf(HandleValue value) * This would result in a call to `ConvertAndCopyTo` * where: * - typeObj = Point - * - datum = line + * - typedObj = line * - offset = sizeof(Point) == 8 * - val = {x: 22, y: 44} * This would result in loading the value of `x`, converting @@ -91,12 +91,12 @@ ToObjectIf(HandleValue value) * and then doing the same for `y`. * * Note that the type of `typeObj` may not be the - * type of `datum` but rather some subcomponent of `datum`. + * type of `typedObj` but rather some subcomponent of `typedObj`. */ static bool ConvertAndCopyTo(JSContext *cx, HandleTypeDescr typeObj, - HandleTypedDatum datum, + HandleTypedObject typedObj, int32_t offset, HandleValue val) { @@ -111,7 +111,7 @@ ConvertAndCopyTo(JSContext *cx, args.setCallee(ObjectValue(*func)); args[0].setObject(*typeObj); - args[1].setObject(*datum); + args[1].setObject(*typedObj); args[2].setInt32(offset); args[3].set(val); @@ -119,20 +119,20 @@ ConvertAndCopyTo(JSContext *cx, } static bool -ConvertAndCopyTo(JSContext *cx, HandleTypedDatum datum, HandleValue val) +ConvertAndCopyTo(JSContext *cx, HandleTypedObject typedObj, HandleValue val) { - Rooted type(cx, &datum->typeDescr()); - return ConvertAndCopyTo(cx, type, datum, 0, val); + Rooted type(cx, &typedObj->typeDescr()); + return ConvertAndCopyTo(cx, type, typedObj, 0, val); } /* - * Overwrites the contents of `datum` at offset `offset` with `val` + * Overwrites the contents of `typedObj` at offset `offset` with `val` * converted to the type `typeObj` */ static bool Reify(JSContext *cx, HandleTypeDescr type, - HandleTypedDatum datum, + HandleTypedObject typedObj, size_t offset, MutableHandleValue to) { @@ -146,7 +146,7 @@ Reify(JSContext *cx, args.setCallee(ObjectValue(*func)); args[0].setObject(*type); - args[1].setObject(*datum); + args[1].setObject(*typedObj); args[2].setInt32(offset); if (!Invoke(cx, args)) @@ -239,7 +239,7 @@ const Class UnsizedArrayTypeDescr::class_ = { nullptr, nullptr, nullptr, - TypedDatum::constructUnsized, + TypedObject::constructUnsized, nullptr }; @@ -256,7 +256,7 @@ const Class SizedArrayTypeDescr::class_ = { nullptr, nullptr, nullptr, - TypedDatum::constructSized, + TypedObject::constructSized, nullptr }; @@ -545,7 +545,7 @@ const Class StructTypeDescr::class_ = { nullptr, /* finalize */ nullptr, /* call */ nullptr, /* hasInstance */ - TypedDatum::constructSized, + TypedObject::constructSized, nullptr /* trace */ }; @@ -1138,14 +1138,11 @@ TypedObjectModuleObject::getSuitableClaspAndProto(JSContext *cx, } /****************************************************************************** - * Typed datums - * - * Datums represent either typed objects or handles. See comment in - * TypedObject.h. + * Typed objects */ -/*static*/ TypedDatum * -TypedDatum::createUnattached(JSContext *cx, +/*static*/ TypedObject * +TypedObject::createUnattached(JSContext *cx, HandleTypeDescr descr, int32_t length) { @@ -1156,15 +1153,15 @@ TypedDatum::createUnattached(JSContext *cx, } -/*static*/ TypedDatum * -TypedDatum::createUnattachedWithClass(JSContext *cx, +/*static*/ TypedObject * +TypedObject::createUnattachedWithClass(JSContext *cx, const Class *clasp, HandleTypeDescr type, int32_t length) { JS_ASSERT(clasp == &TransparentTypedObject::class_ || clasp == &OpaqueTypedObject::class_); - JS_ASSERT(JSCLASS_RESERVED_SLOTS(clasp) == JS_DATUM_SLOTS); + JS_ASSERT(JSCLASS_RESERVED_SLOTS(clasp) == JS_TYPEDOBJ_SLOTS); JS_ASSERT(clasp->hasPrivate()); RootedObject proto(cx); @@ -1186,13 +1183,13 @@ TypedDatum::createUnattachedWithClass(JSContext *cx, return nullptr; obj->setPrivate(nullptr); - obj->initReservedSlot(JS_DATUM_SLOT_BYTEOFFSET, Int32Value(0)); - obj->initReservedSlot(JS_DATUM_SLOT_BYTELENGTH, Int32Value(0)); - obj->initReservedSlot(JS_DATUM_SLOT_OWNER, NullValue()); - obj->initReservedSlot(JS_DATUM_SLOT_NEXT_VIEW, PrivateValue(nullptr)); - obj->initReservedSlot(JS_DATUM_SLOT_NEXT_BUFFER, PrivateValue(UNSET_BUFFER_LINK)); - obj->initReservedSlot(JS_DATUM_SLOT_LENGTH, Int32Value(length)); - obj->initReservedSlot(JS_DATUM_SLOT_TYPE_DESCR, ObjectValue(*type)); + obj->initReservedSlot(JS_TYPEDOBJ_SLOT_BYTEOFFSET, Int32Value(0)); + obj->initReservedSlot(JS_TYPEDOBJ_SLOT_BYTELENGTH, Int32Value(0)); + obj->initReservedSlot(JS_TYPEDOBJ_SLOT_OWNER, NullValue()); + obj->initReservedSlot(JS_TYPEDOBJ_SLOT_NEXT_VIEW, PrivateValue(nullptr)); + obj->initReservedSlot(JS_TYPEDOBJ_SLOT_NEXT_BUFFER, PrivateValue(UNSET_BUFFER_LINK)); + obj->initReservedSlot(JS_TYPEDOBJ_SLOT_LENGTH, Int32Value(length)); + obj->initReservedSlot(JS_TYPEDOBJ_SLOT_TYPE_DESCR, ObjectValue(*type)); // Tag the type object for this instance with the type // representation, if that has not been done already. @@ -1205,31 +1202,31 @@ TypedDatum::createUnattachedWithClass(JSContext *cx, } } - return static_cast(&*obj); + return static_cast(&*obj); } void -TypedDatum::attach(ArrayBufferObject &buffer, int32_t offset) +TypedObject::attach(ArrayBufferObject &buffer, int32_t offset) { JS_ASSERT(offset >= 0); JS_ASSERT(offset + size() <= buffer.byteLength()); buffer.addView(this); setPrivate(buffer.dataPointer() + offset); - setReservedSlot(JS_DATUM_SLOT_BYTEOFFSET, Int32Value(offset)); - setReservedSlot(JS_DATUM_SLOT_OWNER, ObjectValue(buffer)); + setReservedSlot(JS_TYPEDOBJ_SLOT_BYTEOFFSET, Int32Value(offset)); + setReservedSlot(JS_TYPEDOBJ_SLOT_OWNER, ObjectValue(buffer)); } void -TypedDatum::attach(TypedDatum &datum, int32_t offset) +TypedObject::attach(TypedObject &typedObj, int32_t offset) { - attach(datum.owner(), datum.offset() + offset); + attach(typedObj.owner(), typedObj.offset() + offset); } -// Returns a suitable JS_DATUM_SLOT_LENGTH value for an instance of +// Returns a suitable JS_TYPEDOBJ_SLOT_LENGTH value for an instance of // the type `type`. `type` must not be an unsized array. static int32_t -DatumLengthFromType(TypeDescr &descr) +TypedObjLengthFromType(TypeDescr &descr) { TypeRepresentation *typeRepr = descr.typeRepresentation(); switch (typeRepr->kind()) { @@ -1243,42 +1240,42 @@ DatumLengthFromType(TypeDescr &descr) return typeRepr->asSizedArray()->length(); case TypeDescr::UnsizedArray: - MOZ_ASSUME_UNREACHABLE("DatumLengthFromType() invoked on unsized type"); + MOZ_ASSUME_UNREACHABLE("TypedObjLengthFromType() invoked on unsized type"); } MOZ_ASSUME_UNREACHABLE("Invalid kind"); } -/*static*/ TypedDatum * -TypedDatum::createDerived(JSContext *cx, HandleSizedTypeDescr type, - HandleTypedDatum datum, size_t offset) +/*static*/ TypedObject * +TypedObject::createDerived(JSContext *cx, HandleSizedTypeDescr type, + HandleTypedObject typedObj, size_t offset) { - JS_ASSERT(offset <= datum->size()); - JS_ASSERT(offset + type->size() <= datum->size()); + JS_ASSERT(offset <= typedObj->size()); + JS_ASSERT(offset + type->size() <= typedObj->size()); - int32_t length = DatumLengthFromType(*type); + int32_t length = TypedObjLengthFromType(*type); - const js::Class *clasp = datum->getClass(); - Rooted obj(cx); + const js::Class *clasp = typedObj->getClass(); + Rooted obj(cx); obj = createUnattachedWithClass(cx, clasp, type, length); if (!obj) return nullptr; - obj->attach(*datum, offset); + obj->attach(*typedObj, offset); return obj; } -/*static*/ TypedDatum * -TypedDatum::createZeroed(JSContext *cx, +/*static*/ TypedObject * +TypedObject::createZeroed(JSContext *cx, HandleTypeDescr descr, int32_t length) { // Create unattached wrapper object. - Rooted obj(cx, createUnattached(cx, descr, length)); + Rooted obj(cx, createUnattached(cx, descr, length)); if (!obj) return nullptr; // Allocate and initialize the memory for this instance. - // Also initialize the JS_DATUM_SLOT_LENGTH slot. + // Also initialize the JS_TYPEDOBJ_SLOT_LENGTH slot. TypeRepresentation *typeRepr = descr->typeRepresentation(); switch (descr->kind()) { case TypeDescr::Scalar: @@ -1325,9 +1322,9 @@ TypedDatum::createZeroed(JSContext *cx, } static bool -ReportDatumTypeError(JSContext *cx, +ReportTypedObjTypeError(JSContext *cx, const unsigned errorNumber, - HandleTypedDatum obj) + HandleTypedObject obj) { // Serialize type string using self-hosted function DescrToSource RootedFunction func( @@ -1358,18 +1355,18 @@ ReportDatumTypeError(JSContext *cx, } /*static*/ void -TypedDatum::obj_trace(JSTracer *trace, JSObject *object) +TypedObject::obj_trace(JSTracer *trace, JSObject *object) { - gc::MarkSlot(trace, &object->getReservedSlotRef(JS_DATUM_SLOT_TYPE_DESCR), + gc::MarkSlot(trace, &object->getReservedSlotRef(JS_TYPEDOBJ_SLOT_TYPE_DESCR), "TypedObjectTypeDescr"); ArrayBufferViewObject::trace(trace, object); - JS_ASSERT(object->is()); - TypedDatum &datum = object->as(); - TypeRepresentation *repr = datum.typeRepresentation(); + JS_ASSERT(object->is()); + TypedObject &typedObj = object->as(); + TypeRepresentation *repr = typedObj.typeRepresentation(); if (repr->opaque()) { - uint8_t *mem = datum.typedMem(); + uint8_t *mem = typedObj.typedMem(); if (!mem) return; // unattached handle or partially constructed @@ -1383,19 +1380,19 @@ TypedDatum::obj_trace(JSTracer *trace, JSObject *object) break; case TypeDescr::UnsizedArray: - repr->asUnsizedArray()->element()->traceInstance(trace, mem, datum.length()); + repr->asUnsizedArray()->element()->traceInstance(trace, mem, typedObj.length()); break; } } } bool -TypedDatum::obj_lookupGeneric(JSContext *cx, HandleObject obj, HandleId id, +TypedObject::obj_lookupGeneric(JSContext *cx, HandleObject obj, HandleId id, MutableHandleObject objp, MutableHandleShape propp) { - JS_ASSERT(obj->is()); + JS_ASSERT(obj->is()); - Rooted typeDescr(cx, &obj->as().typeDescr()); + Rooted typeDescr(cx, &obj->as().typeDescr()); TypeRepresentation *typeRepr = typeDescr->typeRepresentation(); switch (typeRepr->kind()) { @@ -1443,7 +1440,7 @@ TypedDatum::obj_lookupGeneric(JSContext *cx, HandleObject obj, HandleId id, } bool -TypedDatum::obj_lookupProperty(JSContext *cx, +TypedObject::obj_lookupProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, MutableHandleObject objp, @@ -1454,10 +1451,10 @@ TypedDatum::obj_lookupProperty(JSContext *cx, } bool -TypedDatum::obj_lookupElement(JSContext *cx, HandleObject obj, uint32_t index, +TypedObject::obj_lookupElement(JSContext *cx, HandleObject obj, uint32_t index, MutableHandleObject objp, MutableHandleShape propp) { - JS_ASSERT(obj->is()); + JS_ASSERT(obj->is()); MarkNonNativePropertyFound(propp); objp.set(obj); return true; @@ -1484,7 +1481,7 @@ ReportPropertyError(JSContext *cx, } bool -TypedDatum::obj_lookupSpecial(JSContext *cx, HandleObject obj, +TypedObject::obj_lookupSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, MutableHandleObject objp, MutableHandleShape propp) { @@ -1493,14 +1490,14 @@ TypedDatum::obj_lookupSpecial(JSContext *cx, HandleObject obj, } bool -TypedDatum::obj_defineGeneric(JSContext *cx, HandleObject obj, HandleId id, HandleValue v, +TypedObject::obj_defineGeneric(JSContext *cx, HandleObject obj, HandleId id, HandleValue v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { return ReportPropertyError(cx, JSMSG_UNDEFINED_PROP, id); } bool -TypedDatum::obj_defineProperty(JSContext *cx, HandleObject obj, +TypedObject::obj_defineProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, HandleValue v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { @@ -1509,7 +1506,7 @@ TypedDatum::obj_defineProperty(JSContext *cx, HandleObject obj, } bool -TypedDatum::obj_defineElement(JSContext *cx, HandleObject obj, uint32_t index, HandleValue v, +TypedObject::obj_defineElement(JSContext *cx, HandleObject obj, uint32_t index, HandleValue v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { AutoRooterGetterSetter gsRoot(cx, attrs, &getter, &setter); @@ -1521,7 +1518,7 @@ TypedDatum::obj_defineElement(JSContext *cx, HandleObject obj, uint32_t index, H } bool -TypedDatum::obj_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, HandleValue v, +TypedObject::obj_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, HandleValue v, PropertyOp getter, StrictPropertyOp setter, unsigned attrs) { Rooted id(cx, SPECIALID_TO_JSID(sid)); @@ -1529,11 +1526,11 @@ TypedDatum::obj_defineSpecial(JSContext *cx, HandleObject obj, HandleSpecialId s } bool -TypedDatum::obj_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, +TypedObject::obj_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleId id, MutableHandleValue vp) { - JS_ASSERT(obj->is()); - Rooted datum(cx, &obj->as()); + JS_ASSERT(obj->is()); + Rooted typedObj(cx, &obj->as()); // Dispatch elements to obj_getElement: uint32_t index; @@ -1542,7 +1539,7 @@ TypedDatum::obj_getGeneric(JSContext *cx, HandleObject obj, HandleObject receive // Handle everything else here: - TypeRepresentation *typeRepr = datum->typeRepresentation(); + TypeRepresentation *typeRepr = typedObj->typeRepresentation(); switch (typeRepr->kind()) { case TypeDescr::Scalar: case TypeDescr::Reference: @@ -1554,20 +1551,20 @@ TypedDatum::obj_getGeneric(JSContext *cx, HandleObject obj, HandleObject receive case TypeDescr::SizedArray: case TypeDescr::UnsizedArray: if (JSID_IS_ATOM(id, cx->names().length)) { - if (!datum->typedMem()) { // unattached + if (!typedObj->typedMem()) { // unattached JS_ReportErrorNumber( cx, js_GetErrorMessage, nullptr, JSMSG_TYPEDOBJECT_HANDLE_UNATTACHED); return false; } - vp.setInt32(datum->length()); + vp.setInt32(typedObj->length()); return true; } break; case TypeDescr::Struct: { - Rooted descr(cx, &datum->typeDescr().as()); + Rooted descr(cx, &typedObj->typeDescr().as()); size_t fieldIndex; if (!descr->fieldIndex(id, &fieldIndex)) @@ -1575,7 +1572,7 @@ TypedDatum::obj_getGeneric(JSContext *cx, HandleObject obj, HandleObject receive size_t offset = descr->fieldOffset(fieldIndex); Rooted fieldType(cx, &descr->fieldDescr(fieldIndex)); - return Reify(cx, fieldType, datum, offset, vp); + return Reify(cx, fieldType, typedObj, offset, vp); } } @@ -1589,7 +1586,7 @@ TypedDatum::obj_getGeneric(JSContext *cx, HandleObject obj, HandleObject receive } bool -TypedDatum::obj_getProperty(JSContext *cx, HandleObject obj, HandleObject receiver, +TypedObject::obj_getProperty(JSContext *cx, HandleObject obj, HandleObject receiver, HandlePropertyName name, MutableHandleValue vp) { RootedId id(cx, NameToId(name)); @@ -1597,12 +1594,12 @@ TypedDatum::obj_getProperty(JSContext *cx, HandleObject obj, HandleObject receiv } bool -TypedDatum::obj_getElement(JSContext *cx, HandleObject obj, HandleObject receiver, +TypedObject::obj_getElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_t index, MutableHandleValue vp) { - JS_ASSERT(obj->is()); - Rooted datum(cx, &obj->as()); - Rooted descr(cx, &datum->typeDescr()); + JS_ASSERT(obj->is()); + Rooted typedObj(cx, &obj->as()); + Rooted descr(cx, &typedObj->typeDescr()); switch (descr->kind()) { case TypeDescr::Scalar: @@ -1612,11 +1609,11 @@ TypedDatum::obj_getElement(JSContext *cx, HandleObject obj, HandleObject receive break; case TypeDescr::SizedArray: - return obj_getArrayElement(cx, datum, descr, + return obj_getArrayElement(cx, typedObj, descr, index, vp); case TypeDescr::UnsizedArray: - return obj_getArrayElement(cx, datum, descr, + return obj_getArrayElement(cx, typedObj, descr, index, vp); } @@ -1631,26 +1628,26 @@ TypedDatum::obj_getElement(JSContext *cx, HandleObject obj, HandleObject receive template /*static*/ bool -TypedDatum::obj_getArrayElement(JSContext *cx, - Handle datum, +TypedObject::obj_getArrayElement(JSContext *cx, + Handle typedObj, Handle typeDescr, uint32_t index, MutableHandleValue vp) { JS_ASSERT(typeDescr->is()); - if (index >= datum->length()) { + if (index >= typedObj->length()) { vp.setUndefined(); return true; } Rooted elementType(cx, &typeDescr->as().elementType()); size_t offset = elementType->size() * index; - return Reify(cx, elementType, datum, offset, vp); + return Reify(cx, elementType, typedObj, offset, vp); } bool -TypedDatum::obj_getSpecial(JSContext *cx, HandleObject obj, +TypedObject::obj_getSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid, MutableHandleValue vp) { @@ -1659,17 +1656,17 @@ TypedDatum::obj_getSpecial(JSContext *cx, HandleObject obj, } bool -TypedDatum::obj_setGeneric(JSContext *cx, HandleObject obj, HandleId id, +TypedObject::obj_setGeneric(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp, bool strict) { - JS_ASSERT(obj->is()); - Rooted datum(cx, &obj->as()); + JS_ASSERT(obj->is()); + Rooted typedObj(cx, &obj->as()); uint32_t index; if (js_IdIsIndex(id, &index)) return obj_setElement(cx, obj, index, vp, strict); - TypeRepresentation *typeRepr = datum->typeRepresentation(); + TypeRepresentation *typeRepr = typedObj->typeRepresentation(); switch (typeRepr->kind()) { case ScalarTypeDescr::Scalar: case TypeDescr::Reference: @@ -1688,7 +1685,7 @@ TypedDatum::obj_setGeneric(JSContext *cx, HandleObject obj, HandleId id, break; case ScalarTypeDescr::Struct: { - Rooted descr(cx, &datum->typeDescr().as()); + Rooted descr(cx, &typedObj->typeDescr().as()); size_t fieldIndex; if (!descr->fieldIndex(id, &fieldIndex)) @@ -1696,15 +1693,15 @@ TypedDatum::obj_setGeneric(JSContext *cx, HandleObject obj, HandleId id, size_t offset = descr->fieldOffset(fieldIndex); Rooted fieldType(cx, &descr->fieldDescr(fieldIndex)); - return ConvertAndCopyTo(cx, fieldType, datum, offset, vp); + return ConvertAndCopyTo(cx, fieldType, typedObj, offset, vp); } } - return ReportDatumTypeError(cx, JSMSG_OBJECT_NOT_EXTENSIBLE, datum); + return ReportTypedObjTypeError(cx, JSMSG_OBJECT_NOT_EXTENSIBLE, typedObj); } bool -TypedDatum::obj_setProperty(JSContext *cx, HandleObject obj, +TypedObject::obj_setProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, MutableHandleValue vp, bool strict) { @@ -1713,12 +1710,12 @@ TypedDatum::obj_setProperty(JSContext *cx, HandleObject obj, } bool -TypedDatum::obj_setElement(JSContext *cx, HandleObject obj, uint32_t index, +TypedObject::obj_setElement(JSContext *cx, HandleObject obj, uint32_t index, MutableHandleValue vp, bool strict) { - JS_ASSERT(obj->is()); - Rooted datum(cx, &obj->as()); - Rooted descr(cx, &datum->typeDescr()); + JS_ASSERT(obj->is()); + Rooted typedObj(cx, &obj->as()); + Rooted descr(cx, &typedObj->typeDescr()); switch (descr->kind()) { case TypeDescr::Scalar: @@ -1728,26 +1725,26 @@ TypedDatum::obj_setElement(JSContext *cx, HandleObject obj, uint32_t index, break; case TypeDescr::SizedArray: - return obj_setArrayElement(cx, datum, descr, index, vp); + return obj_setArrayElement(cx, typedObj, descr, index, vp); case TypeDescr::UnsizedArray: - return obj_setArrayElement(cx, datum, descr, index, vp); + return obj_setArrayElement(cx, typedObj, descr, index, vp); } - return ReportDatumTypeError(cx, JSMSG_OBJECT_NOT_EXTENSIBLE, datum); + return ReportTypedObjTypeError(cx, JSMSG_OBJECT_NOT_EXTENSIBLE, typedObj); } template /*static*/ bool -TypedDatum::obj_setArrayElement(JSContext *cx, - Handle datum, +TypedObject::obj_setArrayElement(JSContext *cx, + Handle typedObj, Handle descr, uint32_t index, MutableHandleValue vp) { JS_ASSERT(descr->is()); - if (index >= datum->length()) { + if (index >= typedObj->length()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPEDOBJECT_BINARYARRAY_BAD_INDEX); return false; @@ -1756,11 +1753,11 @@ TypedDatum::obj_setArrayElement(JSContext *cx, Rooted elementType(cx); elementType = &descr->as().elementType(); size_t offset = elementType->size() * index; - return ConvertAndCopyTo(cx, elementType, datum, offset, vp); + return ConvertAndCopyTo(cx, elementType, typedObj, offset, vp); } bool -TypedDatum::obj_setSpecial(JSContext *cx, HandleObject obj, +TypedObject::obj_setSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, MutableHandleValue vp, bool strict) { @@ -1769,12 +1766,12 @@ TypedDatum::obj_setSpecial(JSContext *cx, HandleObject obj, } bool -TypedDatum::obj_getGenericAttributes(JSContext *cx, HandleObject obj, +TypedObject::obj_getGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigned *attrsp) { uint32_t index; - Rooted datum(cx, &obj->as()); - TypeRepresentation *typeRepr = datum->typeRepresentation(); + Rooted typedObj(cx, &obj->as()); + TypeRepresentation *typeRepr = typedObj->typeRepresentation(); switch (typeRepr->kind()) { case TypeDescr::Scalar: @@ -1817,8 +1814,8 @@ static bool IsOwnId(JSContext *cx, HandleObject obj, HandleId id) { uint32_t index; - Rooted datum(cx, &obj->as()); - TypeRepresentation *typeRepr = datum->typeRepresentation(); + Rooted typedObj(cx, &obj->as()); + TypeRepresentation *typeRepr = typedObj->typeRepresentation(); switch (typeRepr->kind()) { case TypeDescr::Scalar: @@ -1838,7 +1835,7 @@ IsOwnId(JSContext *cx, HandleObject obj, HandleId id) } bool -TypedDatum::obj_setGenericAttributes(JSContext *cx, HandleObject obj, +TypedObject::obj_setGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigned *attrsp) { if (IsOwnId(cx, obj, id)) @@ -1854,7 +1851,7 @@ TypedDatum::obj_setGenericAttributes(JSContext *cx, HandleObject obj, } bool -TypedDatum::obj_deleteProperty(JSContext *cx, HandleObject obj, +TypedObject::obj_deleteProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, bool *succeeded) { Rooted id(cx, NameToId(name)); @@ -1871,7 +1868,7 @@ TypedDatum::obj_deleteProperty(JSContext *cx, HandleObject obj, } bool -TypedDatum::obj_deleteElement(JSContext *cx, HandleObject obj, uint32_t index, +TypedObject::obj_deleteElement(JSContext *cx, HandleObject obj, uint32_t index, bool *succeeded) { RootedId id(cx); @@ -1891,7 +1888,7 @@ TypedDatum::obj_deleteElement(JSContext *cx, HandleObject obj, uint32_t index, } bool -TypedDatum::obj_deleteSpecial(JSContext *cx, HandleObject obj, +TypedObject::obj_deleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, bool *succeeded) { RootedObject proto(cx, obj->getProto()); @@ -1904,14 +1901,14 @@ TypedDatum::obj_deleteSpecial(JSContext *cx, HandleObject obj, } bool -TypedDatum::obj_enumerate(JSContext *cx, HandleObject obj, JSIterateOp enum_op, +TypedObject::obj_enumerate(JSContext *cx, HandleObject obj, JSIterateOp enum_op, MutableHandleValue statep, MutableHandleId idp) { uint32_t index; - JS_ASSERT(obj->is()); - Rooted datum(cx, &obj->as()); - TypeRepresentation *typeRepr = datum->typeRepresentation(); + JS_ASSERT(obj->is()); + Rooted typedObj(cx, &obj->as()); + TypeRepresentation *typeRepr = typedObj->typeRepresentation(); switch (typeRepr->kind()) { case TypeDescr::Scalar: @@ -1936,17 +1933,17 @@ TypedDatum::obj_enumerate(JSContext *cx, HandleObject obj, JSIterateOp enum_op, case JSENUMERATE_INIT_ALL: case JSENUMERATE_INIT: statep.setInt32(0); - idp.set(INT_TO_JSID(datum->length())); + idp.set(INT_TO_JSID(typedObj->length())); break; case JSENUMERATE_NEXT: index = static_cast(statep.toInt32()); - if (index < datum->length()) { + if (index < typedObj->length()) { idp.set(INT_TO_JSID(index)); statep.setInt32(index + 1); } else { - JS_ASSERT(index == datum->length()); + JS_ASSERT(index == typedObj->length()); statep.setNull(); } @@ -1989,18 +1986,18 @@ TypedDatum::obj_enumerate(JSContext *cx, HandleObject obj, JSIterateOp enum_op, } /* static */ size_t -TypedDatum::dataOffset() +TypedObject::dataOffset() { // the offset of 7 is based on the alloc kind - return JSObject::getPrivateDataOffset(JS_DATUM_SLOT_DATA); + return JSObject::getPrivateDataOffset(JS_TYPEDOBJ_SLOT_DATA); } void -TypedDatum::neuter(JSContext *cx) +TypedObject::neuter(JSContext *cx) { - setSlot(JS_DATUM_SLOT_LENGTH, Int32Value(0)); - setSlot(JS_DATUM_SLOT_BYTELENGTH, Int32Value(0)); - setSlot(JS_DATUM_SLOT_BYTEOFFSET, Int32Value(0)); + setSlot(JS_TYPEDOBJ_SLOT_LENGTH, Int32Value(0)); + setSlot(JS_TYPEDOBJ_SLOT_BYTELENGTH, Int32Value(0)); + setSlot(JS_TYPEDOBJ_SLOT_BYTEOFFSET, Int32Value(0)); setPrivate(nullptr); } @@ -2011,7 +2008,7 @@ TypedDatum::neuter(JSContext *cx) const Class TransparentTypedObject::class_ = { "TypedObject", Class::NON_NATIVE | - JSCLASS_HAS_RESERVED_SLOTS(JS_DATUM_SLOTS) | + JSCLASS_HAS_RESERVED_SLOTS(JS_TYPEDOBJ_SLOTS) | JSCLASS_HAS_PRIVATE | JSCLASS_IMPLEMENTS_BARRIERS, JS_PropertyStub, @@ -2025,34 +2022,34 @@ const Class TransparentTypedObject::class_ = { nullptr, /* call */ nullptr, /* construct */ nullptr, /* hasInstance */ - TypedDatum::obj_trace, + TypedObject::obj_trace, JS_NULL_CLASS_SPEC, JS_NULL_CLASS_EXT, { - TypedDatum::obj_lookupGeneric, - TypedDatum::obj_lookupProperty, - TypedDatum::obj_lookupElement, - TypedDatum::obj_lookupSpecial, - TypedDatum::obj_defineGeneric, - TypedDatum::obj_defineProperty, - TypedDatum::obj_defineElement, - TypedDatum::obj_defineSpecial, - TypedDatum::obj_getGeneric, - TypedDatum::obj_getProperty, - TypedDatum::obj_getElement, - TypedDatum::obj_getSpecial, - TypedDatum::obj_setGeneric, - TypedDatum::obj_setProperty, - TypedDatum::obj_setElement, - TypedDatum::obj_setSpecial, - TypedDatum::obj_getGenericAttributes, - TypedDatum::obj_setGenericAttributes, - TypedDatum::obj_deleteProperty, - TypedDatum::obj_deleteElement, - TypedDatum::obj_deleteSpecial, + TypedObject::obj_lookupGeneric, + TypedObject::obj_lookupProperty, + TypedObject::obj_lookupElement, + TypedObject::obj_lookupSpecial, + TypedObject::obj_defineGeneric, + TypedObject::obj_defineProperty, + TypedObject::obj_defineElement, + TypedObject::obj_defineSpecial, + TypedObject::obj_getGeneric, + TypedObject::obj_getProperty, + TypedObject::obj_getElement, + TypedObject::obj_getSpecial, + TypedObject::obj_setGeneric, + TypedObject::obj_setProperty, + TypedObject::obj_setElement, + TypedObject::obj_setSpecial, + TypedObject::obj_getGenericAttributes, + TypedObject::obj_setGenericAttributes, + TypedObject::obj_deleteProperty, + TypedObject::obj_deleteElement, + TypedObject::obj_deleteSpecial, nullptr, nullptr, // watch/unwatch nullptr, /* slice */ - TypedDatum::obj_enumerate, + TypedObject::obj_enumerate, nullptr, /* thisObject */ } }; @@ -2106,7 +2103,7 @@ CheckOffset(int32_t offset, } /*static*/ bool -TypedDatum::constructSized(JSContext *cx, unsigned int argc, Value *vp) +TypedObject::constructSized(JSContext *cx, unsigned int argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); @@ -2123,7 +2120,7 @@ TypedDatum::constructSized(JSContext *cx, unsigned int argc, Value *vp) // Zero argument constructor: if (args.length() == 0) { int32_t length = LengthForType(*callee); - Rooted obj(cx, createZeroed(cx, callee, length)); + Rooted obj(cx, createZeroed(cx, callee, length)); if (!obj) return false; args.rval().setObject(*obj); @@ -2162,8 +2159,8 @@ TypedDatum::constructSized(JSContext *cx, unsigned int argc, Value *vp) return false; } - Rooted obj(cx); - obj = TypedDatum::createUnattached(cx, callee, LengthForType(*callee)); + Rooted obj(cx); + obj = TypedObject::createUnattached(cx, callee, LengthForType(*callee)); if (!obj) return false; @@ -2176,7 +2173,7 @@ TypedDatum::constructSized(JSContext *cx, unsigned int argc, Value *vp) if (args[0].isObject()) { // Create the typed object. int32_t length = LengthForType(*callee); - Rooted obj(cx, createZeroed(cx, callee, length)); + Rooted obj(cx, createZeroed(cx, callee, length)); if (!obj) return false; @@ -2194,7 +2191,7 @@ TypedDatum::constructSized(JSContext *cx, unsigned int argc, Value *vp) } /*static*/ bool -TypedDatum::constructUnsized(JSContext *cx, unsigned int argc, Value *vp) +TypedObject::constructUnsized(JSContext *cx, unsigned int argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); @@ -2214,7 +2211,7 @@ TypedDatum::constructUnsized(JSContext *cx, unsigned int argc, Value *vp) // Zero argument constructor: if (args.length() == 0) { - Rooted obj(cx, createZeroed(cx, callee, 0)); + Rooted obj(cx, createZeroed(cx, callee, 0)); if (!obj) return false; args.rval().setObject(*obj); @@ -2224,7 +2221,7 @@ TypedDatum::constructUnsized(JSContext *cx, unsigned int argc, Value *vp) // Length constructor. if (args[0].isInt32()) { int32_t length = args[0].toInt32(); - Rooted obj(cx, createZeroed(cx, callee, length)); + Rooted obj(cx, createZeroed(cx, callee, length)); if (!obj) return false; args.rval().setObject(*obj); @@ -2283,8 +2280,8 @@ TypedDatum::constructUnsized(JSContext *cx, unsigned int argc, Value *vp) length = maximumLength; } - Rooted obj(cx); - obj = TypedDatum::createUnattached(cx, callee, length); + Rooted obj(cx); + obj = TypedObject::createUnattached(cx, callee, length); if (!obj) return false; @@ -2315,7 +2312,7 @@ TypedDatum::constructUnsized(JSContext *cx, unsigned int argc, Value *vp) } // Create the unsized array. - Rooted obj(cx, createZeroed(cx, callee, length)); + Rooted obj(cx, createZeroed(cx, callee, length)); if (!obj) return false; @@ -2339,7 +2336,7 @@ TypedDatum::constructUnsized(JSContext *cx, unsigned int argc, Value *vp) const Class OpaqueTypedObject::class_ = { "Handle", Class::NON_NATIVE | - JSCLASS_HAS_RESERVED_SLOTS(JS_DATUM_SLOTS) | + JSCLASS_HAS_RESERVED_SLOTS(JS_TYPEDOBJ_SLOTS) | JSCLASS_HAS_PRIVATE | JSCLASS_IMPLEMENTS_BARRIERS, JS_PropertyStub, @@ -2353,34 +2350,34 @@ const Class OpaqueTypedObject::class_ = { nullptr, /* call */ nullptr, /* construct */ nullptr, /* hasInstance */ - TypedDatum::obj_trace, + TypedObject::obj_trace, JS_NULL_CLASS_SPEC, JS_NULL_CLASS_EXT, { - TypedDatum::obj_lookupGeneric, - TypedDatum::obj_lookupProperty, - TypedDatum::obj_lookupElement, - TypedDatum::obj_lookupSpecial, - TypedDatum::obj_defineGeneric, - TypedDatum::obj_defineProperty, - TypedDatum::obj_defineElement, - TypedDatum::obj_defineSpecial, - TypedDatum::obj_getGeneric, - TypedDatum::obj_getProperty, - TypedDatum::obj_getElement, - TypedDatum::obj_getSpecial, - TypedDatum::obj_setGeneric, - TypedDatum::obj_setProperty, - TypedDatum::obj_setElement, - TypedDatum::obj_setSpecial, - TypedDatum::obj_getGenericAttributes, - TypedDatum::obj_setGenericAttributes, - TypedDatum::obj_deleteProperty, - TypedDatum::obj_deleteElement, - TypedDatum::obj_deleteSpecial, + TypedObject::obj_lookupGeneric, + TypedObject::obj_lookupProperty, + TypedObject::obj_lookupElement, + TypedObject::obj_lookupSpecial, + TypedObject::obj_defineGeneric, + TypedObject::obj_defineProperty, + TypedObject::obj_defineElement, + TypedObject::obj_defineSpecial, + TypedObject::obj_getGeneric, + TypedObject::obj_getProperty, + TypedObject::obj_getElement, + TypedObject::obj_getSpecial, + TypedObject::obj_setGeneric, + TypedObject::obj_setProperty, + TypedObject::obj_setElement, + TypedObject::obj_setSpecial, + TypedObject::obj_getGenericAttributes, + TypedObject::obj_setGenericAttributes, + TypedObject::obj_deleteProperty, + TypedObject::obj_deleteElement, + TypedObject::obj_deleteSpecial, nullptr, nullptr, // watch/unwatch nullptr, // slice - TypedDatum::obj_enumerate, + TypedObject::obj_enumerate, nullptr, /* thisObject */ } }; @@ -2405,9 +2402,9 @@ js::NewOpaqueTypedObject(JSContext *cx, unsigned argc, Value *vp) JS_ASSERT(args[0].isObject() && args[0].toObject().is()); Rooted descr(cx, &args[0].toObject().as()); - int32_t length = DatumLengthFromType(*descr); - Rooted obj(cx); - obj = TypedDatum::createUnattachedWithClass(cx, &OpaqueTypedObject::class_, descr, length); + int32_t length = TypedObjLengthFromType(*descr); + Rooted obj(cx); + obj = TypedObject::createUnattachedWithClass(cx, &OpaqueTypedObject::class_, descr, length); if (!obj) return false; args.rval().setObject(*obj); @@ -2415,20 +2412,20 @@ js::NewOpaqueTypedObject(JSContext *cx, unsigned argc, Value *vp) } bool -js::NewDerivedTypedDatum(JSContext *cx, unsigned argc, Value *vp) +js::NewDerivedTypedObject(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); JS_ASSERT(args.length() == 3); JS_ASSERT(args[0].isObject() && args[0].toObject().is()); - JS_ASSERT(args[1].isObject() && args[1].toObject().is()); + JS_ASSERT(args[1].isObject() && args[1].toObject().is()); JS_ASSERT(args[2].isInt32()); Rooted descr(cx, &args[0].toObject().as()); - Rooted datum(cx, &args[1].toObject().as()); + Rooted typedObj(cx, &args[1].toObject().as()); int32_t offset = args[2].toInt32(); - Rooted obj(cx); - obj = TypedDatum::createDerived(cx, descr, datum, offset); + Rooted obj(cx); + obj = TypedObject::createDerived(cx, descr, typedObj, offset); if (!obj) return false; @@ -2437,24 +2434,25 @@ js::NewDerivedTypedDatum(JSContext *cx, unsigned argc, Value *vp) } bool -js::AttachDatum(ThreadSafeContext *, unsigned argc, Value *vp) +js::AttachTypedObject(ThreadSafeContext *, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); JS_ASSERT(args.length() == 3); - JS_ASSERT(args[0].isObject() && args[0].toObject().is()); - JS_ASSERT(args[1].isObject() && args[1].toObject().is()); + JS_ASSERT(args[0].isObject() && args[0].toObject().is()); + JS_ASSERT(args[1].isObject() && args[1].toObject().is()); JS_ASSERT(args[2].isInt32()); - TypedDatum &handle = args[0].toObject().as(); - TypedDatum &target = args[1].toObject().as(); + TypedObject &handle = args[0].toObject().as(); + TypedObject &target = args[1].toObject().as(); JS_ASSERT(handle.typedMem() == nullptr); // must not be attached already size_t offset = args[2].toInt32(); handle.attach(target, offset); return true; } -JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::AttachDatumJitInfo, AttachDatumJitInfo, - js::AttachDatum); +JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::AttachTypedObjectJitInfo, + AttachTypedObjectJitInfo, + js::AttachTypedObject); bool js::ObjectIsTypeDescr(ThreadSafeContext *, unsigned argc, Value *vp) @@ -2498,18 +2496,18 @@ JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::ObjectIsTransparentTypedObjectJitInfo, js::ObjectIsTransparentTypedObject); bool -js::DatumIsAttached(ThreadSafeContext *cx, unsigned argc, Value *vp) +js::TypedObjectIsAttached(ThreadSafeContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); - JS_ASSERT(args[0].isObject() && args[0].toObject().is()); - TypedDatum &datum = args[0].toObject().as(); - args.rval().setBoolean(datum.typedMem() != nullptr); + JS_ASSERT(args[0].isObject() && args[0].toObject().is()); + TypedObject &typedObj = args[0].toObject().as(); + args.rval().setBoolean(typedObj.typedMem() != nullptr); return true; } -JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::DatumIsAttachedJitInfo, - DatumIsAttachedJitInfo, - js::DatumIsAttached); +JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::TypedObjectIsAttachedJitInfo, + TypedObjectIsAttachedJitInfo, + js::TypedObjectIsAttached); bool js::ClampToUint8(ThreadSafeContext *, unsigned argc, Value *vp) @@ -2529,26 +2527,26 @@ js::Memcpy(ThreadSafeContext *, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); JS_ASSERT(args.length() == 5); - JS_ASSERT(args[0].isObject() && args[0].toObject().is()); + JS_ASSERT(args[0].isObject() && args[0].toObject().is()); JS_ASSERT(args[1].isInt32()); - JS_ASSERT(args[2].isObject() && args[2].toObject().is()); + JS_ASSERT(args[2].isObject() && args[2].toObject().is()); JS_ASSERT(args[3].isInt32()); JS_ASSERT(args[4].isInt32()); - TypedDatum &targetDatum = args[0].toObject().as(); + TypedObject &targetTypedObj = args[0].toObject().as(); int32_t targetOffset = args[1].toInt32(); - TypedDatum &sourceDatum = args[2].toObject().as(); + TypedObject &sourceTypedObj = args[2].toObject().as(); int32_t sourceOffset = args[3].toInt32(); int32_t size = args[4].toInt32(); JS_ASSERT(targetOffset >= 0); JS_ASSERT(sourceOffset >= 0); JS_ASSERT(size >= 0); - JS_ASSERT((size_t) (size + targetOffset) <= targetDatum.size()); - JS_ASSERT((size_t) (size + sourceOffset) <= sourceDatum.size()); + JS_ASSERT((size_t) (size + targetOffset) <= targetTypedObj.size()); + JS_ASSERT((size_t) (size + sourceOffset) <= sourceTypedObj.size()); - uint8_t *target = targetDatum.typedMem(targetOffset); - uint8_t *source = sourceDatum.typedMem(sourceOffset); + uint8_t *target = targetTypedObj.typedMem(targetOffset); + uint8_t *source = sourceTypedObj.typedMem(sourceOffset); memcpy(target, source, size); args.rval().setUndefined(); return true; @@ -2592,25 +2590,26 @@ js::StoreScalar##T::Func(ThreadSafeContext *, unsigned argc, Value *vp) { \ CallArgs args = CallArgsFromVp(argc, vp); \ JS_ASSERT(args.length() == 3); \ - JS_ASSERT(args[0].isObject() && args[0].toObject().is()); \ + JS_ASSERT(args[0].isObject() && args[0].toObject().is()); \ JS_ASSERT(args[1].isInt32()); \ JS_ASSERT(args[2].isNumber()); \ \ - TypedDatum &datum = args[0].toObject().as(); \ + TypedObject &typedObj = args[0].toObject().as(); \ int32_t offset = args[1].toInt32(); \ \ /* Should be guaranteed by the typed objects API: */ \ JS_ASSERT(offset % MOZ_ALIGNOF(T) == 0); \ \ - T *target = reinterpret_cast(datum.typedMem(offset)); \ + T *target = reinterpret_cast(typedObj.typedMem(offset)); \ double d = args[2].toNumber(); \ *target = ConvertScalar(d); \ args.rval().setUndefined(); \ return true; \ } \ \ -JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::StoreScalar##T::JitInfo, StoreScalar##T, \ - js::StoreScalar##T::Func); +JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::StoreScalar##T::JitInfo, \ + StoreScalar##T, \ + js::StoreScalar##T::Func); #define JS_STORE_REFERENCE_CLASS_IMPL(_constant, T, _name) \ bool \ @@ -2618,45 +2617,46 @@ js::StoreReference##T::Func(ThreadSafeContext *, unsigned argc, Value *vp) { \ CallArgs args = CallArgsFromVp(argc, vp); \ JS_ASSERT(args.length() == 3); \ - JS_ASSERT(args[0].isObject() && args[0].toObject().is()); \ + JS_ASSERT(args[0].isObject() && args[0].toObject().is()); \ JS_ASSERT(args[1].isInt32()); \ \ - TypedDatum &datum = args[0].toObject().as(); \ + TypedObject &typedObj = args[0].toObject().as(); \ int32_t offset = args[1].toInt32(); \ \ /* Should be guaranteed by the typed objects API: */ \ JS_ASSERT(offset % MOZ_ALIGNOF(T) == 0); \ \ - T *target = reinterpret_cast(datum.typedMem(offset)); \ + T *target = reinterpret_cast(typedObj.typedMem(offset)); \ store(target, args[2]); \ args.rval().setUndefined(); \ return true; \ } \ \ - JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::StoreReference##T::JitInfo, StoreReference##T, \ - js::StoreReference##T::Func); +JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::StoreReference##T::JitInfo, \ + StoreReference##T, \ + js::StoreReference##T::Func); -#define JS_LOAD_SCALAR_CLASS_IMPL(_constant, T, _name) \ -bool \ -js::LoadScalar##T::Func(ThreadSafeContext *, unsigned argc, Value *vp) \ -{ \ - CallArgs args = CallArgsFromVp(argc, vp); \ - JS_ASSERT(args.length() == 2); \ - JS_ASSERT(args[0].isObject() && args[0].toObject().is()); \ - JS_ASSERT(args[1].isInt32()); \ - \ - TypedDatum &datum = args[0].toObject().as(); \ - int32_t offset = args[1].toInt32(); \ - \ - /* Should be guaranteed by the typed objects API: */ \ - JS_ASSERT(offset % MOZ_ALIGNOF(T) == 0); \ - \ - T *target = reinterpret_cast(datum.typedMem(offset)); \ - args.rval().setNumber((double) *target); \ - return true; \ -} \ - \ -JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::LoadScalar##T::JitInfo, LoadScalar##T, \ +#define JS_LOAD_SCALAR_CLASS_IMPL(_constant, T, _name) \ +bool \ +js::LoadScalar##T::Func(ThreadSafeContext *, unsigned argc, Value *vp) \ +{ \ + CallArgs args = CallArgsFromVp(argc, vp); \ + JS_ASSERT(args.length() == 2); \ + JS_ASSERT(args[0].isObject() && args[0].toObject().is()); \ + JS_ASSERT(args[1].isInt32()); \ + \ + TypedObject &typedObj = args[0].toObject().as(); \ + int32_t offset = args[1].toInt32(); \ + \ + /* Should be guaranteed by the typed objects API: */ \ + JS_ASSERT(offset % MOZ_ALIGNOF(T) == 0); \ + \ + T *target = reinterpret_cast(typedObj.typedMem(offset)); \ + args.rval().setNumber((double) *target); \ + return true; \ +} \ + \ +JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::LoadScalar##T::JitInfo, LoadScalar##T, \ js::LoadScalar##T::Func); #define JS_LOAD_REFERENCE_CLASS_IMPL(_constant, T, _name) \ @@ -2665,21 +2665,22 @@ js::LoadReference##T::Func(ThreadSafeContext *, unsigned argc, Value *vp) { \ CallArgs args = CallArgsFromVp(argc, vp); \ JS_ASSERT(args.length() == 2); \ - JS_ASSERT(args[0].isObject() && args[0].toObject().is()); \ + JS_ASSERT(args[0].isObject() && args[0].toObject().is()); \ JS_ASSERT(args[1].isInt32()); \ \ - TypedDatum &datum = args[0].toObject().as(); \ + TypedObject &typedObj = args[0].toObject().as(); \ int32_t offset = args[1].toInt32(); \ \ /* Should be guaranteed by the typed objects API: */ \ JS_ASSERT(offset % MOZ_ALIGNOF(T) == 0); \ \ - T *target = reinterpret_cast(datum.typedMem(offset)); \ + T *target = reinterpret_cast(typedObj.typedMem(offset)); \ load(target, args.rval()); \ return true; \ } \ \ -JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::LoadReference##T::JitInfo, LoadReference##T, \ +JS_JITINFO_NATIVE_PARALLEL_THREADSAFE(js::LoadReference##T::JitInfo, \ + LoadReference##T, \ js::LoadReference##T::Func); // Because the precise syntax for storing values/objects/strings diff --git a/js/src/builtin/TypedObject.h b/js/src/builtin/TypedObject.h index a3dd1bd2227..060e7c5732f 100644 --- a/js/src/builtin/TypedObject.h +++ b/js/src/builtin/TypedObject.h @@ -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 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 static bool obj_getArrayElement(JSContext *cx, - Handle datum, + Handle typedObj, Handle typeDescr, uint32_t index, MutableHandleValue vp); template static bool obj_setArrayElement(JSContext *cx, - Handle datum, + Handle typedObj, Handle 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 typedContents, + Handle 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(); + return getReservedSlot(JS_TYPEDOBJ_SLOT_OWNER).toObject().as(); } TypeDescr &typeDescr() const { - return getReservedSlot(JS_DATUM_SLOT_TYPE_DESCR).toObject().as(); + return getReservedSlot(JS_TYPEDOBJ_SLOT_TYPE_DESCR).toObject().as(); } 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 HandleTypedDatum; +typedef Handle HandleTypedObject; -class TransparentTypedObject : public TypedDatum +class TransparentTypedObject : public TypedObject { public: static const Class class_; @@ -466,7 +476,7 @@ class TransparentTypedObject : public TypedDatum typedef Handle 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() const template <> inline bool -JSObject::is() const +JSObject::is() const { - return IsTypedDatumClass(getClass()); + return IsTypedObjectClass(getClass()); } #endif /* builtin_TypedObject_h */ diff --git a/js/src/builtin/TypedObject.js b/js/src/builtin/TypedObject.js index 5173de4223e..150b1359bfc 100644 --- a/js/src/builtin/TypedObject.js +++ b/js/src/builtin/TypedObject.js @@ -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); diff --git a/js/src/builtin/TypedObjectConstants.h b/js/src/builtin/TypedObjectConstants.h index 9ceae8ed7aa..6cff93ebf3c 100644 --- a/js/src/builtin/TypedObjectConstants.h +++ b/js/src/builtin/TypedObjectConstants.h @@ -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 diff --git a/js/src/builtin/TypedObjectSimple.h b/js/src/builtin/TypedObjectSimple.h index 6136037ad16..5681c360946 100644 --- a/js/src/builtin/TypedObjectSimple.h +++ b/js/src/builtin/TypedObjectSimple.h @@ -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 diff --git a/js/src/jit/CodeGenerator.cpp b/js/src/jit/CodeGenerator.cpp index 4537d713b70..02e4ba2f1df 100644 --- a/js/src/jit/CodeGenerator.cpp +++ b/js/src/jit/CodeGenerator.cpp @@ -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; } diff --git a/js/src/jit/IonBuilder.cpp b/js/src/jit/IonBuilder.cpp index 12f11f751b8..49a7619c81b 100644 --- a/js/src/jit/IonBuilder.cpp +++ b/js/src/jit/IonBuilder.cpp @@ -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; } diff --git a/js/src/jit/ParallelFunctions.cpp b/js/src/jit/ParallelFunctions.cpp index ee294f93f86..6060c55b01a 100644 --- a/js/src/jit/ParallelFunctions.cpp +++ b/js/src/jit/ParallelFunctions.cpp @@ -82,18 +82,18 @@ jit::ParallelWriteGuard(ForkJoinContext *cx, JSObject *object) JS_ASSERT(ForkJoinContext::current() == cx); - if (object->is()) { - TypedDatum &datum = object->as(); + if (object->is()) { + TypedObject &typedObj = object->as(); - // 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()); // in case JIT supplies something bogus - uint8_t *typedMem = datum->typedMem(); + JS_ASSERT(typedObj->is()); // in case JIT supplies something bogus + uint8_t *typedMem = typedObj->typedMem(); return (typedMem >= cx->targetRegionStart && typedMem < cx->targetRegionEnd); } diff --git a/js/src/jit/ParallelFunctions.h b/js/src/jit/ParallelFunctions.h index e903e65c30b..83780f8b1f6 100644 --- a/js/src/jit/ParallelFunctions.h +++ b/js/src/jit/ParallelFunctions.h @@ -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); diff --git a/js/src/jit/VMFunctions.cpp b/js/src/jit/VMFunctions.cpp index 242dd2c9a26..c03d0ff33fb 100644 --- a/js/src/jit/VMFunctions.cpp +++ b/js/src/jit/VMFunctions.cpp @@ -961,10 +961,10 @@ CreateDerivedTypedObj(JSContext *cx, HandleObject descr, HandleObject owner, int32_t offset) { JS_ASSERT(descr->is()); - JS_ASSERT(owner->is()); + JS_ASSERT(owner->is()); Rooted descr1(cx, &descr->as()); - Rooted owner1(cx, &owner->as()); - return TypedDatum::createDerived(cx, descr1, owner1, offset); + Rooted owner1(cx, &owner->as()); + return TypedObject::createDerived(cx, descr1, owner1, offset); } JSString * diff --git a/js/src/vm/ForkJoin.cpp b/js/src/vm/ForkJoin.cpp index 76acb5ff78b..29823012909 100644 --- a/js/src/vm/ForkJoin.cpp +++ b/js/src/vm/ForkJoin.cpp @@ -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()); + JS_ASSERT(args[0].isObject() && args[0].toObject().is()); JS_ASSERT(args[1].isInt32()); JS_ASSERT(args[2].isInt32()); - uint8_t *mem = args[0].toObject().as().typedMem(); + uint8_t *mem = args[0].toObject().as().typedMem(); int32_t start = args[1].toInt32(); int32_t end = args[2].toInt32(); diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp index f4f14ebb92b..d646c929506 100644 --- a/js/src/vm/SelfHosting.cpp +++ b/js/src/vm/SelfHosting.cpp @@ -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::AttachDatumJitInfo, 5, 0), + JS_FNINFO("AttachTypedObject", + JSNativeThreadSafeWrapper, + &js::AttachTypedObjectJitInfo, 5, 0), JS_FNINFO("ObjectIsTypeDescr", JSNativeThreadSafeWrapper, &js::ObjectIsTypeDescrJitInfo, 5, 0), JS_FNINFO("ObjectIsTransparentTypedObject", JSNativeThreadSafeWrapper, &js::ObjectIsTransparentTypedObjectJitInfo, 5, 0), - JS_FNINFO("DatumIsAttached", - JSNativeThreadSafeWrapper, - &js::DatumIsAttachedJitInfo, 1, 0), + JS_FNINFO("TypedObjectIsAttached", + JSNativeThreadSafeWrapper, + &js::TypedObjectIsAttachedJitInfo, 1, 0), JS_FNINFO("ObjectIsOpaqueTypedObject", JSNativeThreadSafeWrapper, &js::ObjectIsOpaqueTypedObjectJitInfo, 5, 0), diff --git a/js/src/vm/TypedArrayObject.cpp b/js/src/vm/TypedArrayObject.cpp index ee63a93fed0..071b1343995 100644 --- a/js/src/vm/TypedArrayObject.cpp +++ b/js/src/vm/TypedArrayObject.cpp @@ -2640,7 +2640,7 @@ ArrayBufferViewObject::neuter(JSContext *cx) else if (is()) as().neuter(cx); else - as().neuter(cx); + as().neuter(cx); } // this default implementation is only valid for integer types diff --git a/js/src/vm/TypedArrayObject.h b/js/src/vm/TypedArrayObject.h index 7874daabe4a..6ca2606c48c 100644 --- a/js/src/vm/TypedArrayObject.h +++ b/js/src/vm/TypedArrayObject.h @@ -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() const { return is() || is() || - IsTypedDatumClass(getClass()); + IsTypedObjectClass(getClass()); } #endif /* vm_TypedArrayObject_h */