Skip to content
Permalink
Browse files
StringLiteral and NumericLiteral are allowed as ObjectLiteral getter …
…/ setter name

https://bugs.webkit.org/show_bug.cgi?id=79571

Patch by Yusuke Suzuki <utatane.tea@gmail.com> on 2012-02-26
Reviewed by Gavin Barraclough.

Source/JavaScriptCore:

* parser/ASTBuilder.h:
(JSC::ASTBuilder::createGetterOrSetterProperty):
* parser/Parser.cpp:
(JSC::::parseProperty):
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::createGetterOrSetterProperty):

LayoutTests:

* fast/js/property-getters-and-setters-expected.txt:
* fast/js/script-tests/property-getters-and-setters.js:
(o9.string_appeared_here.7.get string_appeared_here):
(o9.set string_appeared_here):
(get shouldBe):
(o10.string_appeared_here.7.get 42):
(o10.set 42):
* platform/chromium/fast/js/property-getters-and-setters-expected.txt:

Canonical link: https://commits.webkit.org/96705@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@108935 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Constellation authored and webkit-commit-queue committed Feb 26, 2012
1 parent 0e344d4 commit a837eec215ee651d011a4a5a7c17bd061f586094
Showing 8 changed files with 78 additions and 3 deletions.
@@ -1,3 +1,19 @@
2012-02-26 Yusuke Suzuki <utatane.tea@gmail.com>

StringLiteral and NumericLiteral are allowed as ObjectLiteral getter / setter name
https://bugs.webkit.org/show_bug.cgi?id=79571

Reviewed by Gavin Barraclough.

* fast/js/property-getters-and-setters-expected.txt:
* fast/js/script-tests/property-getters-and-setters.js:
(o9.string_appeared_here.7.get string_appeared_here):
(o9.set string_appeared_here):
(get shouldBe):
(o10.string_appeared_here.7.get 42):
(o10.set 42):
* platform/chromium/fast/js/property-getters-and-setters-expected.txt:

2012-02-26 Sheriff Bot <webkit.review.bot@gmail.com>

Unreviewed, rolling out r108547.
@@ -30,6 +30,12 @@ PASS o7.x is undefined.
If an object has a property and its prototype has a setter function for that property, then setting the property should set the property directly and not call the setter function.
PASS o8.numSets is 0
PASS typeof testObj.getter is 'string'
the get set with string property name
PASS o9.b is 8
PASS o9.b is 11
the get set with numeric property name
PASS o10[42] is 8
PASS o10[42] is 11
PASS successfullyParsed is true

TEST COMPLETE
@@ -67,3 +67,15 @@ shouldBe("o8.numSets", "0");
({getter:"foo", b:"bar"});
testObj=({get getter(){return 'getter was called.'}, b: 'bar'})
shouldBe("typeof testObj.getter", "'string'");

debug("the get set with string property name");
var o9 = { 'a':7, get 'b'() { return this.a + 1 }, set 'b'(x) { this.a = x } }
shouldBe("o9.b", "8");
o9.b = 10;
shouldBe("o9.b", "11");

debug("the get set with numeric property name");
var o10 = { 'a':7, get 42() { return this.a + 1 }, set 42(x) { this.a = x } }
shouldBe("o10[42]", "8");
o10[42] = 10;
shouldBe("o10[42]", "11");
@@ -30,6 +30,12 @@ PASS o7.x is undefined.
If an object has a property and its prototype has a setter function for that property, then setting the property should set the property directly and not call the setter function.
PASS o8.numSets is 0
PASS typeof testObj.getter is 'string'
the get set with string property name
PASS o9.b is 8
PASS o9.b is 11
the get set with numeric property name
PASS o10[42] is 8
PASS o10[42] is 11
PASS successfullyParsed is true

TEST COMPLETE
@@ -1,3 +1,17 @@
2012-02-26 Yusuke Suzuki <utatane.tea@gmail.com>

StringLiteral and NumericLiteral are allowed as ObjectLiteral getter / setter name
https://bugs.webkit.org/show_bug.cgi?id=79571

Reviewed by Gavin Barraclough.

* parser/ASTBuilder.h:
(JSC::ASTBuilder::createGetterOrSetterProperty):
* parser/Parser.cpp:
(JSC::::parseProperty):
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::createGetterOrSetterProperty):

2012-02-26 Mark Hahnenberg <mhahnenberg@apple.com>

Implement fast path for op_new_array in the baseline JIT
@@ -276,6 +276,11 @@ class ASTBuilder {
return new (m_globalData) PropertyNode(m_globalData, *name, new (m_globalData) FuncExprNode(lineNumber, m_globalData->propertyNames->nullIdentifier, body, m_sourceCode->subExpression(openBracePos, closeBracePos, bodyStartLine), params), type);
}

template <bool> PropertyNode* createGetterOrSetterProperty(JSGlobalData*, int lineNumber, PropertyNode::Type type, double name, ParameterNode* params, FunctionBodyNode* body, int openBracePos, int closeBracePos, int bodyStartLine, int bodyEndLine)
{
body->setLoc(bodyStartLine, bodyEndLine);
return new (m_globalData) PropertyNode(m_globalData, name, new (m_globalData) FuncExprNode(lineNumber, m_globalData->propertyNames->nullIdentifier, body, m_sourceCode->subExpression(openBracePos, closeBracePos, bodyStartLine), params), type);
}

ArgumentsNode* createArguments() { return new (m_globalData) ArgumentsNode(); }
ArgumentsNode* createArguments(ArgumentListNode* args) { return new (m_globalData) ArgumentsNode(args); }
@@ -1204,7 +1204,6 @@ template <bool complete, class TreeBuilder> TreeProperty Parser<LexerType>::pars
return context.template createProperty<complete>(ident, node, PropertyNode::Constant);
}
failIfFalse(wasIdent);
matchOrFail(IDENT);
const Identifier* accessorName = 0;
TreeFormalParameterList parameters = 0;
TreeFunctionBody body = 0;
@@ -1218,8 +1217,19 @@ template <bool complete, class TreeBuilder> TreeProperty Parser<LexerType>::pars
type = PropertyNode::Setter;
else
fail();
failIfFalse((parseFunctionInfo<FunctionNeedsName, false>(context, accessorName, parameters, body, openBracePos, closeBracePos, bodyStartLine)));
return context.template createGetterOrSetterProperty<complete>(m_lexer->lastLineNumber(), type, accessorName, parameters, body, openBracePos, closeBracePos, bodyStartLine, m_lastLine);
const Identifier* stringPropertyName = 0;
double numericPropertyName = 0;
if (m_token.m_type == IDENT || m_token.m_type == STRING)
stringPropertyName = m_token.m_data.ident;
else if (m_token.m_type == NUMBER)
numericPropertyName = m_token.m_data.doubleValue;
else
fail();
next();
failIfFalse((parseFunctionInfo<FunctionNoRequirements, false>(context, accessorName, parameters, body, openBracePos, closeBracePos, bodyStartLine)));
if (stringPropertyName)
return context.template createGetterOrSetterProperty<complete>(m_lexer->lastLineNumber(), type, stringPropertyName, parameters, body, openBracePos, closeBracePos, bodyStartLine, m_lastLine);
return context.template createGetterOrSetterProperty<complete>(const_cast<JSGlobalData*>(m_globalData), m_lexer->lastLineNumber(), type, numericPropertyName, parameters, body, openBracePos, closeBracePos, bodyStartLine, m_lastLine);
}
case NUMBER: {
double propertyName = m_token.m_data.doubleValue;
@@ -210,6 +210,12 @@ class SyntaxChecker {
return Property(type);
return Property(name, type);
}
template <bool strict> Property createGetterOrSetterProperty(JSGlobalData* globalData, int, PropertyNode::Type type, double name, int, int, int, int, int, int)
{
if (!strict)
return Property(type);
return Property(&globalData->parserArena->identifierArena().makeNumericIdentifier(globalData, name), type);
}

void appendStatement(int, int) { }
void addVar(const Identifier*, bool) { }

0 comments on commit a837eec

Please sign in to comment.