Bug 557728 - Split constructors into called-from-script and called-from-api. r=vlad sr=jst
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 08 Apr 2010 18:20:06 -0700
changeset 40636 e7a05d0e9fc5a36f6594187fdbf4d84aeb073b3f
parent 40635 eea9f123edfedafa5034662c5a9cbcda787272a2
child 40637 25879ce33e7ac39bec6c3abea7670d93b1063a97
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad, jst
bugs557728
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 557728 - Split constructors into called-from-script and called-from-api. r=vlad sr=jst
js/src/jstypedarray.cpp
js/src/jstypedarray.h
--- a/js/src/jstypedarray.cpp
+++ b/js/src/jstypedarray.cpp
@@ -106,16 +106,30 @@ ArrayBuffer::class_constructor(JSContext
 {
     if (!JS_IsConstructing(cx)) {
         obj = js_NewObject(cx, &ArrayBuffer::jsclass, NULL, NULL);
         if (!obj)
             return false;
         *rval = OBJECT_TO_JSVAL(obj);
     }
 
+    return create(cx, obj, argc, argv, rval);
+}
+
+bool
+ArrayBuffer::create(JSContext *cx, JSObject *obj,
+                    uintN argc, jsval *argv, jsval *rval)
+{
+    if (!obj) {
+        obj = js_NewObject(cx, &ArrayBuffer::jsclass, NULL, NULL);
+        if (!obj)
+            return false;
+        *rval = OBJECT_TO_JSVAL(obj);
+    }
+
     if (argc == 0) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                              JSMSG_TYPED_ARRAY_BAD_ARGS);
         return false;
     }
 
     int32 nbytes = js_ValueToECMAInt32(cx, &argv[0]);
     if (JSVAL_IS_NULL(argv[0]))
@@ -683,16 +697,29 @@ class TypedArrayTemplate
 
         if (!JS_IsConstructing(cx)) {
             obj = js_NewObject(cx, slowClass(), NULL, NULL);
             if (!obj)
                 return false;
             *rval = OBJECT_TO_JSVAL(obj);
         }
 
+        return create(cx, obj, argc, argv, rval);
+    }
+
+    static bool
+    create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+    {
+        if (!obj) {
+            obj = js_NewObject(cx, slowClass(), NULL, NULL);
+            if (!obj)
+                return false;
+            *rval = OBJECT_TO_JSVAL(obj);
+        }
+
         ThisTypeArray *tarray = 0;
 
         // must have at least one arg
         if (argc == 0) {
             JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                  JSMSG_TYPED_ARRAY_BAD_ARGS);
             return false;
         }
@@ -1396,54 +1423,52 @@ js_IsTypedArray(JSObject *obj)
 JS_FRIEND_API(JSObject *)
 js_CreateArrayBuffer(JSContext *cx, jsuint nbytes)
 {
     AutoValueRooter tvr(cx);
     if (!js_NewNumberInRootedValue(cx, jsdouble(nbytes), tvr.addr()))
         return NULL;
 
     AutoValueRooter rval(cx);
-    if (!ArrayBuffer::class_constructor(cx, cx->globalObject,
-                                        1, tvr.addr(), 
-                                        rval.addr()))
+    if (!ArrayBuffer::create(cx, NULL, 1, tvr.addr(), rval.addr()))
         return NULL;
 
     return JSVAL_TO_OBJECT(rval.value());
 }
 
 static inline JSBool
 TypedArrayConstruct(JSContext *cx, jsint atype, uintN argc, jsval *argv, jsval *rv)
 {
     switch (atype) {
       case TypedArray::TYPE_INT8:
-        return !!Int8Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
+        return !!Int8Array::create(cx, NULL, argc, argv, rv);
 
       case TypedArray::TYPE_UINT8:
-        return !!Uint8Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
+        return !!Uint8Array::create(cx, NULL, argc, argv, rv);
 
       case TypedArray::TYPE_INT16:
-        return !!Int16Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
+        return !!Int16Array::create(cx, NULL, argc, argv, rv);
 
       case TypedArray::TYPE_UINT16:
-        return !!Uint16Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
+        return !!Uint16Array::create(cx, NULL, argc, argv, rv);
 
       case TypedArray::TYPE_INT32:
-        return !!Int32Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
+        return !!Int32Array::create(cx, NULL, argc, argv, rv);
 
       case TypedArray::TYPE_UINT32:
-        return !!Uint32Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
+        return !!Uint32Array::create(cx, NULL, argc, argv, rv);
 
       case TypedArray::TYPE_FLOAT32:
-        return !!Float32Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
+        return !!Float32Array::create(cx, NULL, argc, argv, rv);
 
       case TypedArray::TYPE_FLOAT64:
-        return !!Float64Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
+        return !!Float64Array::create(cx, NULL, argc, argv, rv);
 
       case TypedArray::TYPE_UINT8_CLAMPED:
-        return !!Uint8ClampedArray::class_constructor(cx, cx->globalObject, argc, argv, rv);
+        return !!Uint8ClampedArray::create(cx, NULL, argc, argv, rv);
 
       default:
         JS_NOT_REACHED("shouldn't have gotten here");
         return false;
     }
 }
 
 JS_FRIEND_API(JSObject *)
--- a/js/src/jstypedarray.h
+++ b/js/src/jstypedarray.h
@@ -59,16 +59,19 @@ struct JS_FRIEND_API(ArrayBuffer) {
     static JSPropertySpec jsprops[];
 
     static JSBool prop_getByteLength(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
     static void class_finalize(JSContext *cx, JSObject *obj);
 
     static JSBool class_constructor(JSContext *cx, JSObject *obj,
                                     uintN argc, jsval *argv, jsval *rval);
 
+    static bool create(JSContext *cx, JSObject *obj, uintN argc,
+                       jsval *argv, jsval *rval);
+
     static ArrayBuffer *fromJSObject(JSObject *obj);
 
     ArrayBuffer()
         : data(0), byteLength()
     {
     }
 
     ~ArrayBuffer();