mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1234702 - Part 4: Self-host default base class constructor. (r=till)
This commit is contained in:
parent
8d268b5780
commit
b9834bc732
@ -9,3 +9,9 @@ var DefaultDerivedClassConstructor =
|
||||
}
|
||||
};
|
||||
MakeDefaultConstructor(DefaultDerivedClassConstructor);
|
||||
|
||||
var DefaultBaseClassConstructor =
|
||||
class {
|
||||
constructor() { }
|
||||
};
|
||||
MakeDefaultConstructor(DefaultBaseClassConstructor);
|
||||
|
@ -1082,7 +1082,8 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool lambdaParen)
|
||||
} else {
|
||||
MOZ_ASSERT(!fun->isExprBody());
|
||||
|
||||
if (fun->infallibleIsDefaultClassConstructor(cx) && fun->isDerivedClassConstructor()) {
|
||||
bool derived = fun->infallibleIsDefaultClassConstructor(cx);
|
||||
if (derived && fun->isDerivedClassConstructor()) {
|
||||
if (!out.append("(...args) {\n ") ||
|
||||
!out.append("super(...args);\n}"))
|
||||
{
|
||||
@ -1092,7 +1093,7 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool lambdaParen)
|
||||
if (!out.append("() {\n "))
|
||||
return nullptr;
|
||||
|
||||
if (!fun->isNative() || fun->native() != js::DefaultClassConstructor) {
|
||||
if (!derived) {
|
||||
if (!out.append("[native code]"))
|
||||
return nullptr;
|
||||
}
|
||||
@ -1277,7 +1278,8 @@ JSFunction::infallibleIsDefaultClassConstructor(JSContext* cx) const
|
||||
bool isDefault = false;
|
||||
if (isInterpretedLazy()) {
|
||||
JSAtom* name = &getExtendedSlot(LAZY_FUNCTION_NAME_SLOT).toString()->asAtom();
|
||||
isDefault = name == cx->names().DefaultDerivedClassConstructor;
|
||||
isDefault = name == cx->names().DefaultDerivedClassConstructor ||
|
||||
name == cx->names().DefaultBaseClassConstructor;
|
||||
} else {
|
||||
isDefault = nonLazyScript()->isDefaultClassConstructor();
|
||||
}
|
||||
|
@ -66,6 +66,7 @@
|
||||
macro(decodeURI, decodeURI, "decodeURI") \
|
||||
macro(decodeURIComponent, decodeURIComponent, "decodeURIComponent") \
|
||||
macro(default_, default_, "default") \
|
||||
macro(DefaultBaseClassConstructor, DefaultBaseClassConstructor, "DefaultBaseClassConstructor") \
|
||||
macro(DefaultDerivedClassConstructor, DefaultDerivedClassConstructor, "DefaultDerivedClassConstructor") \
|
||||
macro(defineProperty, defineProperty, "defineProperty") \
|
||||
macro(defineGetter, defineGetter, "__defineGetter__") \
|
||||
|
@ -291,21 +291,20 @@ SetPropertyOperation(JSContext* cx, JSOp op, HandleValue lval, HandleId id, Hand
|
||||
}
|
||||
|
||||
static JSFunction*
|
||||
MakeDefaultConstructor(JSContext* cx, JSOp op, JSAtom* atom)
|
||||
MakeDefaultConstructor(JSContext* cx, JSOp op, JSAtom* atom, HandleObject proto)
|
||||
{
|
||||
RootedAtom name(cx, atom == cx->names().empty ? nullptr : atom);
|
||||
JSNative native = DefaultClassConstructor;
|
||||
return NewFunctionWithProto(cx, native, 0, JSFunction::NATIVE_CLASS_CTOR, nullptr, name, nullptr);
|
||||
}
|
||||
bool derived = op == JSOP_DERIVEDCONSTRUCTOR;
|
||||
MOZ_ASSERT(derived == !!proto);
|
||||
|
||||
static JSFunction*
|
||||
MakeDerivedDefaultConstructor(JSContext* cx, JSAtom* atom, HandleObject proto)
|
||||
{
|
||||
RootedPropertyName selfHostedName(cx, cx->names().DefaultDerivedClassConstructor);
|
||||
PropertyName* lookup = derived ? cx->names().DefaultDerivedClassConstructor
|
||||
: cx->names().DefaultBaseClassConstructor;
|
||||
|
||||
RootedPropertyName selfHostedName(cx, lookup);
|
||||
RootedAtom name(cx, atom == cx->names().empty ? nullptr : atom);
|
||||
|
||||
RootedFunction ctor(cx);
|
||||
if (!cx->runtime()->createLazySelfHostedFunctionClone(cx, selfHostedName, name, /* nargs = */ 1,
|
||||
if (!cx->runtime()->createLazySelfHostedFunctionClone(cx, selfHostedName, name,
|
||||
/* nargs = */ !!derived,
|
||||
proto, TenuredObject, &ctor))
|
||||
{
|
||||
return nullptr;
|
||||
@ -3902,7 +3901,8 @@ CASE(JSOP_DERIVEDCONSTRUCTOR)
|
||||
MOZ_ASSERT(REGS.sp[-1].isObject());
|
||||
ReservedRooted<JSObject*> proto(&rootObject0, ®S.sp[-1].toObject());
|
||||
|
||||
JSFunction* constructor = MakeDerivedDefaultConstructor(cx, script->getAtom(REGS.pc), proto);
|
||||
JSFunction* constructor = MakeDefaultConstructor(cx, JSOp(*REGS.pc), script->getAtom(REGS.pc),
|
||||
proto);
|
||||
if (!constructor)
|
||||
goto error;
|
||||
|
||||
@ -3912,7 +3912,8 @@ END_CASE(JSOP_DERIVEDCONSTRUCTOR)
|
||||
|
||||
CASE(JSOP_CLASSCONSTRUCTOR)
|
||||
{
|
||||
JSFunction* constructor = MakeDefaultConstructor(cx, JSOp(*REGS.pc), script->getAtom(REGS.pc));
|
||||
JSFunction* constructor = MakeDefaultConstructor(cx, JSOp(*REGS.pc), script->getAtom(REGS.pc),
|
||||
nullptr);
|
||||
if (!constructor)
|
||||
goto error;
|
||||
PUSH_OBJECT(*constructor);
|
||||
@ -4813,24 +4814,6 @@ js::ReportRuntimeLexicalError(JSContext* cx, unsigned errorNumber,
|
||||
ReportRuntimeLexicalError(cx, errorNumber, name);
|
||||
}
|
||||
|
||||
bool
|
||||
js::DefaultClassConstructor(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (!args.isConstructing()) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_CANT_CALL_CLASS_CONSTRUCTOR);
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject newTarget(cx, &args.newTarget().toObject());
|
||||
JSObject* obj = CreateThis(cx, &PlainObject::class_, newTarget);
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
args.rval().set(ObjectValue(*obj));
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
js::ReportRuntimeRedeclaration(JSContext* cx, HandlePropertyName name,
|
||||
frontend::Definition::Kind declKind)
|
||||
|
Loading…
Reference in New Issue
Block a user