Backed out changeset 0a5cf306560d (bug 1255925) on request from evilpie

This commit is contained in:
Carsten "Tomcat" Book 2016-04-14 16:20:02 +02:00
parent 56fa69434b
commit f893a5d6de
9 changed files with 35 additions and 147 deletions

View File

@ -1995,25 +1995,6 @@ Parser<SyntaxParseHandler>::leaveFunction(Node fn, ParseContext<SyntaxParseHandl
return addFreeVariablesFromLazyFunction(funbox->function(), outerpc);
}
template <typename ParseHandler>
JSAtom*
Parser<ParseHandler>::prefixAccessorName(PropertyType propType, HandleAtom propAtom)
{
RootedAtom prefix(context);
if (propType == PropertyType::Setter || propType == PropertyType::SetterNoExpressionClosure) {
prefix = context->names().setPrefix;
} else {
MOZ_ASSERT(propType == PropertyType::Getter || propType == PropertyType::GetterNoExpressionClosure);
prefix = context->names().getPrefix;
}
RootedString str(context, ConcatStrings<CanGC>(context, prefix, propAtom));
if (!str)
return nullptr;
return AtomizeString(context, str);
}
/*
* defineArg is called for both the arguments of a regular function definition
* and the arguments specified by the Function constructor.
@ -2417,7 +2398,7 @@ Parser<FullParseHandler>::bindLexicalFunctionName(HandlePropertyName funName,
template <>
bool
Parser<FullParseHandler>::checkFunctionDefinition(HandleAtom funAtom,
Parser<FullParseHandler>::checkFunctionDefinition(HandlePropertyName funName,
ParseNode** pn_, FunctionSyntaxKind kind,
bool* pbodyProcessed,
ParseNode** assignmentForAnnexBOut)
@ -2426,7 +2407,6 @@ Parser<FullParseHandler>::checkFunctionDefinition(HandleAtom funAtom,
*pbodyProcessed = false;
if (kind == Statement) {
RootedPropertyName funName(context, funAtom->asPropertyName());
MOZ_ASSERT(assignmentForAnnexBOut);
*assignmentForAnnexBOut = nullptr;
@ -2671,7 +2651,7 @@ Parser<ParseHandler>::addFreeVariablesFromLazyFunction(JSFunction* fun,
template <>
bool
Parser<SyntaxParseHandler>::checkFunctionDefinition(HandleAtom funAtom,
Parser<SyntaxParseHandler>::checkFunctionDefinition(HandlePropertyName funName,
Node* pn, FunctionSyntaxKind kind,
bool* pbodyProcessed,
Node* assignmentForAnnexBOut)
@ -2682,7 +2662,6 @@ Parser<SyntaxParseHandler>::checkFunctionDefinition(HandleAtom funAtom,
bool bodyLevel = pc->atBodyLevel();
if (kind == Statement) {
RootedPropertyName funName(context, funAtom->asPropertyName());
*assignmentForAnnexBOut = null();
if (!bodyLevel) {
@ -2791,7 +2770,7 @@ Parser<ParseHandler>::templateLiteral(YieldHandling yieldHandling)
template <typename ParseHandler>
typename ParseHandler::Node
Parser<ParseHandler>::functionDef(InHandling inHandling, YieldHandling yieldHandling,
HandleAtom funName, FunctionSyntaxKind kind,
HandlePropertyName funName, FunctionSyntaxKind kind,
GeneratorKind generatorKind, InvokedPrediction invoked,
Node* assignmentForAnnexBOut)
{
@ -7243,23 +7222,21 @@ Parser<FullParseHandler>::classDefinition(YieldHandling yieldHandling,
// FIXME: Implement ES6 function "name" property semantics
// (bug 883377).
RootedAtom funName(context);
RootedPropertyName funName(context);
switch (propType) {
case PropertyType::GetterNoExpressionClosure:
case PropertyType::SetterNoExpressionClosure:
if (!tokenStream.isCurrentTokenType(TOK_RB)) {
funName = prefixAccessorName(propType, propAtom);
if (!funName)
return null();
}
funName = nullptr;
break;
case PropertyType::Constructor:
case PropertyType::DerivedConstructor:
funName = name;
break;
default:
if (!tokenStream.isCurrentTokenType(TOK_RB))
funName = propAtom;
if (tokenStream.isCurrentTokenType(TOK_NAME))
funName = tokenStream.currentName();
else
funName = nullptr;
}
ParseNode* fn = methodDefinition(yieldHandling, propType, funName);
if (!fn)
@ -9386,17 +9363,18 @@ Parser<ParseHandler>::objectLiteral(YieldHandling yieldHandling, PossibleError*
} else {
// FIXME: Implement ES6 function "name" property semantics
// (bug 883377).
RootedAtom funName(context);
if (!tokenStream.isCurrentTokenType(TOK_RB)) {
funName = propAtom;
if (propType == PropertyType::Getter || propType == PropertyType::Setter) {
funName = prefixAccessorName(propType, propAtom);
if (!funName)
return null();
}
RootedPropertyName funName(context);
switch (propType) {
case PropertyType::Getter:
case PropertyType::Setter:
funName = nullptr;
break;
default:
if (tokenStream.isCurrentTokenType(TOK_NAME))
funName = tokenStream.currentName();
else
funName = nullptr;
}
Node fn = methodDefinition(yieldHandling, propType, funName);
if (!fn)
return null();
@ -9423,7 +9401,7 @@ Parser<ParseHandler>::objectLiteral(YieldHandling yieldHandling, PossibleError*
template <typename ParseHandler>
typename ParseHandler::Node
Parser<ParseHandler>::methodDefinition(YieldHandling yieldHandling, PropertyType propType,
HandleAtom funName)
HandlePropertyName funName)
{
FunctionSyntaxKind kind = FunctionSyntaxKindFromPropertyType(propType);
GeneratorKind generatorKind = GeneratorKindFromPropertyType(propType);

View File

@ -875,7 +875,8 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter
bool tryNewTarget(Node& newTarget);
bool checkAndMarkSuperScope();
Node methodDefinition(YieldHandling yieldHandling, PropertyType propType, HandleAtom funName);
Node methodDefinition(YieldHandling yieldHandling, PropertyType propType,
HandlePropertyName funName);
/*
* Additional JS parsers.
@ -883,7 +884,7 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter
bool functionArguments(YieldHandling yieldHandling, FunctionSyntaxKind kind,
Node funcpn, bool* hasRest);
Node functionDef(InHandling inHandling, YieldHandling uieldHandling, HandleAtom name,
Node functionDef(InHandling inHandling, YieldHandling uieldHandling, HandlePropertyName name,
FunctionSyntaxKind kind, GeneratorKind generatorKind,
InvokedPrediction invoked = PredictUninvoked,
Node* assignmentForAnnexBOut = nullptr);
@ -951,7 +952,7 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter
bool makeDefIntoUse(Definition* dn, Node pn, HandleAtom atom);
bool bindLexicalFunctionName(HandlePropertyName funName, ParseNode* pn);
bool bindBodyLevelFunctionName(HandlePropertyName funName, ParseNode** pn);
bool checkFunctionDefinition(HandleAtom funAtom, Node* pn, FunctionSyntaxKind kind,
bool checkFunctionDefinition(HandlePropertyName funName, Node* pn, FunctionSyntaxKind kind,
bool* pbodyProcessed, Node* assignmentForAnnexBOut);
bool finishFunctionDefinition(Node pn, FunctionBox* funbox, Node body);
bool addFreeVariablesFromLazyFunction(JSFunction* fun, ParseContext<ParseHandler>* pc);
@ -1058,8 +1059,6 @@ class Parser : private JS::AutoGCRooter, public StrictModeGetter
bool leaveFunction(Node fn, ParseContext<ParseHandler>* outerpc,
FunctionSyntaxKind kind = Expression);
JSAtom* prefixAccessorName(PropertyType propType, HandleAtom propAtom);
TokenPos pos() const { return tokenStream.currentToken().pos; }
bool asmJS(Node list);

View File

@ -1,7 +1,7 @@
var o = {get prop() a + b, set prop(x) a + b};
var prop = Object.getOwnPropertyDescriptor(o, "prop");
assertEq(prop.get.toString(), "function get prop() a + b");
assertEq(prop.get.toSource(), "(function get prop() a + b)");
assertEq(prop.set.toString(), "function set prop(x) a + b");
assertEq(prop.set.toSource(), "(function set prop(x) a + b)");
assertEq(prop.get.toString(), "function () a + b");
assertEq(prop.get.toSource(), "(function () a + b)");
assertEq(prop.set.toString(), "function (x) a + b");
assertEq(prop.set.toSource(), "(function (x) a + b)");
assertEq(o.toSource(), "({get prop () a + b, set prop (x) a + b})");

View File

@ -20,11 +20,11 @@ cold_and_warm(entry1, { function: entry1 }, [ "entry1" ]);
var getx = { get x() { } };
cold_and_warm(Object.getOwnPropertyDescriptor(getx, 'x').get,
{ object: getx, property: 'x' }, [ "get x" ]);
{ object: getx, property: 'x' }, [ "getx.x" ]);
var sety = { set y(v) { } };
cold_and_warm(Object.getOwnPropertyDescriptor(sety, 'y').set,
{ object: sety, property: 'y', value: 'glerk' }, [ "set y" ]);
{ object: sety, property: 'y', value: 'glerk' }, [ "sety.y" ]);
cold_and_warm(Object.prototype.toString, { ToString: {} }, []);

View File

@ -1,40 +0,0 @@
class TestClass {
get getter() { }
set setter(x) { }
method() { }
static get staticGetter() { }
static set staticSetter(x) { }
static staticMethod() { }
get 1() { }
set 2(v) { }
3() { }
static get 4() { }
static set 5(x) { }
static 6() { }
}
function name(obj, property, get) {
let desc = Object.getOwnPropertyDescriptor(obj, property);
return (get ? desc.get : desc.set).name;
}
assertEq(name(TestClass.prototype, "getter", true), "get getter");
assertEq(name(TestClass.prototype, "setter", false), "set setter");
assertEq(TestClass.prototype.method.name, "method");
assertEq(name(TestClass, "staticGetter", true), "get staticGetter");
assertEq(name(TestClass, "staticSetter", false), "set staticSetter");
assertEq(TestClass.staticMethod.name, "staticMethod");
assertEq(name(TestClass.prototype, "1", true), "get 1");
assertEq(name(TestClass.prototype, "2", false), "set 2");
assertEq(TestClass.prototype[3].name, "3");
assertEq(name(TestClass, "4", true), "get 4");
assertEq(name(TestClass, "5", false), "set 5");
assertEq(TestClass[6].name, "6");
reportCompare(true, true);

View File

@ -1,36 +0,0 @@
function name(obj, property, get) {
let desc = Object.getOwnPropertyDescriptor(obj, property);
return (get ? desc.get : desc.set).name;
}
assertEq(name({get a() {}}, "a", true), "get a");
assertEq(name({set a(v) {}}, "a", false), "set a");
assertEq(name({get 123() {}}, "123", true), "get 123");
assertEq(name({set 123(v) {}}, "123", false), "set 123");
assertEq(name({get case() {}}, "case", true), "get case");
assertEq(name({set case(v) {}}, "case", false), "set case");
assertEq(name({get get() {}}, "get", true), "get get");
assertEq(name({set set(v) {}}, "set", false), "set set");
let o = {get a() { }, set a(v) {}};
assertEq(name(o, "a", true), "get a");
assertEq(name(o, "a", false), "set a");
o = {get 123() { }, set 123(v) {}}
assertEq(name(o, "123", true), "get 123");
assertEq(name(o, "123", false), "set 123");
o = {get case() { }, set case(v) {}}
assertEq(name(o, "case", true), "get case");
assertEq(name(o, "case", false), "set case");
// Congratulations on implementing these!
assertEq(name({get ["a"]() {}}, "a", true), "");
assertEq(name({get [123]() {}}, "123", true), "");
assertEq(name({set ["a"](v) {}}, "a", false), "");
assertEq(name({set [123](v) {}}, "123", false), "");
reportCompare(true, true);

View File

@ -4,19 +4,8 @@ function testClasses() {
function methodFun(id, kind, generator, args, body = []) {
assertEq(generator && kind === "method", generator);
assertEq(typeof id === 'string' || id === null, true);
let methodName;
switch (kind) {
case "method":
methodName = typeof id === 'string' ? ident(id) : null;
break;
case "get":
case "set":
methodName = ident(`${kind} ${typeof id === 'string' ? id : ""}`);
break;
default:
methodName = null;
break;
}
let idN = typeof id === 'string' ? ident(id) : null;
let methodName = kind !== "method" ? null : idN;
return generator
? genFunExpr("es6", methodName, args.map(ident), blockStmt(body))
: funExpr(methodName, args.map(ident), blockStmt(body));

View File

@ -19,11 +19,11 @@ assertError("({ a() false })", SyntaxError);
assertExpr("({ get x() { return 42 } })",
objExpr([ { key: ident("x"),
value: funExpr(ident("get x"), [], blockStmt([returnStmt(lit(42))])),
value: funExpr(null, [], blockStmt([returnStmt(lit(42))])),
kind: "get" } ]));
assertExpr("({ set x(v) { return 42 } })",
objExpr([ { key: ident("x"),
value: funExpr(ident("set x"), [ident("v")], blockStmt([returnStmt(lit(42))])),
value: funExpr(null, [ident("v")], blockStmt([returnStmt(lit(42))])),
kind: "set" } ]));
// Bug 1073809 - Getter/setter syntax with generators

View File

@ -122,7 +122,6 @@
macro(gcCycleNumber, gcCycleNumber, "gcCycleNumber") \
macro(GeneratorFunction, GeneratorFunction, "GeneratorFunction") \
macro(get, get, "get") \
macro(getPrefix, getPrefix, "get ") \
macro(getInternals, getInternals, "getInternals") \
macro(getOwnPropertyDescriptor, getOwnPropertyDescriptor, "getOwnPropertyDescriptor") \
macro(getOwnPropertyNames, getOwnPropertyNames, "getOwnPropertyNames") \
@ -237,7 +236,6 @@
macro(sensitivity, sensitivity, "sensitivity") \
macro(separator, separator, "separator") \
macro(set, set, "set") \
macro(setPrefix, setPrefix, "set ") \
macro(shape, shape, "shape") \
macro(size, size, "size") \
macro(source, source, "source") \