mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1055472 - Part 6: Make the Number constructor properly subclassable. (r=Waldo)
This commit is contained in:
parent
6e5a905729
commit
e325bd50b8
@ -488,7 +488,11 @@ Number(JSContext* cx, unsigned argc, Value* vp)
|
|||||||
if (!isConstructing)
|
if (!isConstructing)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
JSObject* obj = NumberObject::create(cx, args.rval().toNumber());
|
RootedObject newTarget(cx, &args.newTarget().toObject());
|
||||||
|
RootedObject proto(cx);
|
||||||
|
if (!GetPrototypeFromConstructor(cx, newTarget, &proto))
|
||||||
|
return false;
|
||||||
|
JSObject* obj = NumberObject::create(cx, args.rval().toNumber(), proto);
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return false;
|
return false;
|
||||||
args.rval().setObject(*obj);
|
args.rval().setObject(*obj);
|
||||||
|
@ -25,6 +25,7 @@ testBuiltin(ReferenceError);
|
|||||||
testBuiltin(SyntaxError);
|
testBuiltin(SyntaxError);
|
||||||
testBuiltin(TypeError);
|
testBuiltin(TypeError);
|
||||||
testBuiltin(URIError);
|
testBuiltin(URIError);
|
||||||
|
testBuiltin(Number);
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -14,14 +14,13 @@
|
|||||||
namespace js {
|
namespace js {
|
||||||
|
|
||||||
inline NumberObject*
|
inline NumberObject*
|
||||||
NumberObject::create(JSContext* cx, double d)
|
NumberObject::create(JSContext* cx, double d, HandleObject proto /* = nullptr */)
|
||||||
{
|
{
|
||||||
JSObject* obj = NewBuiltinClassInstance(cx, &class_);
|
NumberObject* obj = NewObjectWithClassProto<NumberObject>(cx, proto);
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
NumberObject& numobj = obj->as<NumberObject>();
|
obj->setPrimitiveValue(d);
|
||||||
numobj.setPrimitiveValue(d);
|
return obj;
|
||||||
return &numobj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace js
|
} // namespace js
|
||||||
|
@ -22,10 +22,11 @@ class NumberObject : public NativeObject
|
|||||||
static const Class class_;
|
static const Class class_;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a new Number object boxing the given number. The object's
|
* Creates a new Number object boxing the given number.
|
||||||
* [[Prototype]] is determined from context.
|
* If proto is nullptr, then Number.prototype will be used instead.
|
||||||
*/
|
*/
|
||||||
static inline NumberObject* create(JSContext* cx, double d);
|
static inline NumberObject* create(JSContext* cx, double d,
|
||||||
|
HandleObject proto = nullptr);
|
||||||
|
|
||||||
double unbox() const {
|
double unbox() const {
|
||||||
return getFixedSlot(PRIMITIVE_VALUE_SLOT).toNumber();
|
return getFixedSlot(PRIMITIVE_VALUE_SLOT).toNumber();
|
||||||
|
Loading…
Reference in New Issue
Block a user