gecko-dev/dom/bindings/Date.h
Boris Zbarsky 7e5a37a024 Bug 1521907 part 3. Start using CheckedUnwrapStatic/Dynamic in bindings. r=peterv
The basic idea for the changes around UnwrapObjectInternal and its callers
(UnwrapObject, UNWRAP_OBJECT, etc) is to add a parameter to the guts of the
object-unwrapping code in bindings which can be either a JSContext* or nullptr
(statically typed).  Then we test which type it is and do either a
CheckedUnwrapDynamic or CheckedUnwrapStatic.  Since the type is known at
compile time, there is no actual runtime check; the compiler just emits a call
to the right thing directly (verified by examining the assembly output on
Linux).

The rest of the changes are mostly propagating through that template parameter,
adding static asserts to make sure people don't accidentally pass nullptr while
trying to unwrap to a type that might be a WindowProxy or Location, etc.

There are also some changes to places that were calling CheckedUnwrap directly
to use either the static or dynamic version, as needed.

Differential Revision: https://phabricator.services.mozilla.com/D17883

--HG--
extra : moz-landing-system : lando
2019-02-02 03:23:49 +00:00

50 lines
1.4 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Representation for dates. */
#ifndef mozilla_dom_Date_h
#define mozilla_dom_Date_h
#include "js/Date.h"
#include "js/TypeDecls.h"
namespace mozilla {
namespace dom {
class Date {
public:
Date() {}
explicit Date(JS::ClippedTime aMilliseconds)
: mMsecSinceEpoch(aMilliseconds) {}
bool IsUndefined() const { return !mMsecSinceEpoch.isValid(); }
JS::ClippedTime TimeStamp() const { return mMsecSinceEpoch; }
// Returns an integer in the range [-8.64e15, +8.64e15] (-0 excluded), *or*
// returns NaN. DO NOT ASSUME THIS IS FINITE!
double ToDouble() const { return mMsecSinceEpoch.toDouble(); }
void SetTimeStamp(JS::ClippedTime aMilliseconds) {
mMsecSinceEpoch = aMilliseconds;
}
// Can return false if unboxing fails. This will NOT throw;
// callers should do it as needed.
bool SetTimeStamp(JSContext* aCx, JSObject* aObject);
bool ToDateObject(JSContext* aCx, JS::MutableHandle<JS::Value> aRval) const;
private:
JS::ClippedTime mMsecSinceEpoch;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_Date_h