зеркало из https://github.com/mozilla/gecko-dev.git
Bug 857138 - Make Date operate with the boxedValue_unbox proxy trap. r=luke
This commit is contained in:
Родитель
8e4a68387a
Коммит
8d455794c0
|
@ -3062,16 +3062,37 @@ js_NewDateObject(JSContext *cx, int year, int mon, int mday,
|
|||
}
|
||||
|
||||
JS_FRIEND_API(bool)
|
||||
js::DateIsValid(JSContext *cx, JSObject *obj)
|
||||
js::DateIsValid(JSContext *cx, JSObject *objArg)
|
||||
{
|
||||
return obj->is<DateObject>() && !IsNaN(obj->as<DateObject>().UTCTime().toNumber());
|
||||
RootedObject obj(cx, objArg);
|
||||
if (!ObjectClassIs(obj, ESClass_Date, cx))
|
||||
return false;
|
||||
|
||||
RootedValue unboxed(cx);
|
||||
if (!Unbox(cx, obj, &unboxed)) {
|
||||
// This can't actually happen, so we don't force consumers to deal with
|
||||
// a clunky out-param API. Do something sane-ish if it does happen.
|
||||
cx->clearPendingException();
|
||||
return false;
|
||||
}
|
||||
|
||||
return !IsNaN(unboxed.toNumber());
|
||||
}
|
||||
|
||||
JS_FRIEND_API(double)
|
||||
js::DateGetMsecSinceEpoch(JSContext *cx, JSObject *obj)
|
||||
js::DateGetMsecSinceEpoch(JSContext *cx, JSObject *objArg)
|
||||
{
|
||||
obj = CheckedUnwrap(obj);
|
||||
if (!obj || !obj->is<DateObject>())
|
||||
RootedObject obj(cx, objArg);
|
||||
if (!ObjectClassIs(obj, ESClass_Date, cx))
|
||||
return 0;
|
||||
return obj->as<DateObject>().UTCTime().toNumber();
|
||||
|
||||
RootedValue unboxed(cx);
|
||||
if (!Unbox(cx, obj, &unboxed)) {
|
||||
// This can't actually happen, so we don't force consumers to deal with
|
||||
// a clunky out-param API. Do something sane-ish if it does happen.
|
||||
cx->clearPendingException();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return unboxed.toNumber();
|
||||
}
|
||||
|
|
|
@ -801,6 +801,8 @@ Unbox(JSContext *cx, HandleObject obj, MutableHandleValue vp)
|
|||
vp.setNumber(obj->as<NumberObject>().unbox());
|
||||
else if (obj->is<StringObject>())
|
||||
vp.setString(obj->as<StringObject>().unbox());
|
||||
else if (obj->is<DateObject>())
|
||||
vp.set(obj->as<DateObject>().UTCTime());
|
||||
else
|
||||
vp.setUndefined();
|
||||
|
||||
|
|
|
@ -1060,8 +1060,10 @@ JSStructuredCloneWriter::startWrite(HandleValue v)
|
|||
return out.writePair(SCTAG_REGEXP_OBJECT, re->getFlags()) &&
|
||||
writeString(SCTAG_STRING, re->getSource());
|
||||
} else if (ObjectClassIs(obj, ESClass_Date, context())) {
|
||||
double d = DateGetMsecSinceEpoch(context(), obj);
|
||||
return out.writePair(SCTAG_DATE_OBJECT, 0) && out.writeDouble(d);
|
||||
RootedValue unboxed(context());
|
||||
if (!Unbox(context(), obj, &unboxed))
|
||||
return false;
|
||||
return out.writePair(SCTAG_DATE_OBJECT, 0) && out.writeDouble(unboxed.toNumber());
|
||||
} else if (JS_IsTypedArrayObject(obj)) {
|
||||
return writeTypedArray(obj);
|
||||
} else if (JS_IsArrayBufferObject(obj) && JS_ArrayBufferHasData(obj)) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче