Bug 1483999 - Avoid duplicate GetBuiltinClass call. r=sfink
authorTom Schuster <evilpies@gmail.com>
Sat, 18 Aug 2018 17:22:19 +0200
changeset 487401 9f9bb31175a814856eeef5939196fa485ca03143
parent 487391 2d1d32212c1e4107bef4d24dbbe2f12adca11837
child 487402 93d0e291f45883765df384c070e56e4e0517db4b
child 487413 16e87606763681d91dc92d6013f3698c36450c9c
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1483999
milestone63.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 1483999 - Avoid duplicate GetBuiltinClass call. r=sfink
js/src/vm/StructuredClone.cpp
--- a/js/src/vm/StructuredClone.cpp
+++ b/js/src/vm/StructuredClone.cpp
@@ -514,17 +514,17 @@ struct JSStructuredCloneWriter {
     bool writeString(uint32_t tag, JSString* str);
     bool writeArrayBuffer(HandleObject obj);
     bool writeTypedArray(HandleObject obj);
     bool writeDataView(HandleObject obj);
     bool writeSharedArrayBuffer(HandleObject obj);
     bool writeSharedWasmMemory(HandleObject obj);
     bool startObject(HandleObject obj, bool* backref);
     bool startWrite(HandleValue v);
-    bool traverseObject(HandleObject obj);
+    bool traverseObject(HandleObject obj, ESClass cls);
     bool traverseMap(HandleObject obj);
     bool traverseSet(HandleObject obj);
     bool traverseSavedFrame(HandleObject obj);
 
 #ifdef ENABLE_BIGINT
     bool writeBigInt(uint32_t tag, BigInt* bi);
 #endif
 
@@ -1371,17 +1371,17 @@ JSStructuredCloneWriter::startObject(Han
                                   "object graph to serialize");
         return false;
     }
 
     return true;
 }
 
 bool
-JSStructuredCloneWriter::traverseObject(HandleObject obj)
+JSStructuredCloneWriter::traverseObject(HandleObject obj, ESClass cls)
 {
     // Get enumerable property ids and put them in reverse order so that they
     // will come off the stack in forward order.
     AutoIdVector properties(context());
     if (!GetPropertyKeys(context(), obj, JSITER_OWNONLY, &properties))
         return false;
 
     for (size_t i = properties.length(); i > 0; --i) {
@@ -1392,21 +1392,24 @@ JSStructuredCloneWriter::traverseObject(
     }
 
     // Push obj and count to the stack.
     if (!objs.append(ObjectValue(*obj)) || !counts.append(properties.length()))
         return false;
 
     checkStack();
 
+#if DEBUG
+    ESClass cls2;
+    if (!GetBuiltinClass(context(), obj, &cls2))
+        return false;
+    MOZ_ASSERT(cls2 == cls);
+#endif
+
     // Write the header for obj.
-    ESClass cls;
-    if (!GetBuiltinClass(context(), obj, &cls))
-        return false;
-
     if (cls == ESClass::Array) {
         uint32_t length = 0;
         if (!JS_GetArrayLength(context(), obj, &length))
             return false;
 
         return out.writePair(SCTAG_ARRAY_OBJECT, NativeEndian::swapToLittleEndian(length));
     }
 
@@ -1609,17 +1612,17 @@ JSStructuredCloneWriter::startWrite(Hand
 
         ESClass cls;
         if (!GetBuiltinClass(context(), obj, &cls))
             return false;
 
         switch (cls) {
           case ESClass::Object:
           case ESClass::Array:
-            return traverseObject(obj);
+            return traverseObject(obj, cls);
           case ESClass::Number: {
             RootedValue unboxed(context());
             if (!Unbox(context(), obj, &unboxed))
                 return false;
             return out.writePair(SCTAG_NUMBER_OBJECT, 0) && out.writeDouble(unboxed.toNumber());
           }
           case ESClass::String: {
             RootedValue unboxed(context());