1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bindings/Date.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "mozilla/dom/Date.h" 1.11 + 1.12 +#include "jsapi.h" // for JS_ObjectIsDate, JS_NewDateObjectMsec 1.13 +#include "jsfriendapi.h" // for js_DateGetMsecSinceEpoch 1.14 +#include "js/RootingAPI.h" // for Rooted, MutableHandle 1.15 +#include "js/Value.h" // for Value 1.16 +#include "jswrapper.h" // for CheckedUnwrap 1.17 +#include "mozilla/FloatingPoint.h" // for IsNaN, UnspecifiedNaN 1.18 + 1.19 +namespace mozilla { 1.20 +namespace dom { 1.21 + 1.22 +Date::Date() 1.23 + : mMsecSinceEpoch(UnspecifiedNaN<double>()) 1.24 +{ 1.25 +} 1.26 + 1.27 +bool 1.28 +Date::IsUndefined() const 1.29 +{ 1.30 + return IsNaN(mMsecSinceEpoch); 1.31 +} 1.32 + 1.33 +bool 1.34 +Date::SetTimeStamp(JSContext* aCx, JSObject* aObject) 1.35 +{ 1.36 + JS::Rooted<JSObject*> obj(aCx, aObject); 1.37 + MOZ_ASSERT(JS_ObjectIsDate(aCx, obj)); 1.38 + 1.39 + obj = js::CheckedUnwrap(obj); 1.40 + // This really sucks: even if JS_ObjectIsDate, CheckedUnwrap can _still_ fail. 1.41 + if (!obj) { 1.42 + return false; 1.43 + } 1.44 + 1.45 + mMsecSinceEpoch = js_DateGetMsecSinceEpoch(obj); 1.46 + return true; 1.47 +} 1.48 + 1.49 +bool 1.50 +Date::ToDateObject(JSContext* aCx, JS::MutableHandle<JS::Value> aRval) const 1.51 +{ 1.52 + JSObject* obj = JS_NewDateObjectMsec(aCx, mMsecSinceEpoch); 1.53 + if (!obj) { 1.54 + return false; 1.55 + } 1.56 + 1.57 + aRval.setObject(*obj); 1.58 + return true; 1.59 +} 1.60 + 1.61 +} // namespace dom 1.62 +} // namespace mozilla