mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 20:25:44 +00:00
Bug 1165794 - Correctly handle getter/setters like methods everywhere. r=efaust
This commit is contained in:
parent
dc759e14b2
commit
16ff100dbd
@ -283,9 +283,8 @@ frontend::CompileScript(ExclusiveContext* cx, LifoAlloc* alloc, HandleObject sco
|
||||
return nullptr;
|
||||
|
||||
bool savedCallerFun = evalCaller && evalCaller->functionOrCallerFunction();
|
||||
bool allowSuperProperty = savedCallerFun && (evalCaller->functionOrCallerFunction()->isMethod() ||
|
||||
evalCaller->functionOrCallerFunction()->isGetter() ||
|
||||
evalCaller->functionOrCallerFunction()->isSetter());
|
||||
bool allowSuperProperty = savedCallerFun &&
|
||||
evalCaller->functionOrCallerFunction()->allowSuperProperty();
|
||||
|
||||
Directives directives(options.strictOption);
|
||||
GlobalSharedContext globalsc(cx, directives, options.extraWarningsOption, allowSuperProperty);
|
||||
|
@ -6766,7 +6766,7 @@ BytecodeEmitter::emitPropertyList(ParseNode* pn, MutableHandlePlainObject objp,
|
||||
if (propdef->pn_right->isKind(PNK_FUNCTION) &&
|
||||
propdef->pn_right->pn_funbox->needsHomeObject())
|
||||
{
|
||||
MOZ_ASSERT(propdef->pn_right->pn_funbox->function()->isMethod());
|
||||
MOZ_ASSERT(propdef->pn_right->pn_funbox->function()->allowSuperProperty());
|
||||
if (!emit2(JSOP_INITHOMEOBJECT, isIndex))
|
||||
return false;
|
||||
}
|
||||
|
@ -1235,9 +1235,11 @@ Parser<ParseHandler>::newFunction(HandleAtom atom, FunctionSyntaxKind kind, Hand
|
||||
break;
|
||||
case Getter:
|
||||
flags = JSFunction::INTERPRETED_GETTER;
|
||||
allocKind = gc::AllocKind::FUNCTION_EXTENDED;
|
||||
break;
|
||||
case Setter:
|
||||
flags = JSFunction::INTERPRETED_SETTER;
|
||||
allocKind = gc::AllocKind::FUNCTION_EXTENDED;
|
||||
break;
|
||||
default:
|
||||
flags = JSFunction::INTERPRETED_NORMAL;
|
||||
|
@ -339,7 +339,7 @@ class FunctionBox : public ObjectBox, public SharedContext
|
||||
}
|
||||
|
||||
bool allowSuperProperty() const {
|
||||
return function()->isMethod() || function()->isGetter() || function()->isSetter();
|
||||
return function()->allowSuperProperty();
|
||||
}
|
||||
};
|
||||
|
||||
|
4
js/src/jit-test/tests/parser/home-object-getter.js
Normal file
4
js/src/jit-test/tests/parser/home-object-getter.js
Normal file
@ -0,0 +1,4 @@
|
||||
var o = {get a() {
|
||||
return eval("5");
|
||||
}}
|
||||
assertEq(o.a, 5);
|
@ -1713,7 +1713,7 @@ CodeGenerator::visitLambda(LLambda* lir)
|
||||
emitLambdaInit(output, scopeChain, info);
|
||||
|
||||
if (info.flags & JSFunction::EXTENDED) {
|
||||
MOZ_ASSERT(info.fun->isMethod());
|
||||
MOZ_ASSERT(info.fun->allowSuperProperty());
|
||||
static_assert(FunctionExtended::NUM_EXTENDED_SLOTS == 2, "All slots must be initialized");
|
||||
masm.storeValue(UndefinedValue(), Address(output, FunctionExtended::offsetOfExtendedSlot(0)));
|
||||
masm.storeValue(UndefinedValue(), Address(output, FunctionExtended::offsetOfExtendedSlot(1)));
|
||||
|
@ -174,6 +174,10 @@ class JSFunction : public js::NativeObject
|
||||
return kind() == Method && isConstructor();
|
||||
}
|
||||
|
||||
bool allowSuperProperty() const {
|
||||
return isMethod() || isGetter() || isSetter();
|
||||
}
|
||||
|
||||
bool hasResolvedLength() const { return flags() & RESOLVED_LENGTH; }
|
||||
bool hasResolvedName() const { return flags() & RESOLVED_NAME; }
|
||||
|
||||
|
43
js/src/tests/ecma_6/Class/superPropBasicGetter.js
Normal file
43
js/src/tests/ecma_6/Class/superPropBasicGetter.js
Normal file
@ -0,0 +1,43 @@
|
||||
var test = `
|
||||
|
||||
class base {
|
||||
constructor() {}
|
||||
|
||||
getValue() {
|
||||
return this._prop;
|
||||
}
|
||||
|
||||
setValue(v) {
|
||||
this._prop = v;
|
||||
}
|
||||
}
|
||||
|
||||
class derived extends base {
|
||||
constructor() {}
|
||||
|
||||
get a() { return super.getValue(); }
|
||||
set a(v) { super.setValue(v); }
|
||||
|
||||
get b() { return eval('super.getValue()'); }
|
||||
set b(v) { eval('super.setValue(v);'); }
|
||||
|
||||
test() {
|
||||
this.a = 15;
|
||||
assertEq(this.a, 15);
|
||||
|
||||
assertEq(this.b, 15);
|
||||
this.b = 30;
|
||||
assertEq(this.b, 30);
|
||||
}
|
||||
}
|
||||
|
||||
var derivedInstance = new derived();
|
||||
derivedInstance.test();
|
||||
|
||||
`;
|
||||
|
||||
if (classesEnabled())
|
||||
eval(test);
|
||||
|
||||
if (typeof reportCompare === 'function')
|
||||
reportCompare(0,0,"OK");
|
@ -3964,7 +3964,7 @@ CASE(JSOP_INITHOMEOBJECT)
|
||||
/* Load the function to be initialized */
|
||||
RootedFunction& func = rootFunction0;
|
||||
func = ®S.sp[-1].toObject().as<JSFunction>();
|
||||
MOZ_ASSERT(func->isMethod());
|
||||
MOZ_ASSERT(func->allowSuperProperty());
|
||||
|
||||
/* Load the home object */
|
||||
RootedNativeObject& obj = rootNativeObject0;
|
||||
@ -3981,7 +3981,7 @@ CASE(JSOP_SUPERBASE)
|
||||
for (; !si.done(); ++si) {
|
||||
if (si.hasScopeObject() && si.type() == ScopeIter::Call) {
|
||||
JSFunction& callee = si.scope().as<CallObject>().callee();
|
||||
MOZ_ASSERT(callee.isMethod());
|
||||
MOZ_ASSERT(callee.allowSuperProperty());
|
||||
MOZ_ASSERT(callee.nonLazyScript()->needsHomeObject());
|
||||
const Value& homeObjVal = callee.getExtendedSlot(FunctionExtended::METHOD_HOMEOBJECT_SLOT);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user