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