Bug 737245 - Typed Arrays should handle cross-compartment wrappers; part2. r=luke

This commit is contained in:
Bobby Holley 2012-04-05 09:39:25 +10:00
parent 75a3219ca6
commit 726caa9a7c
5 changed files with 34 additions and 0 deletions

View File

@ -1057,6 +1057,7 @@ struct JSObject : public js::ObjectImpl
inline bool isScope() const;
inline bool isScript() const;
inline bool isStopIteration() const;
inline bool isTypedArray() const;
inline bool isWeakMap() const;
inline bool isXML() const;
inline bool isXMLId() const;

View File

@ -803,6 +803,7 @@ inline bool JSObject::isStaticBlock() const { return isBlock() && !getProto(); }
inline bool JSObject::isStopIteration() const { return hasClass(&js::StopIterationClass); }
inline bool JSObject::isStrictArguments() const { return hasClass(&js::StrictArgumentsObjectClass); }
inline bool JSObject::isString() const { return hasClass(&js::StringClass); }
inline bool JSObject::isTypedArray() const { return IsFastTypedArrayClass(getClass()); };
inline bool JSObject::isWeakMap() const { return hasClass(&js::WeakMapClass); }
inline bool JSObject::isWith() const { return hasClass(&js::WithClass); }
inline bool JSObject::isXML() const { return hasClass(&js::XMLClass); }

View File

@ -2513,17 +2513,32 @@ IsFastTypedArrayClass(const Class *clasp)
clasp < &TypedArray::fastClasses[TypedArray::TYPE_MAX];
}
bool
IsSlowTypedArrayClass(const Class *clasp)
{
return &TypedArray::slowClasses[0] <= clasp &&
clasp < &TypedArray::slowClasses[TypedArray::TYPE_MAX];
}
bool IsFastOrSlowTypedArray(JSObject *obj)
{
Class *clasp = obj->getClass();
return IsFastTypedArrayClass(clasp) || IsSlowTypedArrayClass(clasp);
}
} // namespace js
uint32_t
JS_GetArrayBufferByteLength(JSObject *obj)
{
JS_ASSERT(obj->isArrayBuffer());
return obj->arrayBufferByteLength();
}
uint8_t *
JS_GetArrayBufferData(JSObject *obj)
{
JS_ASSERT(obj->isArrayBuffer());
return obj->arrayBufferDataOffset();
}
@ -2632,29 +2647,34 @@ js_CreateTypedArrayWithBuffer(JSContext *cx, int atype, JSObject *bufArg,
uint32_t
JS_GetTypedArrayLength(JSObject *obj)
{
JS_ASSERT(obj->isTypedArray());
return obj->getSlot(TypedArray::FIELD_LENGTH).toInt32();
}
uint32_t
JS_GetTypedArrayByteOffset(JSObject *obj)
{
JS_ASSERT(obj->isTypedArray());
return obj->getSlot(TypedArray::FIELD_BYTEOFFSET).toInt32();
}
uint32_t
JS_GetTypedArrayByteLength(JSObject *obj)
{
JS_ASSERT(obj->isTypedArray());
return obj->getSlot(TypedArray::FIELD_BYTELENGTH).toInt32();
}
uint32_t
JS_GetTypedArrayType(JSObject *obj)
{
JS_ASSERT(obj->isTypedArray());
return obj->getSlot(TypedArray::FIELD_TYPE).toInt32();
}
void *
JS_GetTypedArrayData(JSObject *obj)
{
JS_ASSERT(obj->isTypedArray());
return TypedArray::getDataOffset(obj);
}

View File

@ -286,6 +286,12 @@ struct JS_FRIEND_API(TypedArray) {
extern bool
IsFastTypedArrayClass(const Class *clasp);
extern bool
IsSlowTypedArrayClass(const Class *clasp);
extern bool
IsFastOrSlowTypedArray(JSObject *obj);
} // namespace js
/* Friend API methods */

View File

@ -70,31 +70,37 @@ ClampIntForUint8Array(int32_t x)
inline uint32_t
TypedArray::getLength(JSObject *obj) {
JS_ASSERT(IsFastOrSlowTypedArray(obj));
return obj->getFixedSlot(FIELD_LENGTH).toInt32();
}
inline uint32_t
TypedArray::getByteOffset(JSObject *obj) {
JS_ASSERT(IsFastOrSlowTypedArray(obj));
return obj->getFixedSlot(FIELD_BYTEOFFSET).toInt32();
}
inline uint32_t
TypedArray::getByteLength(JSObject *obj) {
JS_ASSERT(IsFastOrSlowTypedArray(obj));
return obj->getFixedSlot(FIELD_BYTELENGTH).toInt32();
}
inline uint32_t
TypedArray::getType(JSObject *obj) {
JS_ASSERT(IsFastOrSlowTypedArray(obj));
return obj->getFixedSlot(FIELD_TYPE).toInt32();
}
inline JSObject *
TypedArray::getBuffer(JSObject *obj) {
JS_ASSERT(IsFastOrSlowTypedArray(obj));
return &obj->getFixedSlot(FIELD_BUFFER).toObject();
}
inline void *
TypedArray::getDataOffset(JSObject *obj) {
JS_ASSERT(IsFastOrSlowTypedArray(obj));
return (void *)obj->getPrivate(NUM_FIXED_SLOTS);
}