NS_IMETHODIMP calDateTime::SetJsDate(JSContext* aCx, JS::HandleValue aDate) { if (!aDate.isObject()) { mIsValid = false; return NS_OK; } JS::Rooted<JSObject*> dobj(aCx, &aDate.toObject()); dobj = js::CheckedUnwrap(dobj); if (!dobj) { mIsValid = false; return NS_OK; } JSAutoCompartment ac(aCx, dobj); if (!JS_ObjectIsDate(aCx, dobj) || !js_DateIsValid(dobj)) { mIsValid = false; return NS_OK; } PRTime utcTime = PRTime(js_DateGetMsecSinceEpoch(dobj)) * 1000; mIsValid = NS_SUCCEEDED(SetNativeTime(utcTime)); return NS_OK; }
NS_IMETHODIMP calDateTime::SetJsDate(JSContext* aCx, const JS::Value& aDate) { if (!aDate.isObject()) { mIsValid = false; return NS_OK; } JSObject& dobj = aDate.toObject(); if (!js_DateIsValid(aCx, &dobj)) { mIsValid = false; return NS_OK; } PRTime utcTime = PRTime(js_DateGetMsecSinceEpoch(aCx, &dobj)) * 1000; mIsValid = NS_SUCCEEDED(SetNativeTime(utcTime)); return NS_OK; }
NS_IMETHODIMP calDateTime::SetJsDate(JSContext* aCx, const JS::Value& aDate) { if (!aDate.isObject()) { mIsValid = false; return NS_OK; } JSObject* dobj = js::CheckedUnwrap(JSVAL_TO_OBJECT(aDate)); JSAutoCompartment ac(aCx, dobj); if (!JS_ObjectIsDate(aCx, dobj) || !js_DateIsValid(dobj)) { mIsValid = false; return NS_OK; } PRTime utcTime = PRTime(js_DateGetMsecSinceEpoch(dobj)) * 1000; mIsValid = NS_SUCCEEDED(SetNativeTime(utcTime)); return NS_OK; }
/* bool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in jsid id, in JSValPtr vp); */ NS_IMETHODIMP calDateTime::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, jsid id, jsval * vp, bool *_retval) { NS_ENSURE_ARG_POINTER(_retval); if (JSID_IS_STRING(id)) { size_t length; JSString *idString = JSID_TO_STRING(id); const jschar *str = JS_GetStringCharsAndLength(cx, idString, &length); nsDependentString const val(reinterpret_cast<PRUnichar const*>(str), length); if (val.EqualsLiteral("jsDate") && vp) { JSObject *dobj; if (!JSVAL_IS_OBJECT(*vp) || !js_DateIsValid(cx, (dobj = JSVAL_TO_OBJECT(*vp)))) { mIsValid = PR_FALSE; } else { jsdouble utcMsec = js_DateGetMsecSinceEpoch(cx, dobj); PRTime utcTime, thousands; LL_F2L(utcTime, utcMsec); LL_I2L(thousands, 1000); LL_MUL(utcTime, utcTime, thousands); nsresult rv = SetNativeTime(utcTime); if (NS_SUCCEEDED(rv)) { mIsValid = PR_TRUE; } else { mIsValid = PR_FALSE; } } *_retval = PR_TRUE; return NS_SUCCESS_I_DID_SOMETHING; } } *_retval = PR_TRUE; return NS_OK; }