From e0e9bcff466b3cbb2cec920702e29f028b4a2cb7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 7 Jul 2015 17:44:22 -0700 Subject: [PATCH] Don't call push.apply, it can stack overflow with large arrays. --- src/compiler/checker.ts | 2 +- src/services/navigationBar.ts | 4 ++-- src/services/services.ts | 22 +++++++++++----------- src/services/signatureHelp.ts | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ef2c6ada2a..e8ac59449d9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3305,7 +3305,7 @@ namespace ts { let declarations: Declaration[] = []; for (let prop of props) { if (prop.declarations) { - declarations.push.apply(declarations, prop.declarations); + addRange(declarations, prop.declarations); } propTypes.push(getTypeOfSymbol(prop)); } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index ead9bc519ce..e822052a5b2 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -228,7 +228,7 @@ namespace ts.NavigationBar { function merge(target: ts.NavigationBarItem, source: ts.NavigationBarItem) { // First, add any spans in the source to the target. - target.spans.push.apply(target.spans, source.spans); + addRange(target.spans, source.spans); if (source.childItems) { if (!target.childItems) { @@ -465,7 +465,7 @@ namespace ts.NavigationBar { // are not properties will be filtered out later by createChildItem. let nodes: Node[] = removeDynamicallyNamedProperties(node); if (constructor) { - nodes.push.apply(nodes, filter(constructor.parameters, p => !isBindingPattern(p.name))); + addRange(nodes, filter(constructor.parameters, p => !isBindingPattern(p.name))); } childItems = getItemsWorker(sortNodes(nodes), createChildItem); diff --git a/src/services/services.ts b/src/services/services.ts index 9996a2ac5fa..fe4f376cbdf 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -345,7 +345,7 @@ namespace ts { ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), jsDocCommentTextRange => { let cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedParamJsDocComment) { - jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment); + addRange(jsDocCommentParts, cleanedParamJsDocComment); } }); } @@ -365,7 +365,7 @@ namespace ts { declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => { let cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedJsDocComment) { - jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); + addRange(jsDocCommentParts, cleanedJsDocComment); } }); } @@ -3812,7 +3812,7 @@ namespace ts { displayParts.push(spacePart()); } if (!(type.flags & TypeFlags.Anonymous)) { - displayParts.push.apply(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)); + addRange(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)); } addSignatureDisplayParts(signature, allSignatures, TypeFormatFlags.WriteArrowStyleSignature); break; @@ -3873,7 +3873,7 @@ namespace ts { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); - displayParts.push.apply(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); + addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } if (symbolFlags & SymbolFlags.Enum) { addNewLineIfDisplayPartsExist(); @@ -3919,7 +3919,7 @@ namespace ts { else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) { addFullSymbolName(signatureDeclaration.symbol); } - displayParts.push.apply(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature)); + addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature)); } } if (symbolFlags & SymbolFlags.EnumMember) { @@ -3980,10 +3980,10 @@ namespace ts { let typeParameterParts = mapToDisplayParts(writer => { typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); }); - displayParts.push.apply(displayParts, typeParameterParts); + addRange(displayParts, typeParameterParts); } else { - displayParts.push.apply(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration)); + addRange(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration)); } } else if (symbolFlags & SymbolFlags.Function || @@ -4017,7 +4017,7 @@ namespace ts { function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) { let fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing); - displayParts.push.apply(displayParts, fullSymbolDisplayParts); + addRange(displayParts, fullSymbolDisplayParts); } function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) { @@ -4047,7 +4047,7 @@ namespace ts { } function addSignatureDisplayParts(signature: Signature, allSignatures: Signature[], flags?: TypeFormatFlags) { - displayParts.push.apply(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature)); + addRange(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature)); if (allSignatures.length > 1) { displayParts.push(spacePart()); displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); @@ -4064,7 +4064,7 @@ namespace ts { let typeParameterParts = mapToDisplayParts(writer => { typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); }); - displayParts.push.apply(displayParts, typeParameterParts); + addRange(displayParts, typeParameterParts); } } @@ -5578,7 +5578,7 @@ namespace ts { // type to the search set if (isNameOfPropertyAssignment(location)) { forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => { - result.push.apply(result, typeChecker.getRootSymbols(contextualSymbol)); + addRange(result, typeChecker.getRootSymbols(contextualSymbol)); }); /* Because in short-hand property assignment, location has two meaning : property name and as value of the property diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 44b022a7b12..f44ebade2a7 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -550,7 +550,7 @@ namespace ts.SignatureHelp { let suffixDisplayParts: SymbolDisplayPart[] = []; if (callTargetDisplayParts) { - prefixDisplayParts.push.apply(prefixDisplayParts, callTargetDisplayParts); + addRange(prefixDisplayParts, callTargetDisplayParts); } if (isTypeParameterList) { @@ -560,12 +560,12 @@ namespace ts.SignatureHelp { suffixDisplayParts.push(punctuationPart(SyntaxKind.GreaterThanToken)); let parameterParts = mapToDisplayParts(writer => typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation)); - suffixDisplayParts.push.apply(suffixDisplayParts, parameterParts); + addRange(suffixDisplayParts, parameterParts); } else { let typeParameterParts = mapToDisplayParts(writer => typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation)); - prefixDisplayParts.push.apply(prefixDisplayParts, typeParameterParts); + addRange(prefixDisplayParts, typeParameterParts); prefixDisplayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); let parameters = candidateSignature.parameters; @@ -575,7 +575,7 @@ namespace ts.SignatureHelp { let returnTypeParts = mapToDisplayParts(writer => typeChecker.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation)); - suffixDisplayParts.push.apply(suffixDisplayParts, returnTypeParts); + addRange(suffixDisplayParts, returnTypeParts); return { isVariadic: candidateSignature.hasRestParameter,