diff --git a/src/vs/base/common/diff/diff.ts b/src/vs/base/common/diff/diff.ts index 3fceba4c97414c0a1688fe24e91b7d717a87748c..7f98094c4bbdeef4764ede3d5b4bdcd39cc1a250 100644 --- a/src/vs/base/common/diff/diff.ts +++ b/src/vs/base/common/diff/diff.ts @@ -211,6 +211,8 @@ class DiffChangeHelper { } +const hasOwnProperty = Object.prototype.hasOwnProperty; + /** * An implementation of the difference algorithm described in * "An O(ND) Difference Algorithm and its letiations" by Eugene W. Myers @@ -257,7 +259,7 @@ export class LcsDiff { // Fill up the hash table for unique elements for (i = 0; i < originalSequenceLength; i++) { let originalElementHash = this.OriginalSequence.getElementHash(i); - if (!hashTable.hasOwnProperty(originalElementHash)) { + if (!hasOwnProperty.call(hashTable, originalElementHash)) { // No entry in the hashtable so this is a new unique element. // Assign the element a new unique identifier and add it to the // hash table @@ -271,7 +273,7 @@ export class LcsDiff { // Now match up modified elements for (i = 0; i < modifiedSequenceLength; i++) { let modifiedElementHash = this.ModifiedSequence.getElementHash(i); - if (!hashTable.hasOwnProperty(modifiedElementHash)) { + if (!hasOwnProperty.call(hashTable, modifiedElementHash)) { this.m_modifiedIds[i] = currentUniqueId++; hashTable[modifiedElementHash] = this.m_modifiedIds[i]; } else { diff --git a/src/vs/editor/test/common/diff/diffComputer.test.ts b/src/vs/editor/test/common/diff/diffComputer.test.ts index fe8850102ad441aed202bd1921f31aad8c17f6e4..192bbc4e5c266a77ed4caec256f8beee1d858a5c 100644 --- a/src/vs/editor/test/common/diff/diffComputer.test.ts +++ b/src/vs/editor/test/common/diff/diffComputer.test.ts @@ -394,4 +394,13 @@ suite('Editor Diff - DiffComputer', () => { ]; assertDiff(original, modified, expected, false, true); }); + + test('issue #12122 r.hasOwnProperty is not a function', () => { + var original = [ 'hasOwnProperty' ]; + var modified = [ 'hasOwnProperty', 'and another line' ]; + var expected = [ + createLineInsertion(2, 2, 1) + ]; + assertDiff(original, modified, expected); + }); });