Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call push.apply, it can stack overflow with large arrays. #3778

Merged
merged 1 commit into from
Jul 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/navigationBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand All @@ -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);
}
});
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -3980,10 +3980,10 @@ namespace ts {
let typeParameterParts = mapToDisplayParts(writer => {
typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(<TypeParameter>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 ||
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand All @@ -4064,7 +4064,7 @@ namespace ts {
let typeParameterParts = mapToDisplayParts(writer => {
typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration);
});
displayParts.push.apply(displayParts, typeParameterParts);
addRange(displayParts, typeParameterParts);
}
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/services/signatureHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ namespace ts.SignatureHelp {
let suffixDisplayParts: SymbolDisplayPart[] = [];

if (callTargetDisplayParts) {
prefixDisplayParts.push.apply(prefixDisplayParts, callTargetDisplayParts);
addRange(prefixDisplayParts, callTargetDisplayParts);
}

if (isTypeParameterList) {
Expand All @@ -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;
Expand All @@ -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,
Expand Down