Bug 1164777 - Part 2: Make super.prop parse inside inside eval inside arrow functions. (r=shu)

This commit is contained in:
Eric Faust 2015-05-22 13:09:44 -07:00
parent fcf7797b5f
commit 585898080e
5 changed files with 40 additions and 12 deletions

View File

@ -283,12 +283,8 @@ frontend::CompileScript(ExclusiveContext* cx, LifoAlloc* alloc, HandleObject sco
return nullptr;
bool savedCallerFun = evalCaller && evalCaller->functionOrCallerFunction();
bool allowSuperProperty = savedCallerFun &&
evalCaller->functionOrCallerFunction()->allowSuperProperty();
Directives directives(options.strictOption);
GlobalSharedContext globalsc(cx, directives, evalStaticScope, options.extraWarningsOption,
allowSuperProperty);
GlobalSharedContext globalsc(cx, directives, evalStaticScope, options.extraWarningsOption);
Rooted<JSScript*> script(cx, JSScript::Create(cx, evalStaticScope, savedCallerFun,
options, staticLevel, sourceObject, 0,

View File

@ -700,8 +700,7 @@ Parser<ParseHandler>::parse(JSObject* chain)
Directives directives(options().strictOption);
GlobalSharedContext globalsc(context, directives,
/* staticEvalScope = */ nullptr,
options().extraWarningsOption,
/* allowSuperProperty = */ false);
options().extraWarningsOption);
ParseContext<ParseHandler> globalpc(this, /* parent = */ nullptr, ParseHandler::null(),
&globalsc, /* newDirectives = */ nullptr,
/* staticLevel = */ 0, /* bodyid = */ 0,

View File

@ -237,20 +237,29 @@ class GlobalSharedContext : public SharedContext
{
private:
Handle<StaticEvalObject*> staticEvalScope_;
bool allowSuperProperty_;
public:
GlobalSharedContext(ExclusiveContext* cx,
Directives directives, Handle<StaticEvalObject*> staticEvalScope,
bool extraWarnings, bool allowSuperProperty)
bool extraWarnings)
: SharedContext(cx, directives, extraWarnings),
staticEvalScope_(staticEvalScope),
allowSuperProperty_(allowSuperProperty)
staticEvalScope_(staticEvalScope)
{}
ObjectBox* toObjectBox() { return nullptr; }
bool allowSuperProperty() const { return allowSuperProperty_; }
HandleObject evalStaticScope() const { return staticEvalScope_; }
bool allowSuperProperty() const {
StaticScopeIter<CanGC> it(context, staticEvalScope_);
for (; !it.done(); it++) {
if (it.type() == StaticScopeIter<CanGC>::Function &&
!it.fun().isArrow())
{
return it.fun().allowSuperProperty();
}
}
return false;
}
};
class FunctionBox : public ObjectBox, public SharedContext

View File

@ -0,0 +1,11 @@
class foo {
constructor() { }
method() {
return (() => eval('super.toString'));
}
}
assertEq(new foo().method()(), Object.prototype.toString);
if (typeof reportCompare === "function")
reportCompare(0,0,"OK");

View File

@ -0,0 +1,13 @@
// It's invalid to eval super.prop inside a nested non-method, even if it
// appears inside a method definition
assertThrowsInstanceOf(() =>
({
method() {
(function () {
eval('super.toString');
})();
}
}).method(), SyntaxError);
if (typeof reportCompare === 'function')
reportCompare(0,0,"OK");