Bug 1050340 - Handle dates generically. r=luke
authorBobby Holley <bobbyholley@gmail.com>
Mon, 18 Aug 2014 14:18:38 -0700
changeset 200229 a4014b7b418a4144eab90bdebadee40e3bac2563
parent 200228 a3761879135a5eadd5f80c627d310c00d080be7a
child 200230 f752615f4e19b83ce3d870a45163ab2d263eedba
push id8272
push useremorley@mozilla.com
push dateTue, 19 Aug 2014 14:17:45 +0000
treeherderfx-team@a955e211bfde [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1050340
milestone34.0a1
Bug 1050340 - Handle dates generically. r=luke
js/src/jsdate.cpp
js/src/vm/StructuredClone.cpp
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -27,16 +27,17 @@
 #include "jsapi.h"
 #include "jscntxt.h"
 #include "jsnum.h"
 #include "jsobj.h"
 #include "jsprf.h"
 #include "jsstr.h"
 #include "jstypes.h"
 #include "jsutil.h"
+#include "jswrapper.h"
 #include "prmjtime.h"
 
 #include "js/Date.h"
 #include "vm/DateTime.h"
 #include "vm/GlobalObject.h"
 #include "vm/Interpreter.h"
 #include "vm/NumericConversions.h"
 #include "vm/String.h"
@@ -3125,10 +3126,13 @@ js_DateGetSeconds(JSObject *obj)
     if (IsNaN(utctime))
         return 0;
     return (int) SecFromTime(utctime);
 }
 
 JS_FRIEND_API(double)
 js_DateGetMsecSinceEpoch(JSObject *obj)
 {
-    return obj->is<DateObject>() ? obj->as<DateObject>().UTCTime().toNumber() : 0;
+    obj = CheckedUnwrap(obj);
+    if (!obj || !obj->is<DateObject>())
+        return 0;
+    return obj->as<DateObject>().UTCTime().toNumber();
 }
--- a/js/src/vm/StructuredClone.cpp
+++ b/js/src/vm/StructuredClone.cpp
@@ -1012,17 +1012,17 @@ JSStructuredCloneWriter::startWrite(Hand
             return true;
 
         if (ObjectClassIs(obj, ESClass_RegExp, context())) {
             RegExpGuard re(context());
             if (!RegExpToShared(context(), obj, &re))
                 return false;
             return out.writePair(SCTAG_REGEXP_OBJECT, re->getFlags()) &&
                    writeString(SCTAG_STRING, re->getSource());
-        } else if (obj->is<DateObject>()) {
+        } else if (ObjectClassIs(obj, ESClass_Date, context())) {
             double d = js_DateGetMsecSinceEpoch(obj);
             return out.writePair(SCTAG_DATE_OBJECT, 0) && out.writeDouble(d);
         } else if (obj->is<TypedArrayObject>()) {
             return writeTypedArray(obj);
         } else if (obj->is<ArrayBufferObject>() && obj->as<ArrayBufferObject>().hasData()) {
             return writeArrayBuffer(obj);
         } else if (obj->is<JSObject>() || obj->is<ArrayObject>()) {
             return traverseObject(obj);