mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-29 05:05:29 +00:00
Bug 1055472 - Part 7: Make the Date constructor properly subclassable. (r=Waldo)
This commit is contained in:
parent
d9b2cbcf06
commit
c380e5d18a
@ -3016,7 +3016,14 @@ static const JSFunctionSpec date_methods[] = {
|
||||
static bool
|
||||
NewDateObject(JSContext* cx, const CallArgs& args, ClippedTime t)
|
||||
{
|
||||
JSObject* obj = NewDateObjectMsec(cx, t);
|
||||
MOZ_ASSERT(args.isConstructing());
|
||||
|
||||
RootedObject proto(cx);
|
||||
RootedObject newTarget(cx, &args.newTarget().toObject());
|
||||
if (!GetPrototypeFromConstructor(cx, newTarget, &proto))
|
||||
return false;
|
||||
|
||||
JSObject* obj = NewDateObjectMsec(cx, t, proto);
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
@ -3260,9 +3267,9 @@ const Class DateObject::protoClass_ = {
|
||||
};
|
||||
|
||||
JSObject*
|
||||
js::NewDateObjectMsec(JSContext* cx, ClippedTime t)
|
||||
js::NewDateObjectMsec(JSContext* cx, ClippedTime t, HandleObject proto /* = nullptr */)
|
||||
{
|
||||
JSObject* obj = NewBuiltinClassInstance(cx, &DateObject::class_);
|
||||
JSObject* obj = NewObjectWithClassProto(cx, &DateObject::class_, proto);
|
||||
if (!obj)
|
||||
return nullptr;
|
||||
obj->as<DateObject>().setUTCTime(t);
|
||||
|
@ -30,7 +30,7 @@ namespace js {
|
||||
* since the epoch.
|
||||
*/
|
||||
extern JSObject*
|
||||
NewDateObjectMsec(JSContext* cx, JS::ClippedTime t);
|
||||
NewDateObjectMsec(JSContext* cx, JS::ClippedTime t, JS::HandleObject proto = nullptr);
|
||||
|
||||
/*
|
||||
* Construct a new Date Object from an exploded local time value.
|
||||
|
@ -1,14 +1,14 @@
|
||||
var test = `
|
||||
|
||||
function testBuiltin(builtin) {
|
||||
function testBuiltin(builtin, ...args) {
|
||||
class inst extends builtin {
|
||||
constructor() {
|
||||
super();
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.called = true;
|
||||
}
|
||||
}
|
||||
|
||||
let instance = new inst();
|
||||
let instance = new inst(...args);
|
||||
assertEq(instance instanceof inst, true);
|
||||
assertEq(instance instanceof builtin, true);
|
||||
assertEq(instance.called, true);
|
||||
@ -26,6 +26,9 @@ testBuiltin(SyntaxError);
|
||||
testBuiltin(TypeError);
|
||||
testBuiltin(URIError);
|
||||
testBuiltin(Number);
|
||||
testBuiltin(Date);
|
||||
testBuiltin(Date, 5);
|
||||
testBuiltin(Date, 5, 10);
|
||||
|
||||
`;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user