Bug 737245 - Typed Arrays should handle cross-compartment wrappers; part2. r=luke
authorBobby Holley <bobbyholley@gmail.com>
Thu, 05 Apr 2012 09:39:25 +1000
changeset 94352 e67ea61f46b6fa360f96249e6ace1da1191e6427
parent 94351 1cbedc2d11c6ec7c83480e5ce7c2ff532d6d35de
child 94353 17e95355ad77035e120598c816ff917f951eebbf
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs737245
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 737245 - Typed Arrays should handle cross-compartment wrappers; part2. r=luke
js/src/jsobj.h
js/src/jsobjinlines.h
js/src/jstypedarray.cpp
js/src/jstypedarray.h
js/src/jstypedarrayinlines.h
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -1052,16 +1052,17 @@ struct JSObject : public js::ObjectImpl
     inline bool isQName() const;
     inline bool isPrimitive() const;
     inline bool isProxy() const;
     inline bool isRegExp() const;
     inline bool isRegExpStatics() const;
     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;
 
     /* Subtypes of ScopeObject. */
     inline bool isBlock() const;
     inline bool isCall() const;
     inline bool isDeclEnv() const;
--- a/js/src/jsobjinlines.h
+++ b/js/src/jsobjinlines.h
@@ -798,16 +798,17 @@ inline bool JSObject::isObject() const {
 inline bool JSObject::isPrimitive() const { return isNumber() || isString() || isBoolean(); }
 inline bool JSObject::isRegExp() const { return hasClass(&js::RegExpClass); }
 inline bool JSObject::isRegExpStatics() const { return hasClass(&js::RegExpStaticsClass); }
 inline bool JSObject::isScope() const { return isCall() || isDeclEnv() || isNestedScope(); }
 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); }
 
 inline bool
 JSObject::isXMLId() const
 {
     return hasClass(&js::QNameClass)
--- a/js/src/jstypedarray.cpp
+++ b/js/src/jstypedarray.cpp
@@ -2508,27 +2508,42 @@ namespace js {
 
 bool
 IsFastTypedArrayClass(const Class *clasp)
 {
     return &TypedArray::fastClasses[0] <= 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();
 }
 
 JS_FRIEND_API(JSBool)
 js_IsTypedArray(JSObject *obj)
 {
     JS_ASSERT(obj);
     Class *clasp = obj->getClass();
@@ -2627,34 +2642,39 @@ js_CreateTypedArrayWithBuffer(JSContext 
 
     AutoArrayRooter tvr(cx, ArrayLength(vals), vals);
     return TypedArrayConstruct(cx, atype, argc, &vals[0]);
 }
 
 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);
 }
--- a/js/src/jstypedarray.h
+++ b/js/src/jstypedarray.h
@@ -281,16 +281,22 @@ struct JS_FRIEND_API(TypedArray) {
 
     static int lengthOffset();
     static int dataOffset();
 };
 
 extern bool
 IsFastTypedArrayClass(const Class *clasp);
 
+extern bool
+IsSlowTypedArrayClass(const Class *clasp);
+
+extern bool
+IsFastOrSlowTypedArray(JSObject *obj);
+
 } // namespace js
 
 /* Friend API methods */
 
 JS_FRIEND_API(JSBool)
 js_IsTypedArray(JSObject *obj);
 
 JS_FRIEND_API(JSBool)
--- a/js/src/jstypedarrayinlines.h
+++ b/js/src/jstypedarrayinlines.h
@@ -65,38 +65,44 @@ ClampIntForUint8Array(int32_t x)
         return 0;
     if (x > 255)
         return 255;
     return 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);
 }
 
 }
 #endif /* jstypedarrayinlines_h */