Bug 911578 - Introduce self-hosting intrinsic isPackedArray. r=jandem
authorTill Schneidereit <till@tillschneidereit.net>
Fri, 29 Nov 2013 17:54:31 +0100
changeset 158140 d9f86fd4fa60ad3eb02031ccf7a10315c1a83f1f
parent 158139 27b8fa30236810268a4df3bd4db199270fc3c200
child 158141 7b039ed2dbacc6f71b4e585f44f633402b1ad32d
push id25737
push usercbook@mozilla.com
push dateMon, 02 Dec 2013 11:42:38 +0000
treeherdermozilla-central@5b9a4d273114 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs911578
milestone28.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 911578 - Introduce self-hosting intrinsic isPackedArray. r=jandem
js/src/jscntxt.h
js/src/vm/SelfHosting.cpp
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -1007,16 +1007,17 @@ bool intrinsic_ToObject(JSContext *cx, u
 bool intrinsic_IsCallable(JSContext *cx, unsigned argc, Value *vp);
 bool intrinsic_ThrowError(JSContext *cx, unsigned argc, Value *vp);
 bool intrinsic_NewDenseArray(JSContext *cx, unsigned argc, Value *vp);
 
 bool intrinsic_UnsafePutElements(JSContext *cx, unsigned argc, Value *vp);
 bool intrinsic_UnsafeSetReservedSlot(JSContext *cx, unsigned argc, Value *vp);
 bool intrinsic_UnsafeGetReservedSlot(JSContext *cx, unsigned argc, Value *vp);
 bool intrinsic_HaveSameClass(JSContext *cx, unsigned argc, Value *vp);
+bool intrinsic_IsPackedArray(JSContext *cx, unsigned argc, Value *vp);
 
 bool intrinsic_ShouldForceSequential(JSContext *cx, unsigned argc, Value *vp);
 bool intrinsic_NewParallelArray(JSContext *cx, unsigned argc, Value *vp);
 
 class AutoLockForExclusiveAccess
 {
 #ifdef JS_WORKER_THREADS
     JSRuntime *runtime;
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -458,16 +458,32 @@ js::intrinsic_HaveSameClass(JSContext *c
     JS_ASSERT(args.length() == 2);
     JS_ASSERT(args[0].isObject());
     JS_ASSERT(args[1].isObject());
 
     args.rval().setBoolean(args[0].toObject().getClass() == args[1].toObject().getClass());
     return true;
 }
 
+bool
+js::intrinsic_IsPackedArray(JSContext *cx, unsigned argc, Value *vp)
+{
+    CallArgs args = CallArgsFromVp(argc, vp);
+    JS_ASSERT(args.length() == 1);
+    JS_ASSERT(args[0].isObject());
+
+    JSObject *obj = &args[0].toObject();
+    bool isPacked = obj->is<ArrayObject>() &&
+                    !obj->type()->hasAllFlags(types::OBJECT_FLAG_NON_PACKED) &&
+                    obj->getDenseInitializedLength() == obj->as<ArrayObject>().length();
+
+    args.rval().setBoolean(isPacked);
+    return true;
+}
+
 static bool
 intrinsic_GetIteratorPrototype(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     JS_ASSERT(args.length() == 0);
 
     JSObject *obj = cx->global()->getOrCreateIteratorPrototype(cx);
     if (!obj)
@@ -607,16 +623,17 @@ static const JSFunctionSpec intrinsic_fu
     JS_FN("MakeWrappable",           intrinsic_MakeWrappable,           1,0),
     JS_FN("DecompileArg",            intrinsic_DecompileArg,            2,0),
     JS_FN("RuntimeDefaultLocale",    intrinsic_RuntimeDefaultLocale,    0,0),
 
     JS_FN("UnsafePutElements",       intrinsic_UnsafePutElements,       3,0),
     JS_FN("UnsafeSetReservedSlot",   intrinsic_UnsafeSetReservedSlot,   3,0),
     JS_FN("UnsafeGetReservedSlot",   intrinsic_UnsafeGetReservedSlot,   2,0),
     JS_FN("HaveSameClass",           intrinsic_HaveSameClass,           2,0),
+    JS_FN("IsPackedArray",           intrinsic_IsPackedArray,           1,0),
 
     JS_FN("GetIteratorPrototype",    intrinsic_GetIteratorPrototype,    0,0),
 
     JS_FN("NewArrayIterator",        intrinsic_NewArrayIterator,        0,0),
     JS_FN("IsArrayIterator",         intrinsic_IsArrayIterator,         1,0),
 
     JS_FN("NewStringIterator",       intrinsic_NewStringIterator,       0,0),
     JS_FN("IsStringIterator",        intrinsic_IsStringIterator,        1,0),