dom/bindings/Date.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "mozilla/dom/Date.h"
     9 #include "jsapi.h" // for JS_ObjectIsDate, JS_NewDateObjectMsec
    10 #include "jsfriendapi.h" // for js_DateGetMsecSinceEpoch
    11 #include "js/RootingAPI.h" // for Rooted, MutableHandle
    12 #include "js/Value.h" // for Value
    13 #include "jswrapper.h" // for CheckedUnwrap
    14 #include "mozilla/FloatingPoint.h" // for IsNaN, UnspecifiedNaN
    16 namespace mozilla {
    17 namespace dom {
    19 Date::Date()
    20   : mMsecSinceEpoch(UnspecifiedNaN<double>())
    21 {
    22 }
    24 bool
    25 Date::IsUndefined() const
    26 {
    27   return IsNaN(mMsecSinceEpoch);
    28 }
    30 bool
    31 Date::SetTimeStamp(JSContext* aCx, JSObject* aObject)
    32 {
    33   JS::Rooted<JSObject*> obj(aCx, aObject);
    34   MOZ_ASSERT(JS_ObjectIsDate(aCx, obj));
    36   obj = js::CheckedUnwrap(obj);
    37   // This really sucks: even if JS_ObjectIsDate, CheckedUnwrap can _still_ fail.
    38   if (!obj) {
    39     return false;
    40   }
    42   mMsecSinceEpoch = js_DateGetMsecSinceEpoch(obj);
    43   return true;
    44 }
    46 bool
    47 Date::ToDateObject(JSContext* aCx, JS::MutableHandle<JS::Value> aRval) const
    48 {
    49   JSObject* obj = JS_NewDateObjectMsec(aCx, mMsecSinceEpoch);
    50   if (!obj) {
    51     return false;
    52   }
    54   aRval.setObject(*obj);
    55   return true;
    56 }
    58 } // namespace dom
    59 } // namespace mozilla

mercurial