Skip to content

Commit

Permalink
mark all internal properties as non-enumerable (close DevExpress#1182,
Browse files Browse the repository at this point in the history
…DevExpress#1209) (DevExpress#1206)

* mark all internal properties as non-enumerable (close DevExpress#1182)

* fix tests
  • Loading branch information
miherlosev authored and AndreyBelym committed Feb 28, 2019
1 parent ec301a5 commit 13d0a6a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/client/sandbox/event/listening-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function addListeningElement (el, events) {
}

if (!isElementListening(el))
el[ELEMENT_LISTENING_EVENTS_STORAGE_PROP] = elementCtx;
Object.defineProperty(el, ELEMENT_LISTENING_EVENTS_STORAGE_PROP, { value: elementCtx, writable: true });
}

export function removeListeningElement (el) {
Expand Down
5 changes: 4 additions & 1 deletion src/client/sandbox/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export default class NodeSandbox extends SandboxBase {
urlAttrName = el.hasAttribute(urlAttrName) ? urlAttrName : null;
}

el[INTERNAL_PROPS.processedContext] = this.window;
Object.defineProperty(el, INTERNAL_PROPS.processedContext, {
value: this.window,
writable: true
});

// NOTE: We need to reprocess url attribute of element, if it's moved to different window (GH-564)
if (urlAttrName)
Expand Down
4 changes: 2 additions & 2 deletions src/client/sandbox/windows-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function getStorage () {
let storage = topSameDomainWindow[WINDOWS_STORAGE];

if (!storage) {
storage = [];
topSameDomainWindow[WINDOWS_STORAGE] = storage;
storage = [];
Object.defineProperty(topSameDomainWindow, WINDOWS_STORAGE, { value: storage });
}

return storage;
Expand Down
4 changes: 2 additions & 2 deletions src/client/utils/url-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
// we will use native methods from an actual document.
// However, a document that contains an element for url resolving is created using a previous version of nativeMethods.
if (!doc[DOCUMENT_URL_RESOLVER])
doc[DOCUMENT_URL_RESOLVER] = this._createResolver(doc);
Object.defineProperty(doc, DOCUMENT_URL_RESOLVER, { value: this._createResolver(doc), writable: true });

return doc[DOCUMENT_URL_RESOLVER];
},
Expand Down Expand Up @@ -83,7 +83,7 @@ export default {
},

changeUrlPart (url, prop, value, doc) {
const resolver = this.getResolverElement(doc);
const resolver = this.getResolverElement(doc);

resolver.href = url;
resolver[prop] = value;
Expand Down
4 changes: 2 additions & 2 deletions test/client/fixtures/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ QUnit.testDone(function () {
module('regression');

asyncTest('should prevent navigation from the about:blank page to the relative url (GH-645)', function () {
var iframe = document.createElement('iframe');
var handler = function () {
var iframe = document.createElement('iframe');
var handler = function () {
var iframeHammerhead = iframe.contentWindow['%hammerhead%'];
var timeoutId = null;
var finalize = function () {
Expand Down
31 changes: 31 additions & 0 deletions test/client/fixtures/common-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
test('mark all internal properties as non-enumerable (GH-1182)', function () {
var documentEnumerableProperties = Object.keys(document);
var windowEnumerableProperties = Object.keys(window);
var elementEnumerableProperties = Object.keys(document.body);
var hasEnumerableInternalProperty = function (propName) {
// Used for tests
if (propName === 'hammerhead')
return false;

return propName.indexOf('hammerhead') !== -1;
};

for (var i = 0; i < documentEnumerableProperties.length; i++) {
var documentEnumerableProperty = documentEnumerableProperties[i];

ok(!hasEnumerableInternalProperty(documentEnumerableProperty), documentEnumerableProperty);
}

for (var j = 0; j < windowEnumerableProperties.length; j++) {
var windowEnumerableProperty = windowEnumerableProperties[j];

ok(!hasEnumerableInternalProperty(windowEnumerableProperty), windowEnumerableProperty);
}

for (var k = 0; k < elementEnumerableProperties.length; k++) {
var elementEnumerableProperty = elementEnumerableProperties[k];

ok(!hasEnumerableInternalProperty(elementEnumerableProperty), elementEnumerableProperty);
}
});

0 comments on commit 13d0a6a

Please sign in to comment.