зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1215744 - Unnamed class expressions shouldn't get a name property. (r=arai)
This commit is contained in:
Родитель
8ed011b817
Коммит
b03dd5c99e
|
@ -487,6 +487,18 @@ fun_resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolvedp)
|
|||
if (fun->hasResolvedName())
|
||||
return true;
|
||||
|
||||
if (fun->isClassConstructor()) {
|
||||
// It's impossible to have an empty named class expression. We
|
||||
// use empty as a sentinel when creating default class
|
||||
// constructors.
|
||||
MOZ_ASSERT(fun->atom() != cx->names().empty);
|
||||
|
||||
// Unnamed class expressions should not get a .name property
|
||||
// at all.
|
||||
if (fun->atom() == nullptr)
|
||||
return true;
|
||||
}
|
||||
|
||||
v.setString(fun->atom() == nullptr ? cx->runtime()->emptyString : fun->atom());
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ class JSFunction : public js::NativeObject
|
|||
/* Derived Flags values for convenience: */
|
||||
NATIVE_FUN = 0,
|
||||
NATIVE_CTOR = NATIVE_FUN | CONSTRUCTOR,
|
||||
NATIVE_CLASS_CTOR = NATIVE_FUN | CONSTRUCTOR | CLASSCONSTRUCTOR_KIND,
|
||||
ASMJS_CTOR = ASMJS_KIND | NATIVE_CTOR,
|
||||
ASMJS_LAMBDA_CTOR = ASMJS_KIND | NATIVE_CTOR | LAMBDA,
|
||||
INTERPRETED_METHOD = INTERPRETED | METHOD_KIND,
|
||||
|
|
|
@ -173,10 +173,15 @@ testName(ExtendedExpr3, "base", false, false, false);
|
|||
|
||||
// ---- anonymous ----
|
||||
|
||||
// Anonymous class expressions don't get name properties unless specified in a
|
||||
// static manner.
|
||||
let Anon = class {
|
||||
constructor() {}
|
||||
};
|
||||
testName(Anon, "", true, false, false);
|
||||
testName(Anon, "", false, false, false);
|
||||
|
||||
let AnonDefault = class { };
|
||||
testName(AnonDefault, "", false, false, false);
|
||||
|
||||
let AnonWithGetter = class {
|
||||
constructor() {}
|
||||
|
@ -201,10 +206,11 @@ testName(AnonWithGetterSetter, "base", false, true, true);
|
|||
let ExtendedAnon1 = class extends Anon {
|
||||
constructor() {}
|
||||
};
|
||||
testName(ExtendedAnon1, "", true, false, false);
|
||||
delete ExtendedAnon1.name;
|
||||
testName(ExtendedAnon1, "", false, false, false);
|
||||
|
||||
let ExtendedAnonDefault = class extends Anon { };
|
||||
testName(ExtendedAnonDefault, "", false, false, false);
|
||||
|
||||
let ExtendedAnon2 = class extends AnonWithGetterSetter {
|
||||
constructor() {}
|
||||
static get name() { return "extend"; }
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
var test = `
|
||||
|
||||
assertEq(class { }.name, "");
|
||||
|
||||
`;
|
||||
|
||||
if (classesEnabled())
|
||||
eval(test);
|
||||
|
||||
if (typeof reportCompare === 'function')
|
||||
reportCompare(0,0,"OK");
|
|
@ -325,9 +325,9 @@ MakeDefaultConstructor(JSContext* cx, JSOp op, JSAtom* atom, HandleObject proto)
|
|||
bool derived = op == JSOP_DERIVEDCONSTRUCTOR;
|
||||
MOZ_ASSERT(derived == !!proto);
|
||||
|
||||
RootedAtom name(cx, atom);
|
||||
RootedAtom name(cx, atom == cx->names().empty ? nullptr : atom);
|
||||
JSNative native = derived ? DefaultDerivedClassConstructor : DefaultClassConstructor;
|
||||
return NewFunctionWithProto(cx, native, 0, JSFunction::NATIVE_CTOR, nullptr, name, proto);
|
||||
return NewFunctionWithProto(cx, native, 0, JSFunction::NATIVE_CLASS_CTOR, nullptr, name, proto);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
Загрузка…
Ссылка в новой задаче