mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1055472 - Part 2: Make the Function constructor properly subclassable. (r=Waldo)
This commit is contained in:
parent
a048777c6e
commit
ee8ffe863b
@ -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,
|
||||
|
26
js/src/tests/ecma_6/Class/extendBuiltinConstructors.js
Normal file
26
js/src/tests/ecma_6/Class/extendBuiltinConstructors.js
Normal 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");
|
Loading…
Reference in New Issue
Block a user