提交 be5e8d57 编写于 作者: A Alex Dima

Fixes #12122: Use Object.prototype.hasOwnProperty when building up the diff hash table

上级 db88c318
...@@ -211,6 +211,8 @@ class DiffChangeHelper { ...@@ -211,6 +211,8 @@ class DiffChangeHelper {
} }
const hasOwnProperty = Object.prototype.hasOwnProperty;
/** /**
* An implementation of the difference algorithm described in * An implementation of the difference algorithm described in
* "An O(ND) Difference Algorithm and its letiations" by Eugene W. Myers * "An O(ND) Difference Algorithm and its letiations" by Eugene W. Myers
...@@ -257,7 +259,7 @@ export class LcsDiff { ...@@ -257,7 +259,7 @@ export class LcsDiff {
// Fill up the hash table for unique elements // Fill up the hash table for unique elements
for (i = 0; i < originalSequenceLength; i++) { for (i = 0; i < originalSequenceLength; i++) {
let originalElementHash = this.OriginalSequence.getElementHash(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. // No entry in the hashtable so this is a new unique element.
// Assign the element a new unique identifier and add it to the // Assign the element a new unique identifier and add it to the
// hash table // hash table
...@@ -271,7 +273,7 @@ export class LcsDiff { ...@@ -271,7 +273,7 @@ export class LcsDiff {
// Now match up modified elements // Now match up modified elements
for (i = 0; i < modifiedSequenceLength; i++) { for (i = 0; i < modifiedSequenceLength; i++) {
let modifiedElementHash = this.ModifiedSequence.getElementHash(i); let modifiedElementHash = this.ModifiedSequence.getElementHash(i);
if (!hashTable.hasOwnProperty(modifiedElementHash)) { if (!hasOwnProperty.call(hashTable, modifiedElementHash)) {
this.m_modifiedIds[i] = currentUniqueId++; this.m_modifiedIds[i] = currentUniqueId++;
hashTable[modifiedElementHash] = this.m_modifiedIds[i]; hashTable[modifiedElementHash] = this.m_modifiedIds[i];
} else { } else {
......
...@@ -394,4 +394,13 @@ suite('Editor Diff - DiffComputer', () => { ...@@ -394,4 +394,13 @@ suite('Editor Diff - DiffComputer', () => {
]; ];
assertDiff(original, modified, expected, false, true); 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);
});
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册