Skip to content

Commit

Permalink
Save the native "value" property setter of HTMLInputElement.prototype (
Browse files Browse the repository at this point in the history
…close DevExpress#1185)
  • Loading branch information
LavrovArtem committed Jun 23, 2017
1 parent dd3c3a4 commit ae27e0e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/client/sandbox/native-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ class NativeMethods {
if (win.DOMParser)
this.DOMParserParseFromString = win.DOMParser.prototype.parseFromString;

// Setters
var inputValueDescriptor = win.Object.getOwnPropertyDescriptor(win.HTMLInputElement.prototype, 'value');
var textAreaValueDescriptor = win.Object.getOwnPropertyDescriptor(win.HTMLTextAreaElement.prototype, 'value');

if (inputValueDescriptor && typeof inputValueDescriptor.set === 'function')
this.inputValueSetter = inputValueDescriptor.set;

if (textAreaValueDescriptor && typeof textAreaValueDescriptor.set === 'function')
this.textAreaValueSetter = textAreaValueDescriptor.set;

this.refreshClasses(win);
}

Expand Down
30 changes: 30 additions & 0 deletions test/client/fixtures/sandbox/native-methods-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,33 @@ if (nativeMethods.performanceNow) {
ok(!isNaN(parseFloat(now)));
});
}

if (nativeMethods.inputValueSetter) {
test("set element's value with native setter", function () {
var input = document.createElement('input');
var inputValueGetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').get;
var textArea = document.createElement('textarea');
var textAreaValueGetter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value').get;
var testNativeValueSetter = function (el, setter, getter) {
Object.defineProperty(el, 'value', {
get: function () {
return getter.call(el);
},
set: function (value) {
return value;
}
});

el.value = '123';

strictEqual(el.value, '');

setter.call(el, '123');

strictEqual(el.value, '123');
};

testNativeValueSetter(input, nativeMethods.inputValueSetter, inputValueGetter);
testNativeValueSetter(textArea, nativeMethods.textAreaValueSetter, textAreaValueGetter);
});
}

0 comments on commit ae27e0e

Please sign in to comment.