From be5e8d5733c1c012d7e3a6c7e049b59d67c13978 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 26 Sep 2016 07:17:52 +0300 Subject: [PATCH] Fixes #12122: Use Object.prototype.hasOwnProperty when building up the diff hash table --- src/vs/base/common/diff/diff.ts | 6 ++++-- src/vs/editor/test/common/diff/diffComputer.test.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/vs/base/common/diff/diff.ts b/src/vs/base/common/diff/diff.ts index 3fceba4c974..7f98094c4bb 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 fe8850102ad..192bbc4e5c2 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); + }); }); -- GitLab