Changeset 204895 in webkit
- Timestamp:
- Aug 24, 2016 6:35:38 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r204881 r204895 1 2016-08-24 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 [ES2016] Allow assignment in for-in head in not-strict mode 4 https://bugs.webkit.org/show_bug.cgi?id=160955 5 6 Reviewed by Saam Barati. 7 8 * stress/for-in-tests.js: 9 (foo): 10 (boo): 11 (catch): 12 1 13 2016-08-23 Benjamin Poulain <benjamin@webkit.org> 2 14 -
trunk/JSTests/stress/for-in-tests.js
r172413 r204895 99 99 } 100 100 })(); 101 102 (function() { 103 var foo = function(a, b) { 104 for (var p = b in a) {} 105 return p; 106 }; 107 noInline(foo); 108 for (var i = 0; i < 10000; ++i) { 109 var expected = 'expected-result'; 110 var result = foo({}, expected); 111 if (expected !== result) 112 throw new Error("bad result: " + result + "!==" + expected); 113 } 114 for (var i = 0; i < 10000; ++i) { 115 var expected = 'a'; 116 var result = foo({a:'abcd'}, expected); 117 if (expected !== result) 118 throw new Error("bad result: " + result + "!==" + expected); 119 } 120 for (var i = 0; i < 10000; ++i) { 121 var expected = 'b'; 122 var result = foo({a:'abcd', b: 'bcde'}, expected); 123 if (expected !== result) 124 throw new Error("bad result: " + result + "!==" + expected); 125 } 126 127 for (var i = 0; i < 10000; ++i) { 128 var expected = 'c'; 129 var o = {a:'abcd', b: 'bcde'}; 130 o.c = 'cdef'; 131 var result = foo(o, expected); 132 if (expected !== result) 133 throw new Error("bad result: " + result + "!==" + expected); 134 } 135 })(); 136 137 (function() { 138 var boo = function () { return 'expected-result'; }; 139 var foo = function(a) { 140 for (var p = boo() in a) {} 141 return p; 142 }; 143 noInline(foo); 144 for (var i = 0; i < 10000; ++i) { 145 var expected = 'expected-result'; 146 var result = foo({}); 147 if (expected !== result) 148 throw new Error("bad result: " + result + "!==" + expected); 149 } 150 })(); 151 152 (function() { 153 var foo = function(a, b, first) { 154 { 155 let p = 'some-value'; 156 for (var p = b in a) {} 157 if (first) 158 return p; 159 } 160 return p; 161 }; 162 noInline(foo); 163 for (var i = 0; i < 10000; ++i) { 164 var expected = 'expected-result'; 165 var result = foo({}, expected, true); 166 if (expected !== result) 167 throw new Error("bad result: " + result + "!==" + expected); 168 } 169 for (var i = 0; i < 10000; ++i) { 170 var expected = 'expected-result'; 171 var result = foo({}, expected, false); 172 if (typeof result !== 'undefined') 173 throw new Error("bad result: " + result + "!== undefined"); 174 } 175 })(); 176 177 (function() { 178 var foo = function(a, b, c) { 179 for (var p = b + c in a) {} 180 return p; 181 }; 182 noInline(foo); 183 for (var i = 0; i < 10000; ++i) { 184 var expected = 'expected-result'; 185 var result = foo({}, 'expected', '-result'); 186 if (expected !== result) 187 throw new Error("bad result: " + result + "!==" + expected); 188 } 189 })(); 190 191 (function() { 192 var error = false; 193 try { 194 eval("(function() { 'use strict'; for (var i = 0 in {}) {}})()"); 195 } catch(e) { 196 error = e instanceof SyntaxError; 197 } 198 if (!error) 199 throw new Error("Expected SyntaxError error"); 200 })(); 201 202 (function() { 203 var error = false; 204 try { 205 eval("(function() { const i = 10; for (var i = 0 in {}) {}})()"); 206 } catch(e) { 207 error = e instanceof SyntaxError; 208 } 209 if (!error) 210 throw new Error("Expected SyntaxError error"); 211 })(); -
trunk/LayoutTests/ChangeLog
r204891 r204895 1 2016-08-24 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 [ES2016] Allow assignment in for-in head in not-strict mode 4 https://bugs.webkit.org/show_bug.cgi?id=160955 5 6 Reviewed by Saam Barati. 7 8 * js/parser-syntax-check-expected.txt: 9 * js/script-tests/parser-syntax-check.js: 10 1 11 2016-08-24 Youenn Fablet <youenn@apple.com> 2 12 -
trunk/LayoutTests/js/parser-syntax-check-expected.txt
r204078 r204895 507 507 PASS Valid: "for (var a = 5 += 6 in b) break" with ReferenceError 508 508 PASS Valid: "function f() { for (var a = 5 += 6 in b) break }" 509 PASS Valid: "for (var a = debug('should notbe hit') in b) break" with ReferenceError510 PASS Valid: "function f() { for (var a = debug('should notbe hit') in b) break }"509 PASS Valid: "for (var a = foo('should be hit') in b) break" with ReferenceError 510 PASS Valid: "function f() { for (var a = foo('should be hit') in b) break }" 511 511 PASS Invalid: "for (var a += 5 in b) break" 512 512 PASS Invalid: "function f() { for (var a += 5 in b) break }" -
trunk/LayoutTests/js/script-tests/parser-syntax-check.js
r204078 r204895 347 347 valid ("for (var a in b in c) break"); 348 348 valid("for (var a = 5 += 6 in b) break"); 349 valid("for (var a = debug('should notbe hit') in b) break");349 valid("for (var a = foo('should be hit') in b) break"); 350 350 invalid("for (var a += 5 in b) break"); 351 351 invalid("for (var a = in b) break"); -
trunk/Source/JavaScriptCore/ChangeLog
r204882 r204895 1 2016-08-24 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 [ES2016] Allow assignment in for-in head in not-strict mode 4 https://bugs.webkit.org/show_bug.cgi?id=160955 5 6 Reviewed by Saam Barati. 7 8 This patch allow make assignment in for..in head in not-strict mode, 9 according to the spec https://tc39.github.io/ecma262/#sec-initializers-in-forin-statement-heads 10 11 * bytecompiler/NodesCodegen.cpp: 12 (JSC::ForInNode::emitLoopHeader): 13 (JSC::ForInNode::emitMultiLoopBytecode): 14 * parser/Nodes.h: 15 (JSC::ExpressionNode::isAssignResolveNode): 16 (JSC::AssignResolveNode::identifier): 17 (JSC::ExpressionNode::isResolveNode): Deleted. 18 * parser/Parser.cpp: 19 (JSC::Parser<LexerType>::parseForStatement): 20 1 21 2016-08-23 Saam Barati <sbarati@apple.com> 2 22 -
trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
r204597 r204895 2560 2560 void ForInNode::emitLoopHeader(BytecodeGenerator& generator, RegisterID* propertyName) 2561 2561 { 2562 if (m_lexpr->isResolveNode()) {2563 const Identifier& ident = static_cast<ResolveNode*>(m_lexpr)->identifier();2562 auto lambdaEmitResolveVariable = [&](const Identifier& ident) 2563 { 2564 2564 Variable var = generator.variable(ident); 2565 2565 if (RegisterID* local = var.local()) { … … 2577 2577 } 2578 2578 generator.emitProfileType(propertyName, var, m_lexpr->position(), JSTextPosition(-1, m_lexpr->position().offset + ident.length(), -1)); 2579 }; 2580 2581 if (m_lexpr->isResolveNode()) { 2582 const Identifier& ident = static_cast<ResolveNode*>(m_lexpr)->identifier(); 2583 lambdaEmitResolveVariable(ident); 2579 2584 return; 2580 2585 } 2586 2587 if (m_lexpr->isAssignResolveNode()) { 2588 const Identifier& ident = static_cast<AssignResolveNode*>(m_lexpr)->identifier(); 2589 lambdaEmitResolveVariable(ident); 2590 return; 2591 } 2592 2581 2593 if (m_lexpr->isDotAccessorNode()) { 2582 2594 DotAccessorNode* assignNode = static_cast<DotAccessorNode*>(m_lexpr); … … 2631 2643 void ForInNode::emitMultiLoopBytecode(BytecodeGenerator& generator, RegisterID* dst) 2632 2644 { 2633 if (!m_lexpr->isAssign mentLocation()) {2645 if (!m_lexpr->isAssignResolveNode() && !m_lexpr->isAssignmentLocation()) { 2634 2646 emitThrowReferenceError(generator, ASCIILiteral("Left side of for-in statement is not a reference.")); 2635 2647 return; … … 2642 2654 2643 2655 generator.emitDebugHook(WillExecuteStatement, firstLine(), startOffset(), lineStartOffset()); 2656 2657 if (m_lexpr->isAssignResolveNode()) 2658 generator.emitNode(generator.ignoredResult(), m_lexpr); 2644 2659 2645 2660 RefPtr<RegisterID> base = generator.newTemporary(); 2646 2661 RefPtr<RegisterID> length; 2647 2662 RefPtr<RegisterID> enumerator; 2663 2648 2664 generator.emitNode(base.get(), m_expr); 2649 2665 RefPtr<RegisterID> local = this->tryGetBoundLocal(generator); -
trunk/Source/JavaScriptCore/parser/Nodes.h
r204854 r204895 169 169 virtual bool isAssignmentLocation() const { return isLocation(); } 170 170 virtual bool isResolveNode() const { return false; } 171 virtual bool isAssignResolveNode() const { return false; } 171 172 virtual bool isBracketAccessorNode() const { return false; } 172 173 virtual bool isDotAccessorNode() const { return false; } … … 1218 1219 public: 1219 1220 AssignResolveNode(const JSTokenLocation&, const Identifier&, ExpressionNode* right, AssignmentContext); 1221 bool isAssignResolveNode() const override { return true; } 1222 const Identifier& identifier() const { return m_ident; } 1220 1223 1221 1224 private: -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r204842 r204895 1204 1204 if (isOfEnumeration) 1205 1205 result = context.createForOfLoop(location, forInTarget, expr, statement, declsStart, inLocation, exprEnd, startLine, endLine, *lexicalVariables); 1206 else 1207 result = context.createForInLoop(location, forInTarget, expr, statement, declsStart, inLocation, exprEnd, startLine, endLine, *lexicalVariables); 1206 else { 1207 if (isVarDeclaraton && forInInitializer) 1208 result = context.createForInLoop(location, decls, expr, statement, declsStart, inLocation, exprEnd, startLine, endLine, *lexicalVariables); 1209 else 1210 result = context.createForInLoop(location, forInTarget, expr, statement, declsStart, inLocation, exprEnd, startLine, endLine, *lexicalVariables); 1211 } 1208 1212 popLexicalScopeIfNecessary(); 1209 1213 return result;
Note: See TracChangeset
for help on using the changeset viewer.