Bug 1055472 - Part 2: Make the Function constructor properly subclassable. (r=Waldo)

This commit is contained in:
Eric Faust 2015-11-13 18:22:21 -08:00
parent a048777c6e
commit ee8ffe863b
2 changed files with 37 additions and 0 deletions

View File

@ -1841,7 +1841,18 @@ FunctionConstructor(JSContext* cx, unsigned argc, Value* vp, GeneratorKind gener
proto = GlobalObject::getOrCreateStarGeneratorFunctionPrototype(cx, global);
if (!proto)
return false;
} else {
RootedObject toTest(cx);
// If we are invoked without |new|, then just use Function.prototype
if (args.isConstructing())
toTest = &args.newTarget().toObject();
else
toTest = &args.callee();
if (!GetPrototypeFromConstructor(cx, toTest, &proto))
return false;
}
RootedObject globalLexical(cx, &global->lexicalScope());
RootedFunction fun(cx, NewFunctionWithProto(cx, nullptr, 0,
JSFunction::INTERPRETED_LAMBDA, globalLexical,

View File

@ -0,0 +1,26 @@
var test = `
function testBuiltin(builtin) {
class inst extends builtin {
constructor() {
super();
this.called = true;
}
}
let instance = new inst();
assertEq(instance instanceof inst, true);
assertEq(instance instanceof builtin, true);
assertEq(instance.called, true);
}
testBuiltin(Function);
`;
if (classesEnabled())
eval(test);
if (typeof reportCompare === 'function')
reportCompare(0,0,"OK");