Changeset 156497 in webkit
- Timestamp:
- Sep 26, 2013 2:27:00 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 12 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r156495 r156497 1 2013-09-26 Commit Queue <commit-queue@webkit.org> 2 3 Unreviewed, rolling out r156464 and r156480. 4 http://trac.webkit.org/changeset/156464 5 http://trac.webkit.org/changeset/156480 6 https://bugs.webkit.org/show_bug.cgi?id=121981 7 8 Leaking too much and killi 9 ng buildbot. (Requested by xenon on 10 #webkit). 11 12 * js/destructuring-assignment-expected.txt: Removed. 13 * js/destructuring-assignment.html: Removed. 14 * js/mozilla/strict/13.1-expected.txt: 15 * js/mozilla/strict/regress-532254-expected.txt: 16 * js/mozilla/strict/script-tests/13.1.js: 17 * js/regress/destructuring-arguments-expected.txt: Removed. 18 * js/regress/destructuring-arguments-length-expected.txt: Removed. 19 * js/regress/destructuring-arguments-length.html: Removed. 20 * js/regress/destructuring-arguments.html: Removed. 21 * js/regress/destructuring-swap-expected.txt: Removed. 22 * js/regress/destructuring-swap.html: Removed. 23 * js/regress/script-tests/destructuring-arguments-length.js: Removed. 24 * js/regress/script-tests/destructuring-arguments.js: Removed. 25 * js/regress/script-tests/destructuring-swap.js: Removed. 26 * js/script-tests/destructuring-assignment.js: Removed. 27 * sputnik/Conformance/13_Function_Definition/S13_A5.html: 28 1 29 2013-09-26 Alexey Proskuryakov <ap@apple.com> 2 30 -
trunk/LayoutTests/js/mozilla/strict/13.1-expected.txt
r156464 r156497 11 11 PASS !!Function("function f(a,b,c,d,e,f,g,h,d) {}") is true 12 12 PASS true === true 13 PASS !!Function("'use strict'; function f([x,y]) {}") is true14 PASS !!Function("function f([x,y]) {}") is true13 PASS Function("'use strict'; function f([x,y]) {}") threw exception of type SyntaxError. 14 PASS Function("function f([x,y]) {}") threw exception of type SyntaxError. 15 15 PASS true === true 16 16 PASS Function("'use strict'; function f([x,x]){}") threw exception of type SyntaxError. … … 39 39 PASS true === true 40 40 PASS Function("'use strict'; function f([eval]){}") threw exception of type SyntaxError. 41 PASS !!Function("function f([eval]){}") is true41 PASS Function("function f([eval]){}") threw exception of type SyntaxError. 42 42 PASS true === true 43 43 PASS Function("'use strict'; function f({x:eval}){}") threw exception of type SyntaxError. 44 PASS !!Function("function f({x:eval}){}") is true44 PASS Function("function f({x:eval}){}") threw exception of type SyntaxError. 45 45 PASS true === true 46 46 PASS Function("'use strict'; function eval(){}") threw exception of type SyntaxError. … … 63 63 PASS true === true 64 64 PASS Function("'use strict'; (function f([eval]){})") threw exception of type SyntaxError. 65 PASS !!Function("(function f([eval]){})") is true65 PASS Function("(function f([eval]){})") threw exception of type SyntaxError. 66 66 PASS true === true 67 67 PASS Function("'use strict'; (function f({x:eval}){})") threw exception of type SyntaxError. 68 PASS !!Function("(function f({x:eval}){})") is true68 PASS Function("(function f({x:eval}){})") threw exception of type SyntaxError. 69 69 PASS true === true 70 70 PASS Function("'use strict'; (function eval(){})") threw exception of type SyntaxError. … … 99 99 PASS true === true 100 100 PASS Function("'use strict'; ({set x([eval]){}})") threw exception of type SyntaxError. 101 PASS !!Function("({set x([eval]){}})") is true101 PASS Function("({set x([eval]){}})") threw exception of type SyntaxError. 102 102 PASS true === true 103 103 PASS Function("'use strict'; ({set x({x:eval}){}})") threw exception of type SyntaxError. 104 PASS !!Function("({set x({x:eval}){}})") is true104 PASS Function("({set x({x:eval}){}})") threw exception of type SyntaxError. 105 105 PASS true === true 106 106 PASS Function("'use strict'; ({set x(eval){\"use strict\";}})") threw exception of type SyntaxError. … … 117 117 PASS true === true 118 118 PASS Function("'use strict'; function f([arguments]){}") threw exception of type SyntaxError. 119 PASS !!Function("function f([arguments]){}") is true119 PASS Function("function f([arguments]){}") threw exception of type SyntaxError. 120 120 PASS true === true 121 121 PASS Function("'use strict'; function f({x:arguments}){}") threw exception of type SyntaxError. 122 PASS !!Function("function f({x:arguments}){}") is true122 PASS Function("function f({x:arguments}){}") threw exception of type SyntaxError. 123 123 PASS true === true 124 124 PASS Function("'use strict'; function arguments(){}") threw exception of type SyntaxError. … … 141 141 PASS true === true 142 142 PASS Function("'use strict'; (function f([arguments]){})") threw exception of type SyntaxError. 143 PASS !!Function("(function f([arguments]){})") is true143 PASS Function("(function f([arguments]){})") threw exception of type SyntaxError. 144 144 PASS true === true 145 145 PASS Function("'use strict'; (function f({x:arguments}){})") threw exception of type SyntaxError. 146 PASS !!Function("(function f({x:arguments}){})") is true146 PASS Function("(function f({x:arguments}){})") threw exception of type SyntaxError. 147 147 PASS true === true 148 148 PASS Function("'use strict'; (function arguments(){})") threw exception of type SyntaxError. … … 177 177 PASS true === true 178 178 PASS Function("'use strict'; ({set x([arguments]){}})") threw exception of type SyntaxError. 179 PASS !!Function("({set x([arguments]){}})") is true179 PASS Function("({set x([arguments]){}})") threw exception of type SyntaxError. 180 180 PASS true === true 181 181 PASS Function("'use strict'; ({set x({x:arguments}){}})") threw exception of type SyntaxError. 182 PASS !!Function("({set x({x:arguments}){}})") is true182 PASS Function("({set x({x:arguments}){}})") threw exception of type SyntaxError. 183 183 PASS true === true 184 184 PASS Function("'use strict'; ({set x(arguments){\"use strict\";}})") threw exception of type SyntaxError. -
trunk/LayoutTests/js/mozilla/strict/regress-532254-expected.txt
r156464 r156497 1 1 PASS Function("'use strict'; function f(eval,[x]){}") threw exception of type SyntaxError. 2 PASS !!Function("function f(eval,[x]){}") is true 2 FAIL !!Function("function f(eval,[x]){}") should be true. Threw exception SyntaxError: Expected an identifier but found '[' instead 3 3 PASS true === true 4 4 PASSED! -
trunk/LayoutTests/js/mozilla/strict/script-tests/13.1.js
r156464 r156497 40 40 // Destructuring is not valid ES5 syntax. 41 41 assertEq(testLenientAndStrict('function f([x,y]) {}', 42 parse sSuccessfully,43 parse sSuccessfully),42 parseRaisesException(SyntaxError), 43 parseRaisesException(SyntaxError)), 44 44 true); 45 45 assertEq(testLenientAndStrict('function f([x,x]){}', … … 119 119 // Destructuring is not valid ES5 syntax. 120 120 assertEq(testLenientAndStrict('function f([eval]){}', 121 parse sSuccessfully,121 parseRaisesException(SyntaxError), 122 122 parseRaisesException(SyntaxError)), 123 123 true); 124 124 // Destructuring is not valid ES5 syntax. 125 125 assertEq(testLenientAndStrict('function f({x:eval}){}', 126 parse sSuccessfully,126 parseRaisesException(SyntaxError), 127 127 parseRaisesException(SyntaxError)), 128 128 true); … … 155 155 // Destructuring is not valid ES5 syntax. 156 156 assertEq(testLenientAndStrict('(function f([eval]){})', 157 parse sSuccessfully,157 parseRaisesException(SyntaxError), 158 158 parseRaisesException(SyntaxError)), 159 159 true); 160 160 // Destructuring is not valid ES5 syntax. 161 161 assertEq(testLenientAndStrict('(function f({x:eval}){})', 162 parse sSuccessfully,162 parseRaisesException(SyntaxError), 163 163 parseRaisesException(SyntaxError)), 164 164 true); … … 209 209 // Destructuring is not valid ES5 syntax. 210 210 assertEq(testLenientAndStrict('({set x([eval]){}})', 211 parse sSuccessfully,211 parseRaisesException(SyntaxError), 212 212 parseRaisesException(SyntaxError)), 213 213 true); 214 214 // Destructuring is not valid ES5 syntax. 215 215 assertEq(testLenientAndStrict('({set x({x:eval}){}})', 216 parse sSuccessfully,216 parseRaisesException(SyntaxError), 217 217 parseRaisesException(SyntaxError)), 218 218 true); … … 235 235 // Destructuring is not valid ES5 syntax. 236 236 assertEq(testLenientAndStrict('function f([arguments]){}', 237 parse sSuccessfully,237 parseRaisesException(SyntaxError), 238 238 parseRaisesException(SyntaxError)), 239 239 true); 240 240 // Destructuring is not valid ES5 syntax. 241 241 assertEq(testLenientAndStrict('function f({x:arguments}){}', 242 parse sSuccessfully,242 parseRaisesException(SyntaxError), 243 243 parseRaisesException(SyntaxError)), 244 244 true); … … 270 270 // Destructuring is not valid ES5 syntax. 271 271 assertEq(testLenientAndStrict('(function f([arguments]){})', 272 parse sSuccessfully,272 parseRaisesException(SyntaxError), 273 273 parseRaisesException(SyntaxError)), 274 274 true); 275 275 // Destructuring is not valid ES5 syntax. 276 276 assertEq(testLenientAndStrict('(function f({x:arguments}){})', 277 parse sSuccessfully,277 parseRaisesException(SyntaxError), 278 278 parseRaisesException(SyntaxError)), 279 279 true); … … 324 324 // Destructuring is not valid ES5 syntax. 325 325 assertEq(testLenientAndStrict('({set x([arguments]){}})', 326 parse sSuccessfully,326 parseRaisesException(SyntaxError), 327 327 parseRaisesException(SyntaxError)), 328 328 true); 329 329 // Destructuring is not valid ES5 syntax. 330 330 assertEq(testLenientAndStrict('({set x({x:arguments}){}})', 331 parse sSuccessfully,331 parseRaisesException(SyntaxError), 332 332 parseRaisesException(SyntaxError)), 333 333 true); -
trunk/LayoutTests/sputnik/Conformance/13_Function_Definition/S13_A5.html
r156464 r156497 77 77 try{ 78 78 eval("function __func([arg1, arg2, arg3]){return arguments.length;}"); 79 testFailed('#1: eval("function __func([arg1, arg2, arg3]){return arguments.length;}") lead to throwing exception'); 79 80 } catch(e){ 80 81 if(!(e instanceof SyntaxError)){ -
trunk/Source/JavaScriptCore/ChangeLog
r156494 r156497 1 2013-09-26 Commit Queue <commit-queue@webkit.org> 2 3 Unreviewed, rolling out r156464 and r156480. 4 http://trac.webkit.org/changeset/156464 5 http://trac.webkit.org/changeset/156480 6 https://bugs.webkit.org/show_bug.cgi?id=121981 7 8 Leaking too much and killi 9 ng buildbot. (Requested by xenon on 10 #webkit). 11 12 * bytecode/UnlinkedCodeBlock.cpp: 13 (JSC::UnlinkedFunctionExecutable::paramString): 14 * bytecompiler/BytecodeGenerator.cpp: 15 (JSC::BytecodeGenerator::BytecodeGenerator): 16 * bytecompiler/BytecodeGenerator.h: 17 (JSC::BytecodeGenerator::emitExpressionInfo): 18 * bytecompiler/NodesCodegen.cpp: 19 (JSC::ForInNode::emitBytecode): 20 (JSC::FuncExprNode::emitBytecode): 21 * parser/ASTBuilder.h: 22 (JSC::ASTBuilder::createFormalParameterList): 23 (JSC::ASTBuilder::createForInLoop): 24 (JSC::ASTBuilder::addVar): 25 * parser/NodeConstructors.h: 26 (JSC::CommaNode::CommaNode): 27 (JSC::ParameterNode::ParameterNode): 28 (JSC::ForInNode::ForInNode): 29 * parser/Nodes.cpp: 30 (JSC::FunctionParameters::create): 31 (JSC::FunctionParameters::FunctionParameters): 32 (JSC::FunctionParameters::~FunctionParameters): 33 * parser/Nodes.h: 34 (JSC::CommaNode::append): 35 (JSC::ParameterNode::ident): 36 (JSC::FunctionParameters::at): 37 (JSC::FunctionParameters::identifiers): 38 * parser/Parser.cpp: 39 (JSC::::Parser): 40 (JSC::::parseVarDeclaration): 41 (JSC::::parseVarDeclarationList): 42 (JSC::::parseForStatement): 43 (JSC::::parseFormalParameters): 44 (JSC::::parseAssignmentExpression): 45 * parser/Parser.h: 46 (JSC::Scope::declareParameter): 47 * parser/SyntaxChecker.h: 48 (JSC::SyntaxChecker::createFormalParameterList): 49 (JSC::SyntaxChecker::createForInLoop): 50 (JSC::SyntaxChecker::operatorStackPop): 51 * runtime/JSONObject.cpp: 52 * runtime/JSONObject.h: 53 1 54 2013-09-26 Anders Carlsson <andersca@apple.com> 2 55 -
trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp
r156482 r156497 184 184 if (!builder.isEmpty()) 185 185 builder.appendLiteral(", "); 186 parameters.at(pos)->toString(builder);186 builder.append(parameters.at(pos).string()); 187 187 } 188 188 return builder.toString(); -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r156482 r156497 181 181 182 182 for (size_t i = 0; i < varStack.size(); ++i) 183 codeBlock->addVariableDeclaration( varStack[i].first, !!(varStack[i].second & DeclarationStacks::IsConstant));183 codeBlock->addVariableDeclaration(*varStack[i].first, !!(varStack[i].second & DeclarationStacks::IsConstant)); 184 184 185 185 } … … 216 216 217 217 m_symbolTable->setUsesNonStrictEval(codeBlock->usesEval() && !codeBlock->isStrictMode()); 218 Vector<Identifier> boundParameterProperties;219 FunctionParameters& parameters = *functionBody->parameters();220 for (size_t i = 0; i < parameters.size(); i++) {221 auto pattern = parameters.at(i);222 if (pattern->isBindingNode())223 continue;224 pattern->collectBoundIdentifiers(boundParameterProperties);225 continue;226 }227 218 m_symbolTable->setParameterCountIncludingThis(functionBody->parameters()->size() + 1); 228 219 … … 264 255 for (size_t i = 0; i < parameters.size(); ++i) { 265 256 capturedArguments[i] = 0; 266 auto pattern = parameters.at(i); 267 if (!pattern->isBindingNode()) 268 continue; 269 const Identifier& ident = static_cast<const BindingNode*>(pattern)->boundProperty(); 270 if (!functionBody->captures(ident) && !shouldCaptureAllTheThings) 257 if (!functionBody->captures(parameters.at(i)) && !shouldCaptureAllTheThings) 271 258 continue; 272 259 capturesAnyArgumentByName = true; … … 313 300 } 314 301 for (size_t i = 0; i < varStack.size(); ++i) { 315 const Identifier& ident = varStack[i].first;302 const Identifier& ident = *varStack[i].first; 316 303 if (functionBody->captures(ident)) 317 304 addVar(ident, varStack[i].second & DeclarationStacks::IsConstant); … … 346 333 m_lastLazyFunction = canLazilyCreateFunctions ? codeBlock->m_numVars : m_firstLazyFunction; 347 334 for (size_t i = 0; i < varStack.size(); ++i) { 348 const Identifier& ident = varStack[i].first;335 const Identifier& ident = *varStack[i].first; 349 336 if (!functionBody->captures(ident)) 350 337 addVar(ident, varStack[i].second & DeclarationStacks::IsConstant); … … 354 341 m_symbolTable->setCaptureEnd(localToOperand(codeBlock->m_numVars)); 355 342 343 FunctionParameters& parameters = *functionBody->parameters(); 356 344 m_parameters.grow(parameters.size() + 1); // reserve space for "this" 357 345 … … 360 348 m_thisRegister.setIndex(nextParameterIndex++); 361 349 m_codeBlock->addParameter(); 362 Vector<std::pair<RegisterID*, const DeconstructionPatternNode*>> deconstructedParameters;350 363 351 for (size_t i = 0; i < parameters.size(); ++i, ++nextParameterIndex) { 364 352 int index = nextParameterIndex; 365 auto pattern = parameters.at(i);366 if (!pattern->isBindingNode()) {367 m_codeBlock->addParameter();368 RegisterID& parameter = registerFor(index);369 parameter.setIndex(index);370 deconstructedParameters.append(make_pair(¶meter, pattern));371 continue;372 }373 auto simpleParameter = static_cast<const BindingNode*>(pattern);374 353 if (capturedArguments.size() && capturedArguments[i]) { 375 ASSERT((functionBody->hasCapturedVariables() && functionBody->captures( simpleParameter->boundProperty())) || shouldCaptureAllTheThings);354 ASSERT((functionBody->hasCapturedVariables() && functionBody->captures(parameters.at(i))) || shouldCaptureAllTheThings); 376 355 index = capturedArguments[i]->index(); 377 356 RegisterID original(nextParameterIndex); 378 357 emitMove(capturedArguments[i], &original); 379 358 } 380 addParameter( simpleParameter->boundProperty(), index);359 addParameter(parameters.at(i), index); 381 360 } 382 361 preserveLastVar(); … … 391 370 instructions().append(kill(&m_thisRegister)); 392 371 instructions().append(0); 393 }394 for (size_t i = 0; i < deconstructedParameters.size(); i++) {395 auto& entry = deconstructedParameters[i];396 entry.second->emitBytecode(*this, entry.first);397 372 } 398 373 } … … 440 415 Vector<Identifier, 0, UnsafeVectorOverflow> variables; 441 416 variables.reserveCapacity(numVariables); 442 for (size_t i = 0; i < numVariables; ++i) { 443 ASSERT(varStack[i].first.impl()->isIdentifier()); 444 variables.append(varStack[i].first); 445 } 417 for (size_t i = 0; i < numVariables; ++i) 418 variables.append(*varStack[i].first); 446 419 codeBlock->adoptVariables(variables); 447 420 preserveLastVar(); -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r156482 r156497 287 287 else 288 288 lineStart = 0; 289 290 if (divotOffset < lineStart) 291 return; 292 289 ASSERT(divotOffset >= lineStart); 293 290 unsigned column = divotOffset - lineStart; 294 291 -
trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
r156464 r156497 36 36 #include "JSGlobalObject.h" 37 37 #include "JSNameScope.h" 38 #include "JSONObject.h"39 38 #include "LabelScope.h" 40 39 #include "Lexer.h" … … 1715 1714 generator.emitExpressionInfo(assignNode->divot(), assignNode->divotStart(), assignNode->divotEnd()); 1716 1715 generator.emitPutById(base, ident, propertyName); 1717 } else if (m_lexpr->isBracketAccessorNode()) { 1716 } else { 1717 ASSERT(m_lexpr->isBracketAccessorNode()); 1718 1718 BracketAccessorNode* assignNode = static_cast<BracketAccessorNode*>(m_lexpr); 1719 1719 propertyName = generator.newTemporary(); … … 1724 1724 generator.emitExpressionInfo(assignNode->divot(), assignNode->divotStart(), assignNode->divotEnd()); 1725 1725 generator.emitPutByVal(base.get(), subscript, propertyName); 1726 } else { 1727 ASSERT(m_lexpr->isDeconstructionNode()); 1728 DeconstructingAssignmentNode* assignNode = static_cast<DeconstructingAssignmentNode*>(m_lexpr); 1729 propertyName = generator.newTemporary(); 1730 RefPtr<RegisterID> protect(propertyName); 1731 assignNode->bindings()->emitBytecode(generator, propertyName); 1732 } 1726 } 1733 1727 1734 1728 generator.emitNode(dst, m_statement); … … 2186 2180 return generator.emitNewFunctionExpression(generator.finalDestination(dst), this); 2187 2181 } 2188 2189 // ------------------------------ DeconstructingAssignmentNode -----------------2190 RegisterID* DeconstructingAssignmentNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst)2191 {2192 if (RegisterID* result = m_bindings->emitDirectBinding(generator, dst, m_initializer))2193 return result;2194 RefPtr<RegisterID> initializer = generator.tempDestination(dst);2195 generator.emitNode(initializer.get(), m_initializer);2196 m_bindings->emitBytecode(generator, initializer.get());2197 return generator.moveToDestinationIfNeeded(dst, initializer.get());2198 }2199 2200 DeconstructionPatternNode::~DeconstructionPatternNode()2201 {2202 }2203 2204 void ArrayPatternNode::emitBytecode(BytecodeGenerator& generator, RegisterID* rhs) const2205 {2206 for (size_t i = 0; i < m_targetPatterns.size(); i++) {2207 auto target = m_targetPatterns[i];2208 if (!target)2209 continue;2210 RefPtr<RegisterID> temp = generator.newTemporary();2211 generator.emitLoad(temp.get(), jsNumber(i));2212 generator.emitGetByVal(temp.get(), rhs, temp.get());2213 target->emitBytecode(generator, temp.get());2214 }2215 }2216 2217 RegisterID* ArrayPatternNode::emitDirectBinding(BytecodeGenerator& generator, RegisterID* dst, ExpressionNode* rhs)2218 {2219 if (rhs->isResolveNode()2220 && generator.willResolveToArguments(static_cast<ResolveNode*>(rhs)->identifier())2221 && !generator.symbolTable().slowArguments()) {2222 for (size_t i = 0; i < m_targetPatterns.size(); i++) {2223 auto target = m_targetPatterns[i];2224 if (!target)2225 continue;2226 2227 RefPtr<RegisterID> temp = generator.newTemporary();2228 generator.emitLoad(temp.get(), jsNumber(i));2229 generator.emitGetArgumentByVal(generator.finalDestination(dst), generator.uncheckedRegisterForArguments(), temp.get());2230 target->emitBytecode(generator, temp.get());2231 }2232 }2233 if (!rhs->isSimpleArray())2234 return 0;2235 ElementNode* elementNodes = static_cast<ArrayNode*>(rhs)->elements();2236 Vector<ExpressionNode*> elements;2237 for (; elementNodes; elementNodes = elementNodes->next())2238 elements.append(elementNodes->value());2239 if (m_targetPatterns.size() != elements.size())2240 return 0;2241 Vector<RefPtr<RegisterID>> registers;2242 registers.reserveCapacity(m_targetPatterns.size());2243 for (size_t i = 0; i < m_targetPatterns.size(); i++) {2244 registers.uncheckedAppend(generator.newTemporary());2245 generator.emitNode(registers.last().get(), elements[i]);2246 }2247 2248 for (size_t i = 0; i < m_targetPatterns.size(); i++) {2249 if (m_targetPatterns[i])2250 m_targetPatterns[i]->emitBytecode(generator, registers[i].get());2251 }2252 RefPtr<RegisterID> result = generator.finalDestination(dst);2253 return generator.emitLoad(result.get(), jsUndefined());2254 }2255 2256 void ArrayPatternNode::toString(StringBuilder& builder) const2257 {2258 builder.append('[');2259 for (size_t i = 0; i < m_targetPatterns.size(); i++) {2260 if (!m_targetPatterns[i]) {2261 builder.append(',');2262 continue;2263 }2264 m_targetPatterns[i]->toString(builder);2265 if (i < m_targetPatterns.size() - 1)2266 builder.append(',');2267 }2268 builder.append(']');2269 }2270 2271 void ArrayPatternNode::collectBoundIdentifiers(Vector<Identifier>& identifiers) const2272 {2273 for (size_t i = 0; i < m_targetPatterns.size(); i++) {2274 if (DeconstructionPatternNode* node = m_targetPatterns[i].get())2275 node->collectBoundIdentifiers(identifiers);2276 }2277 }2278 2279 void ObjectPatternNode::toString(StringBuilder& builder) const2280 {2281 builder.append('{');2282 for (size_t i = 0; i < m_targetPatterns.size(); i++) {2283 if (m_targetPatterns[i].wasString) {2284 builder.append('"');2285 escapeStringToBuilder(builder, m_targetPatterns[i].propertyName.string());2286 builder.append('"');2287 } else2288 builder.append(m_targetPatterns[i].propertyName.string());2289 builder.append(":");2290 m_targetPatterns[i].pattern->toString(builder);2291 if (i < m_targetPatterns.size() - 1)2292 builder.append(',');2293 }2294 builder.append('}');2295 }2296 2297 void ObjectPatternNode::emitBytecode(BytecodeGenerator& generator, RegisterID* rhs) const2298 {2299 for (size_t i = 0; i < m_targetPatterns.size(); i++) {2300 auto& target = m_targetPatterns[i];2301 RefPtr<RegisterID> temp = generator.newTemporary();2302 generator.emitGetById(temp.get(), rhs, target.propertyName);2303 target.pattern->emitBytecode(generator, temp.get());2304 }2305 }2306 2307 void ObjectPatternNode::collectBoundIdentifiers(Vector<Identifier>& identifiers) const2308 {2309 for (size_t i = 0; i < m_targetPatterns.size(); i++)2310 m_targetPatterns[i].pattern->collectBoundIdentifiers(identifiers);2311 }2312 2313 void BindingNode::emitBytecode(BytecodeGenerator& generator, RegisterID* value) const2314 {2315 if (Local local = generator.local(m_boundProperty)) {2316 if (local.isReadOnly()) {2317 generator.emitReadOnlyExceptionIfNeeded();2318 return;2319 }2320 generator.emitMove(local.get(), value);2321 return;2322 }2323 if (generator.isStrictMode())2324 generator.emitExpressionInfo(divot(), divotStart(), divotEnd());2325 RegisterID* scope = generator.emitResolveScope(generator.newTemporary(), m_boundProperty);2326 generator.emitExpressionInfo(divot(), divotStart(), divotEnd());2327 generator.emitPutToScope(scope, m_boundProperty, value, generator.isStrictMode() ? ThrowIfNotFound : DoNotThrowIfNotFound);2328 return;2329 }2330 2331 void BindingNode::toString(StringBuilder& builder) const2332 {2333 builder.append(m_boundProperty.string());2334 }2335 2336 void BindingNode::collectBoundIdentifiers(Vector<Identifier>& identifiers) const2337 {2338 identifiers.append(m_boundProperty);2339 }2340 2182 2341 2183 } // namespace JSC -
trunk/Source/JavaScriptCore/parser/ASTBuilder.h
r156464 r156497 91 91 }; 92 92 93 94 93 typedef SyntaxChecker FunctionBodyBuilder; 95 94 … … 109 108 typedef ConstDeclNode* ConstDeclList; 110 109 typedef std::pair<ExpressionNode*, BinaryOpInfo> BinaryOperand; 111 typedef RefPtr<DeconstructionPatternNode> DeconstructionPattern; 112 typedef RefPtr<ArrayPatternNode> ArrayPattern; 113 typedef RefPtr<ObjectPatternNode> ObjectPattern; 114 typedef RefPtr<BindingNode> BindingPattern; 110 115 111 static const bool CreatesAST = true; 116 112 static const bool NeedsFreeVariableInfo = true; … … 319 315 ElementNode* createElementList(ElementNode* elems, int elisions, ExpressionNode* expr) { return new (m_vm) ElementNode(elems, elisions, expr); } 320 316 321 ParameterNode* createFormalParameterList( DeconstructionPattern pattern) { return new (m_vm) ParameterNode(pattern); }322 ParameterNode* createFormalParameterList(ParameterNode* list, DeconstructionPattern pattern) { return new (m_vm) ParameterNode(list, pattern); }317 ParameterNode* createFormalParameterList(const Identifier& ident) { return new (m_vm) ParameterNode(ident); } 318 ParameterNode* createFormalParameterList(ParameterNode* list, const Identifier& ident) { return new (m_vm) ParameterNode(list, ident); } 323 319 324 320 CaseClauseNode* createClause(ExpressionNode* expr, JSC::SourceElements* statements) { return new (m_vm) CaseClauseNode(expr, statements); } … … 366 362 } 367 363 364 StatementNode* createForInLoop(const JSTokenLocation& location, const Identifier* ident, ExpressionNode* iter, StatementNode* statements, const JSTextPosition& start, const JSTextPosition& divot, const JSTextPosition& end, int startLine, int endLine) 365 { 366 ForInNode* result = new (m_vm) ForInNode(m_vm, location, *ident, iter, statements, start); 367 result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); 368 setExceptionLocation(result, start, divot + 1, end); 369 return result; 370 } 371 368 372 StatementNode* createForInLoop(const JSTokenLocation& location, ExpressionNode* lhs, ExpressionNode* iter, StatementNode* statements, const JSTextPosition& eStart, const JSTextPosition& eDivot, const JSTextPosition& eEnd, int start, int end) 369 373 { 370 374 ForInNode* result = new (m_vm) ForInNode(location, lhs, iter, statements); 371 result->setLoc(start, end, location.startOffset, location.lineStartOffset);372 setExceptionLocation(result, eStart, eDivot, eEnd);373 return result;374 }375 376 StatementNode* createForInLoop(const JSTokenLocation& location, PassRefPtr<DeconstructionPatternNode> pattern, ExpressionNode* iter, StatementNode* statements, const JSTextPosition& eStart, const JSTextPosition& eDivot, const JSTextPosition& eEnd, int start, int end)377 {378 ForInNode* result = new (m_vm) ForInNode(m_vm, location, pattern.get(), iter, statements);379 375 result->setLoc(start, end, location.startOffset, location.lineStartOffset); 380 376 setExceptionLocation(result, eStart, eDivot, eEnd); … … 520 516 if (m_vm->propertyNames->arguments == *ident) 521 517 usesArguments(); 522 ASSERT(ident->impl()->isIdentifier()); 523 m_scope.m_varDeclarations->data.append(std::make_pair(*ident, attrs)); 518 m_scope.m_varDeclarations->data.append(std::make_pair(ident, attrs)); 524 519 } 525 520 … … 621 616 bool isResolve(ExpressionNode* expr) const { return expr->isResolveNode(); } 622 617 623 ExpressionNode* createDeconstructingAssignment(const JSTokenLocation& location, PassRefPtr<DeconstructionPatternNode> pattern, ExpressionNode* initializer)624 {625 return new (m_vm) DeconstructingAssignmentNode(location, pattern.get(), initializer);626 }627 628 ArrayPattern createArrayPattern(const JSTokenLocation&)629 {630 return ArrayPatternNode::create(m_vm);631 }632 633 void appendArrayPatternSkipEntry(ArrayPattern node, const JSTokenLocation& location)634 {635 node->appendIndex(location, 0);636 }637 638 void appendArrayPatternEntry(ArrayPattern node, const JSTokenLocation& location, DeconstructionPattern pattern)639 {640 node->appendIndex(location, pattern.get());641 }642 643 ObjectPattern createObjectPattern(const JSTokenLocation&)644 {645 return ObjectPatternNode::create(m_vm);646 }647 648 void appendObjectPatternEntry(ObjectPattern node, const JSTokenLocation& location, bool wasString, const Identifier& identifier, DeconstructionPattern pattern)649 {650 node->appendEntry(location, identifier, wasString, pattern.get());651 }652 653 BindingPattern createBindingLocation(const JSTokenLocation&, const Identifier& boundProperty, const JSTextPosition& divot, const JSTextPosition& start, const JSTextPosition& end)654 {655 return BindingNode::create(m_vm, boundProperty, divot, start, end);656 }657 658 618 private: 659 619 struct Scope { -
trunk/Source/JavaScriptCore/parser/NodeConstructors.h
r156464 r156497 604 604 : ExpressionNode(location) 605 605 { 606 ASSERT(expr1);607 ASSERT(expr2);608 606 m_expressions.append(expr1); 609 607 m_expressions.append(expr2); … … 735 733 } 736 734 737 inline ParameterNode::ParameterNode( PassRefPtr<DeconstructionPatternNode> pattern)738 : m_ pattern(pattern)735 inline ParameterNode::ParameterNode(const Identifier& ident) 736 : m_ident(ident) 739 737 , m_next(0) 740 738 { 741 ASSERT(m_pattern); 742 } 743 744 inline ParameterNode::ParameterNode(ParameterNode* l, PassRefPtr<DeconstructionPatternNode> pattern) 745 : m_pattern(pattern) 739 } 740 741 inline ParameterNode::ParameterNode(ParameterNode* l, const Identifier& ident) 742 : m_ident(ident) 746 743 , m_next(0) 747 744 { 748 745 l->m_next = this; 749 ASSERT(m_pattern);750 ASSERT(l->m_pattern);751 746 } 752 747 … … 818 813 , m_statement(statement) 819 814 { 820 ASSERT(l); 821 } 822 823 inline ForInNode::ForInNode(VM* vm, const JSTokenLocation& location, DeconstructionPatternNode* pattern, ExpressionNode* expr, StatementNode* statement) 824 : StatementNode(location) 825 , m_lexpr(new (vm) DeconstructingAssignmentNode(location, pattern, 0)) 815 } 816 817 inline ForInNode::ForInNode(VM* vm, const JSTokenLocation& location, const Identifier& ident, ExpressionNode* expr, StatementNode* statement, const JSTextPosition& divotStart) 818 : StatementNode(location) 819 , m_lexpr(new (vm) ResolveNode(location, ident, divotStart)) 826 820 , m_expr(expr) 827 821 , m_statement(statement) 828 822 { 829 ASSERT(pattern); 830 } 831 832 inline DeconstructionPatternNode::DeconstructionPatternNode(VM*) 833 { 834 } 835 836 inline ArrayPatternNode::ArrayPatternNode(VM* vm) 837 : DeconstructionPatternNode(vm) 838 { 839 } 840 841 inline PassRefPtr<ArrayPatternNode> ArrayPatternNode::create(VM* vm) 842 { 843 return adoptRef(new ArrayPatternNode(vm)); 844 } 845 846 inline ObjectPatternNode::ObjectPatternNode(VM* vm) 847 : DeconstructionPatternNode(vm) 848 { 849 } 850 851 inline PassRefPtr<ObjectPatternNode> ObjectPatternNode::create(VM* vm) 852 { 853 return adoptRef(new ObjectPatternNode(vm)); 854 } 855 856 inline PassRefPtr<BindingNode> BindingNode::create(VM* vm, const Identifier& boundProperty, const JSTextPosition& divot, const JSTextPosition& start, const JSTextPosition& end) 857 { 858 return adoptRef(new BindingNode(vm, boundProperty, divot, start, end)); 859 } 860 861 inline BindingNode::BindingNode(VM* vm, const Identifier& boundProperty, const JSTextPosition& divot, const JSTextPosition& start, const JSTextPosition& end) 862 : DeconstructionPatternNode(vm) 863 , ThrowableExpressionData(divot, start, end) 864 , m_boundProperty(boundProperty) 865 { 866 } 867 868 inline DeconstructingAssignmentNode::DeconstructingAssignmentNode(const JSTokenLocation& location, PassRefPtr<DeconstructionPatternNode> bindings, ExpressionNode* initializer) 869 : ExpressionNode(location) 870 , m_bindings(bindings) 871 , m_initializer(initializer) 872 { 873 } 874 823 } 824 875 825 } // namespace JSC 876 826 -
trunk/Source/JavaScriptCore/parser/Nodes.cpp
r156464 r156497 158 158 ++parameterCount; 159 159 160 size_t objectSize = sizeof(FunctionParameters) - sizeof(void*) + sizeof( DeconstructionPatternNode*) * parameterCount;160 size_t objectSize = sizeof(FunctionParameters) - sizeof(void*) + sizeof(StringImpl*) * parameterCount; 161 161 void* slot = fastMalloc(objectSize); 162 162 return adoptRef(new (slot) FunctionParameters(firstParameter, parameterCount)); … … 167 167 { 168 168 unsigned i = 0; 169 for (ParameterNode* parameter = firstParameter; parameter; parameter = parameter->nextParam()) { 170 auto pattern = parameter->pattern(); 171 pattern->ref(); 172 patterns()[i++] = pattern; 173 } 169 for (ParameterNode* parameter = firstParameter; parameter; parameter = parameter->nextParam()) 170 new (&identifiers()[i++]) Identifier(parameter->ident()); 174 171 } 175 172 … … 177 174 { 178 175 for (unsigned i = 0; i < m_size; ++i) 179 patterns()[i]->deref();176 identifiers()[i].~Identifier(); 180 177 } 181 178 -
trunk/Source/JavaScriptCore/parser/Nodes.h
r156464 r156497 81 81 namespace DeclarationStacks { 82 82 enum VarAttrs { IsConstant = 1, HasInitializer = 2 }; 83 typedef Vector<std::pair< Identifier, unsigned> > VarStack;83 typedef Vector<std::pair<const Identifier*, unsigned> > VarStack; 84 84 typedef Vector<FunctionBodyNode*> FunctionStack; 85 85 } … … 155 155 virtual bool isBracketAccessorNode() const { return false; } 156 156 virtual bool isDotAccessorNode() const { return false; } 157 virtual bool isDeconstructionNode() const { return false; }158 157 virtual bool isFuncExprNode() const { return false; } 159 158 virtual bool isCommaNode() const { return false; } … … 463 462 ArgumentListNode* toArgumentList(VM*, int, int) const; 464 463 465 ElementNode* elements() const { ASSERT(isSimpleArray()); return m_element; }466 464 private: 467 465 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); … … 1083 1081 using ParserArenaDeletable::operator new; 1084 1082 1085 void append(ExpressionNode* expr) { ASSERT(expr);m_expressions.append(expr); }1083 void append(ExpressionNode* expr) { m_expressions.append(expr); } 1086 1084 1087 1085 private: … … 1241 1239 StatementNode* m_statement; 1242 1240 }; 1243 1244 class DeconstructionPatternNode;1245 1241 1246 1242 class ForInNode : public StatementNode, public ThrowableExpressionData { 1247 1243 public: 1248 1244 ForInNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*); 1249 ForInNode(VM*, const JSTokenLocation&, DeconstructionPatternNode*, ExpressionNode*, StatementNode*);1245 ForInNode(VM*, const JSTokenLocation&, const Identifier&, ExpressionNode*, StatementNode*, const JSTextPosition& divotStart); 1250 1246 1251 1247 private: … … 1346 1342 class ParameterNode : public ParserArenaFreeable { 1347 1343 public: 1348 ParameterNode( PassRefPtr<DeconstructionPatternNode>);1349 ParameterNode(ParameterNode*, PassRefPtr<DeconstructionPatternNode>);1350 1351 DeconstructionPatternNode* pattern() const { return m_pattern.get(); }1344 ParameterNode(const Identifier&); 1345 ParameterNode(ParameterNode*, const Identifier&); 1346 1347 const Identifier& ident() const { return m_ident; } 1352 1348 ParameterNode* nextParam() const { return m_next; } 1353 1349 1354 1350 private: 1355 RefPtr<DeconstructionPatternNode> m_pattern;1351 const Identifier& m_ident; 1356 1352 ParameterNode* m_next; 1357 1353 }; … … 1465 1461 class FunctionParameters : public RefCounted<FunctionParameters> { 1466 1462 WTF_MAKE_FAST_ALLOCATED; 1467 WTF_MAKE_NONCOPYABLE(FunctionParameters);1468 1463 public: 1469 1464 static PassRefPtr<FunctionParameters> create(ParameterNode*); … … 1471 1466 1472 1467 unsigned size() const { return m_size; } 1473 DeconstructionPatternNode* at(unsigned index) { ASSERT(index < m_size); return patterns()[index]; }1468 const Identifier& at(unsigned index) const { ASSERT(index < m_size); return identifiers()[index]; } 1474 1469 1475 1470 private: 1476 1471 FunctionParameters(ParameterNode*, unsigned size); 1477 1472 1478 DeconstructionPatternNode** patterns() { return &m_storage; } 1473 Identifier* identifiers() { return reinterpret_cast<Identifier*>(&m_storage); } 1474 const Identifier* identifiers() const { return reinterpret_cast<const Identifier*>(&m_storage); } 1479 1475 1480 1476 unsigned m_size; 1481 DeconstructionPatternNode* m_storage;1477 void* m_storage; 1482 1478 }; 1483 1479 … … 1535 1531 }; 1536 1532 1537 class DeconstructionPatternNode : public RefCounted<DeconstructionPatternNode> {1538 WTF_MAKE_NONCOPYABLE(DeconstructionPatternNode);1539 WTF_MAKE_FAST_ALLOCATED;1540 1541 public:1542 virtual void collectBoundIdentifiers(Vector<Identifier>&) const = 0;1543 virtual void emitBytecode(BytecodeGenerator&, RegisterID* source) const = 0;1544 virtual void toString(StringBuilder&) const = 0;1545 1546 virtual bool isBindingNode() const { return false; }1547 virtual RegisterID* emitDirectBinding(BytecodeGenerator&, RegisterID*, ExpressionNode*) { return 0; }1548 1549 virtual ~DeconstructionPatternNode() = 0;1550 1551 protected:1552 DeconstructionPatternNode(VM*);1553 };1554 1555 class ArrayPatternNode : public DeconstructionPatternNode {1556 public:1557 static PassRefPtr<ArrayPatternNode> create(VM*);1558 void appendIndex(const JSTokenLocation&, DeconstructionPatternNode* node)1559 {1560 m_targetPatterns.append(node);1561 }1562 1563 private:1564 ArrayPatternNode(VM*);1565 void collectBoundIdentifiers(Vector<Identifier>&) const;1566 void emitBytecode(BytecodeGenerator&, RegisterID*) const;1567 RegisterID* emitDirectBinding(BytecodeGenerator&, RegisterID* dst, ExpressionNode*);1568 void toString(StringBuilder&) const;1569 1570 Vector<RefPtr<DeconstructionPatternNode>> m_targetPatterns;1571 };1572 1573 class ObjectPatternNode : public DeconstructionPatternNode {1574 public:1575 static PassRefPtr<ObjectPatternNode> create(VM*);1576 void appendEntry(const JSTokenLocation&, const Identifier& identifier, bool wasString, DeconstructionPatternNode* pattern)1577 {1578 m_targetPatterns.append(Entry(identifier, wasString, pattern));1579 }1580 1581 private:1582 ObjectPatternNode(VM*);1583 void collectBoundIdentifiers(Vector<Identifier>&) const;1584 void emitBytecode(BytecodeGenerator&, RegisterID*) const;1585 void toString(StringBuilder&) const;1586 struct Entry {1587 Entry(const Identifier& propertyName, bool wasString, DeconstructionPatternNode* pattern)1588 : propertyName(propertyName)1589 , wasString(wasString)1590 , pattern(pattern)1591 {1592 }1593 Identifier propertyName;1594 bool wasString;1595 RefPtr<DeconstructionPatternNode> pattern;1596 };1597 Vector<Entry> m_targetPatterns;1598 };1599 1600 class BindingNode : public DeconstructionPatternNode, ThrowableExpressionData {1601 public:1602 static PassRefPtr<BindingNode> create(VM*, const Identifier& boundProperty, const JSTextPosition& divot, const JSTextPosition& start, const JSTextPosition& end);1603 const Identifier& boundProperty() const { return m_boundProperty; }1604 1605 private:1606 BindingNode(VM*, const Identifier& boundProperty, const JSTextPosition& divot, const JSTextPosition& start, const JSTextPosition& end);1607 1608 void collectBoundIdentifiers(Vector<Identifier>&) const;1609 void emitBytecode(BytecodeGenerator&, RegisterID*) const;1610 void toString(StringBuilder&) const;1611 1612 virtual bool isBindingNode() const { return true; }1613 1614 Identifier m_boundProperty;1615 };1616 1617 class DeconstructingAssignmentNode : public ExpressionNode {1618 public:1619 DeconstructingAssignmentNode(const JSTokenLocation&, PassRefPtr<DeconstructionPatternNode>, ExpressionNode*);1620 DeconstructionPatternNode* bindings() { return m_bindings.get(); }1621 1622 private:1623 virtual bool isLocation() const { return true; }1624 virtual bool isDeconstructionNode() const { return true; }1625 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);1626 1627 RefPtr<DeconstructionPatternNode> m_bindings;1628 ExpressionNode* m_initializer;1629 };1630 1631 1533 class FuncDeclNode : public StatementNode { 1632 1534 public: -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r156492 r156497 85 85 m_token.m_location.endOffset = source.startOffset(); 86 86 m_token.m_location.lineStartOffset = source.startOffset(); 87 87 88 m_functionCache = vm->addSourceProviderCache(source.provider()); 88 89 ScopeRef scope = pushScope(); … … 92 93 scope->setStrictMode(); 93 94 if (parameters) { 94 for (unsigned i = 0; i < parameters->size(); i++) { 95 auto parameter = parameters->at(i); 96 if (!parameter->isBindingNode()) 97 continue; 98 scope->declareParameter(&static_cast<BindingNode*>(parameter)->boundProperty()); 99 } 95 for (unsigned i = 0; i < parameters->size(); i++) 96 scope->declareParameter(¶meters->at(i)); 100 97 } 101 98 if (!name.isNull()) … … 207 204 int end = 0; 208 205 int scratch; 209 TreeDeconstructionPatternscratch1 = 0;206 const Identifier* scratch1 = 0; 210 207 TreeExpression scratch2 = 0; 211 208 JSTextPosition scratch3; … … 275 272 276 273 template <typename LexerType> 277 template <class TreeBuilder> TreeExpression Parser<LexerType>::parseVarDeclarationList(TreeBuilder& context, int& declarations, TreeDeconstructionPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd)274 template <class TreeBuilder> TreeExpression Parser<LexerType>::parseVarDeclarationList(TreeBuilder& context, int& declarations, const Identifier*& lastIdent, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd) 278 275 { 279 276 TreeExpression varDecls = 0; 280 const Identifier* lastIdent;281 277 do { 282 lastIdent = 0; 283 lastPattern = 0; 278 declarations++; 284 279 JSTokenLocation location(tokenLocation()); 285 280 next(); 286 TreeExpression node = 0; 287 declarations++; 288 bool hasInitializer = false; 289 if (match(IDENT)) { 290 JSTextPosition varStart = tokenStartPosition(); 291 identStart = varStart; 292 const Identifier* name = m_token.m_data.ident; 293 lastIdent = name; 294 next(); 295 hasInitializer = match(EQUAL); 296 failIfFalseIfStrictWithNameAndMessage(declareVariable(name), "Cannot declare a variable named", name->impl(), "in strict mode."); 297 context.addVar(name, (hasInitializer || (!m_allowsIn && match(INTOKEN))) ? DeclarationStacks::HasInitializer : 0); 298 if (hasInitializer) { 299 JSTextPosition varDivot = tokenStartPosition() + 1; 300 initStart = tokenStartPosition(); 301 next(TreeBuilder::DontBuildStrings); // consume '=' 302 TreeExpression initializer = parseAssignmentExpression(context); 303 initEnd = lastTokenEndPosition(); 304 lastInitializer = initializer; 305 failIfFalse(initializer); 306 307 node = context.createAssignResolve(location, *name, initializer, varStart, varDivot, lastTokenEndPosition()); 308 } 309 } else { 310 lastIdent = 0; 311 auto pattern = parseDeconstructionPattern<DeconstructToVariables>(context); 312 failIfFalse(pattern); 313 hasInitializer = match(EQUAL); 314 lastPattern = pattern; 315 if (hasInitializer) { 316 next(TreeBuilder::DontBuildStrings); // consume '=' 317 TreeExpression rhs = parseExpression(context); 318 node = context.createDeconstructingAssignment(location, pattern, rhs); 319 } 320 ASSERT(node); 321 } 322 281 matchOrFail(IDENT); 282 283 JSTextPosition varStart = tokenStartPosition(); 284 identStart = varStart; 285 const Identifier* name = m_token.m_data.ident; 286 lastIdent = name; 287 next(); 288 bool hasInitializer = match(EQUAL); 289 failIfFalseIfStrictWithNameAndMessage(declareVariable(name), "Cannot declare a variable named", name->impl(), "in strict mode."); 290 context.addVar(name, (hasInitializer || (!m_allowsIn && match(INTOKEN))) ? DeclarationStacks::HasInitializer : 0); 323 291 if (hasInitializer) { 292 JSTextPosition varDivot = tokenStartPosition() + 1; 293 initStart = tokenStartPosition(); 294 next(TreeBuilder::DontBuildStrings); // consume '=' 295 TreeExpression initializer = parseAssignmentExpression(context); 296 initEnd = lastTokenEndPosition(); 297 lastInitializer = initializer; 298 failIfFalse(initializer); 299 300 TreeExpression node = context.createAssignResolve(location, *name, initializer, varStart, varDivot, lastTokenEndPosition()); 324 301 if (!varDecls) 325 302 varDecls = node; … … 328 305 } 329 306 } while (match(COMMA)); 330 if (lastIdent)331 lastPattern = createBindingPattern<DeconstructToVariables>(context, *lastIdent, 0);332 307 return varDecls; 333 }334 335 template <typename LexerType>336 template <DeconstructionKind kind, class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, const Identifier& name, int depth)337 {338 ASSERT(!name.isEmpty());339 ASSERT(!name.isNull());340 341 ASSERT(name.impl()->isIdentifier());342 if (depth) {343 if (kind == DeconstructToVariables)344 failIfFalseIfStrictWithNameAndMessage(declareVariable(&name), "Cannot deconstruct to a variable named", name.impl(), ".");345 if (kind == DeconstructToParameters) {346 auto bindingResult = declareBoundParameter(&name);347 failIfFalseIfStrictWithNameAndMessage(bindingResult != Scope::StrictBindingFailed, "Cannot deconstruct to a parameter named", name.impl(), "in strict mode.");348 failIfFalseWithNameAndMessage(bindingResult != Scope::BindingFailed, "Cannot deconstruct to a parameter named", name.impl(), ".");349 }350 context.addVar(&name, kind == DeconstructToParameters ? 0 : DeclarationStacks::HasInitializer);351 } else {352 if (kind == DeconstructToVariables) {353 failIfFalseIfStrictWithNameAndMessage(declareVariable(&name), "Cannot declare a variable named", name.impl(), "in strict mode.");354 context.addVar(&name, DeclarationStacks::HasInitializer);355 }356 357 if (kind == DeconstructToParameters)358 failIfFalseIfStrictWithNameAndMessage(declareParameter(&name), "Cannot declare a parameter named", name.impl(), "in strict mode.");359 }360 return context.createBindingLocation(m_token.m_location, name, m_token.m_endPosition, m_token.m_startPosition, m_token.m_endPosition);361 }362 363 template <typename LexerType>364 template <DeconstructionKind kind, class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::parseDeconstructionPattern(TreeBuilder& context, int depth)365 {366 failIfStackOverflow();367 int nonLHSCount = m_nonLHSCount;368 TreeDeconstructionPattern pattern;369 switch (m_token.m_type) {370 case OPENBRACKET: {371 auto arrayPattern = context.createArrayPattern(m_token.m_location);372 next();373 do {374 while (match(COMMA)) {375 context.appendArrayPatternSkipEntry(arrayPattern, m_token.m_location);376 next();377 }378 failIfTrue(hasError());379 JSTokenLocation location = m_token.m_location;380 auto innerPattern = parseDeconstructionPattern<kind>(context, depth + 1);381 failIfFalse(innerPattern);382 context.appendArrayPatternEntry(arrayPattern, location, innerPattern);383 } while (consume(COMMA));384 consumeOrFail(CLOSEBRACKET);385 pattern = arrayPattern;386 break;387 }388 case OPENBRACE: {389 next();390 auto objectPattern = context.createObjectPattern(m_token.m_location);391 bool wasString = false;392 do {393 Identifier propertyName;394 TreeDeconstructionPattern innerPattern = 0;395 JSTokenLocation location = m_token.m_location;396 if (match(IDENT)) {397 propertyName = *m_token.m_data.ident;398 next();399 if (consume(COLON))400 innerPattern = parseDeconstructionPattern<kind>(context, depth + 1);401 else402 innerPattern = createBindingPattern<kind>(context, propertyName, depth);403 } else {404 switch (m_token.m_type) {405 case NUMBER:406 propertyName = Identifier::from(m_vm, m_token.m_data.doubleValue);407 break;408 case STRING:409 propertyName = *m_token.m_data.ident;410 wasString = true;411 break;412 default:413 failIfTrue(!(m_token.m_type & KeywordTokenFlag));414 propertyName = *m_token.m_data.ident;415 break;416 }417 next();418 consumeOrFail(COLON);419 innerPattern = parseDeconstructionPattern<kind>(context, depth + 1);420 }421 failIfFalse(innerPattern);422 context.appendObjectPatternEntry(objectPattern, location, wasString, propertyName, innerPattern);423 } while (consume(COMMA));424 consumeOrFail(CLOSEBRACE);425 pattern = objectPattern;426 break;427 }428 429 default: {430 matchOrFail(IDENT);431 pattern = createBindingPattern<kind>(context, *m_token.m_data.ident, depth);432 next();433 break;434 }435 }436 m_nonLHSCount = nonLHSCount;437 return pattern;438 308 } 439 309 … … 482 352 /* 483 353 for (var IDENT in expression) statement 354 for (var IDENT = expression in expression) statement 484 355 for (var varDeclarationList; expressionOpt; expressionOpt) 485 356 */ 486 TreeDeconstructionPatternforInTarget = 0;357 const Identifier* forInTarget = 0; 487 358 TreeExpression forInInitializer = 0; 488 359 m_allowsIn = false; … … 499 370 failIfFalse(declarations == 1); 500 371 failIfTrueWithMessage(forInInitializer, "Cannot use initialiser syntax in a for-in loop"); 501 372 502 373 // Handle for-in with var declaration 503 374 JSTextPosition inLocation = tokenStartPosition(); … … 516 387 endLoop(); 517 388 failIfFalse(statement); 389 518 390 return context.createForInLoop(location, forInTarget, expr, statement, declsStart, inLocation, exprEnd, startLine, endLine); 519 391 } … … 901 773 template <class TreeBuilder> TreeFormalParameterList Parser<LexerType>::parseFormalParameters(TreeBuilder& context) 902 774 { 903 auto parameter = parseDeconstructionPattern<DeconstructToParameters>(context);904 failIfFalse (parameter);905 TreeFormalParameterList list = context.createFormalParameterList( parameter);775 matchOrFail(IDENT); 776 failIfFalseIfStrictWithNameAndMessage(declareParameter(m_token.m_data.ident), "Cannot declare a parameter named", m_token.m_data.ident->impl(), " in strict mode"); 777 TreeFormalParameterList list = context.createFormalParameterList(*m_token.m_data.ident); 906 778 TreeFormalParameterList tail = list; 907 while (consume(COMMA)) { 908 parameter = parseDeconstructionPattern<DeconstructToParameters>(context); 909 failIfFalse(parameter); 910 tail = context.createFormalParameterList(tail, parameter); 779 next(); 780 while (match(COMMA)) { 781 next(); 782 matchOrFail(IDENT); 783 const Identifier* ident = m_token.m_data.ident; 784 failIfFalseIfStrictWithNameAndMessage(declareParameter(ident), "Cannot declare a parameter named", ident->impl(), "in strict mode"); 785 next(); 786 tail = context.createFormalParameterList(tail, *ident); 911 787 } 912 788 return list; … … 1280 1156 m_lastIdentifier = 0; 1281 1157 } 1282 lhs = parse AssignmentExpression(context);1158 lhs = parseConditionalExpression(context); 1283 1159 failIfFalse(lhs); 1284 1160 if (initialNonLHSCount != m_nonLHSCount) -
trunk/Source/JavaScriptCore/parser/Parser.h
r156480 r156497 74 74 #define TreeProperty typename TreeBuilder::Property 75 75 #define TreePropertyList typename TreeBuilder::PropertyList 76 #define TreeDeconstructionPattern typename TreeBuilder::DeconstructionPattern77 76 78 77 COMPILE_ASSERT(LastUntaggedToken < 64, LessThan64UntaggedTokens); … … 80 79 enum SourceElementsMode { CheckForStrictMode, DontCheckForStrictMode }; 81 80 enum FunctionRequirements { FunctionNoRequirements, FunctionNeedsName }; 82 enum DeconstructionKind {83 DeconstructToVariables,84 DeconstructToParameters,85 DeconstructToExpressions86 };87 81 88 82 template <typename T> inline bool isEvalNode() { return false; } … … 230 224 return isValidStrictMode; 231 225 } 232 233 enum BindingResult {234 BindingFailed,235 StrictBindingFailed,236 BindingSucceeded237 };238 BindingResult declareBoundParameter(const Identifier* ident)239 {240 bool isArguments = m_vm->propertyNames->arguments == *ident;241 bool newEntry = m_declaredVariables.add(ident->string().impl()).isNewEntry;242 bool isValidStrictMode = newEntry && m_vm->propertyNames->eval != *ident && !isArguments;243 m_isValidStrictMode = m_isValidStrictMode && isValidStrictMode;244 245 if (isArguments)246 m_shadowsArguments = true;247 if (!newEntry)248 return BindingFailed;249 return isValidStrictMode ? BindingSucceeded : StrictBindingFailed;250 }251 252 226 253 227 void useVariable(const Identifier* ident, bool isEval) … … 883 857 bool isValidStrictMode() { return currentScope()->isValidStrictMode(); } 884 858 bool declareParameter(const Identifier* ident) { return currentScope()->declareParameter(ident); } 885 Scope::BindingResult declareBoundParameter(const Identifier* ident) { return currentScope()->declareBoundParameter(ident); }886 859 bool breakIsValid() 887 860 { … … 954 927 template <class TreeBuilder> ALWAYS_INLINE TreeFunctionBody parseFunctionBody(TreeBuilder&); 955 928 template <class TreeBuilder> ALWAYS_INLINE TreeFormalParameterList parseFormalParameters(TreeBuilder&); 956 template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseVarDeclarationList(TreeBuilder&, int& declarations, TreeDeconstructionPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd); 957 template <class TreeBuilder> ALWAYS_INLINE TreeConstDeclList parseConstDeclarationList(TreeBuilder&); 958 959 template <DeconstructionKind, class TreeBuilder> ALWAYS_INLINE TreeDeconstructionPattern createBindingPattern(TreeBuilder&, const Identifier&, int depth); 960 template <DeconstructionKind, class TreeBuilder> ALWAYS_INLINE TreeDeconstructionPattern parseDeconstructionPattern(TreeBuilder&, int depth = 0); 929 template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseVarDeclarationList(TreeBuilder&, int& declarations, const Identifier*& lastIdent, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd); 930 template <class TreeBuilder> ALWAYS_INLINE TreeConstDeclList parseConstDeclarationList(TreeBuilder& context); 961 931 template <FunctionRequirements, bool nameIsInContainingScope, class TreeBuilder> bool parseFunctionInfo(TreeBuilder&, const Identifier*&, TreeFormalParameterList&, TreeFunctionBody&, unsigned& openBraceOffset, unsigned& closeBraceOffset, int& bodyStartLine, unsigned& bodyStartColumn); 962 932 ALWAYS_INLINE int isBinaryOperator(JSTokenType); -
trunk/Source/JavaScriptCore/parser/SyntaxChecker.h
r156464 r156497 112 112 typedef int ConstDeclList; 113 113 typedef int BinaryOperand; 114 typedef int DeconstructionPattern; 115 typedef int ArrayPattern; 116 typedef int ObjectPattern; 117 114 118 115 static const bool CreatesAST = false; 119 116 static const bool NeedsFreeVariableInfo = false; … … 177 174 int createElementList(int, int) { return 1; } 178 175 int createElementList(int, int, int) { return 1; } 179 int createFormalParameterList( DeconstructionPattern) { return 1; }180 int createFormalParameterList(int, DeconstructionPattern) { return 1; }176 int createFormalParameterList(const Identifier&) { return 1; } 177 int createFormalParameterList(int, const Identifier&) { return 1; } 181 178 int createClause(int, int) { return 1; } 182 179 int createClauseList(int) { return 1; } … … 189 186 int createIfStatement(const JSTokenLocation&, int, int, int, int, int) { return 1; } 190 187 int createForLoop(const JSTokenLocation&, int, int, int, int, int, int) { return 1; } 188 int createForInLoop(const JSTokenLocation&, const Identifier*, int, int, int, int, int, int, int) { return 1; } 191 189 int createForInLoop(const JSTokenLocation&, int, int, int, int, int, int, int, int) { return 1; } 192 190 int createEmptyStatement(const JSTokenLocation&) { return 1; } … … 253 251 PropertyNode::Type getType(const Property& property) const { return property.type; } 254 252 bool isResolve(ExpressionType expr) const { return expr == ResolveExpr || expr == ResolveEvalExpr; } 255 ExpressionType createDeconstructingAssignment(const JSTokenLocation&, int, ExpressionType) 256 { 257 return 1; 258 } 259 260 ArrayPattern createArrayPattern(const JSTokenLocation&) 261 { 262 return 1; 263 } 264 void appendArrayPatternSkipEntry(ArrayPattern, const JSTokenLocation&) 265 { 266 } 267 void appendArrayPatternEntry(ArrayPattern, const JSTokenLocation&, DeconstructionPattern) 268 { 269 } 270 ObjectPattern createObjectPattern(const JSTokenLocation&) 271 { 272 return 1; 273 } 274 void appendObjectPatternEntry(ArrayPattern, const JSTokenLocation&, bool, const Identifier&, DeconstructionPattern) 275 { 276 } 277 DeconstructionPattern createBindingLocation(const JSTokenLocation&, const Identifier&, const JSTextPosition&, const JSTextPosition&, const JSTextPosition&) 278 { 279 return 1; 280 } 253 281 254 private: 282 255 int m_topBinaryExpr; -
trunk/Source/JavaScriptCore/runtime/JSONObject.cpp
r156464 r156497 303 303 } 304 304 } 305 306 void escapeStringToBuilder(StringBuilder& builder, const String& message) 307 { 308 if (message.is8Bit()) 309 appendStringToStringBuilder(builder, message.characters8(), message.length()); 310 else 311 appendStringToStringBuilder(builder, message.characters16(), message.length()); 312 } 313 305 314 306 void Stringifier::appendQuotedString(StringBuilder& builder, const String& value) 315 307 { -
trunk/Source/JavaScriptCore/runtime/JSONObject.h
r156464 r156497 64 64 String JSONStringify(ExecState*, JSValue, unsigned indent); 65 65 66 void escapeStringToBuilder(StringBuilder&, const String&);67 68 66 } // namespace JSC 69 67
Note: See TracChangeset
for help on using the changeset viewer.