Finalize typed arrays via the background thread (bug 625250, r=njn).
authorAndreas Gal <gal@mozilla.com>
Wed, 12 Jan 2011 18:40:29 -0800
changeset 60575 b93dcfdb15e18857d89e6c057a26d280a78f2335
parent 60574 5d3b8f835242aaf3532c8095ed730a6f277ca4a8
child 60576 707130d68d1be2727c8d4112ca6cca617e120bd9
push id18037
push usercleary@mozilla.com
push dateFri, 14 Jan 2011 17:42:55 +0000
treeherdermozilla-central@4e0501a0c5e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs625250
milestone2.0b10pre
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
Finalize typed arrays via the background thread (bug 625250, r=njn).
js/src/jstypedarray.cpp
--- a/js/src/jstypedarray.cpp
+++ b/js/src/jstypedarray.cpp
@@ -118,17 +118,17 @@ ArrayBuffer::prop_getByteLength(JSContex
 }
 
 void
 ArrayBuffer::class_finalize(JSContext *cx, JSObject *obj)
 {
     ArrayBuffer *abuf = ArrayBuffer::fromJSObject(obj);
     if (abuf)
         abuf->freeStorage(cx);
-    delete abuf;
+    cx->destroy<ArrayBuffer>(abuf);
 }
 
 /*
  * new ArrayBuffer(byteLength)
  */
 JSBool
 ArrayBuffer::class_constructor(JSContext *cx, uintN argc, Value *vp)
 {
@@ -156,24 +156,24 @@ ArrayBuffer::create(JSContext *cx, uintN
          * as an integer value; if someone actually ever complains (validly), then we
          * can fix.
          */
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                              JSMSG_BAD_ARRAY_LENGTH);
         return false;
     }
 
-    ArrayBuffer *abuf = new ArrayBuffer();
+    ArrayBuffer *abuf = cx->create<ArrayBuffer>();
     if (!abuf) {
         JS_ReportOutOfMemory(cx);
         return false;
     }
 
     if (!abuf->allocateStorage(cx, nbytes)) {
-        delete abuf;
+        cx->destroy<ArrayBuffer>(abuf);
         return false;
     }
 
     obj->setPrivate(abuf);
     rval->setObject(*obj);
     return true;
 }
 
@@ -752,24 +752,24 @@ class TypedArrayTemplate
         // figure out the type of the first argument;
         // no args is treated like an int arg of 0.
         jsuint len = 0;
         bool hasLen = true;
         if (argc > 0)
             hasLen = ValueIsLength(cx, argv[0], &len);
 
         if (hasLen) {
-            tarray = new ThisTypeArray();
+            tarray = cx->create<ThisTypeArray>();
             if (!tarray) {
                 JS_ReportOutOfMemory(cx);
                 return false;
             }
 
             if (!tarray->init(cx, len)) {
-                delete tarray;
+                cx->destroy<ThisTypeArray>(tarray);
                 return false;
             }
         } else if (argv[0].isObject()) {
             int32_t byteOffset = -1;
             int32_t length = -1;
 
             if (argc > 1) {
                 if (!ValueToInt32(cx, argv[1], &byteOffset))
@@ -786,41 +786,41 @@ class TypedArrayTemplate
                     return false;
                 if (length < 0) {
                     JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                          JSMSG_TYPED_ARRAY_NEGATIVE_ARG, "2");
                     return false;
                 }
             }
 
-            tarray = new ThisTypeArray();
+            tarray = cx->create<ThisTypeArray>();
             if (!tarray) {
                 JS_ReportOutOfMemory(cx);
                 return false;
             }
 
             if (!tarray->init(cx, &argv[0].toObject(), byteOffset, length)) {
-                delete tarray;
+                cx->destroy<ThisTypeArray>(tarray);
                 return false;
             }
         } else {
             JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                  JSMSG_TYPED_ARRAY_BAD_ARGS);
             return false;
         }
 
         rval->setObject(*obj);
         return makeFastWithPrivate(cx, obj, tarray);
     }
 
     static void
     class_finalize(JSContext *cx, JSObject *obj)
     {
         ThisTypeArray *tarray = ThisTypeArray::fromJSObject(obj);
-        delete tarray;
+        cx->destroy<ThisTypeArray>(tarray);
     }
 
     /* slice(start[, end]) */
     static JSBool
     fun_slice(JSContext *cx, uintN argc, Value *vp)
     {
         Value *argv = JS_ARGV(cx, vp);
         JSObject *obj = ComputeThisFromVp(cx, vp);
@@ -866,30 +866,30 @@ class TypedArrayTemplate
                     end = length;
                 }
             }
         }
 
         if (begin > end)
             begin = end;
 
-        ThisTypeArray *ntarray = tarray->slice(begin, end);
+        ThisTypeArray *ntarray = tarray->slice(cx, begin, end);
         if (!ntarray) {
             // this should rarely ever happen
             JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                  JSMSG_TYPED_ARRAY_BAD_ARGS);
             return false;
         }
 
         // note the usage of NewObject here -- we don't want the
         // constructor to be called!
         JS_ASSERT(slowClass() != &js_FunctionClass);
         JSObject *nobj = NewNonFunction<WithProto::Class>(cx, slowClass(), NULL, NULL);
         if (!nobj) {
-            delete ntarray;
+            cx->destroy<ThisTypeArray>(ntarray);
             return false;
         }
 
         vp->setObject(*nobj);
         return makeFastWithPrivate(cx, nobj, ntarray);
     }
 
     /* set(array[, offset]) */
@@ -1082,22 +1082,22 @@ class TypedArrayTemplate
     setIndex(uint32 index, NativeType val)
     {
         *(static_cast<NativeType*>(data) + index) = val;
     }
 
     inline void copyIndexToValue(JSContext *cx, uint32 index, Value *vp);
 
     ThisTypeArray *
-    slice(uint32 begin, uint32 end)
+    slice(JSContext *cx, uint32 begin, uint32 end)
     {
         if (begin > length || end > length)
             return NULL;
 
-        ThisTypeArray *tarray = new ThisTypeArray();
+        ThisTypeArray *tarray = cx->create<ThisTypeArray>();
         if (!tarray)
             return NULL;
 
         tarray->buffer = buffer;
         tarray->bufferJS = bufferJS;
         tarray->byteOffset = byteOffset + begin * sizeof(NativeType);
         tarray->byteLength = (end - begin) * sizeof(NativeType);
         tarray->length = end - begin;