mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1055472 - Part 6: Make the Number constructor properly subclassable. (r=Waldo)
This commit is contained in:
parent
13f285c204
commit
e9db21e231
@ -488,7 +488,11 @@ Number(JSContext* cx, unsigned argc, Value* vp)
|
||||
if (!isConstructing)
|
||||
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)
|
||||
return false;
|
||||
args.rval().setObject(*obj);
|
||||
|
@ -25,6 +25,7 @@ testBuiltin(ReferenceError);
|
||||
testBuiltin(SyntaxError);
|
||||
testBuiltin(TypeError);
|
||||
testBuiltin(URIError);
|
||||
testBuiltin(Number);
|
||||
|
||||
`;
|
||||
|
||||
|
@ -14,14 +14,13 @@
|
||||
namespace js {
|
||||
|
||||
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)
|
||||
return nullptr;
|
||||
NumberObject& numobj = obj->as<NumberObject>();
|
||||
numobj.setPrimitiveValue(d);
|
||||
return &numobj;
|
||||
obj->setPrimitiveValue(d);
|
||||
return obj;
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
@ -22,10 +22,11 @@ class NumberObject : public NativeObject
|
||||
static const Class class_;
|
||||
|
||||
/*
|
||||
* Creates a new Number object boxing the given number. The object's
|
||||
* [[Prototype]] is determined from context.
|
||||
* Creates a new Number object boxing the given number.
|
||||
* 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 {
|
||||
return getFixedSlot(PRIMITIVE_VALUE_SLOT).toNumber();
|
||||
|
Loading…
Reference in New Issue
Block a user