Skip to content

Commit

Permalink
Don't leak modifications to the global object
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Sep 9, 2018
1 parent e6b29f5 commit 06e504b
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
// Pretend that `Reflect.construct` isn't supported.
this.Reflect = undefined;
const oldReflect = this.Reflect;
const oldHTMLElement = this.HTMLElement;

this.HTMLElement = function() {
// Here, `this.HTMLElement` is this function, not the original HTMLElement
// constructor. `this.constructor` should be this function too, but isn't.
constructor = this.constructor;
};
try {
// Pretend that `Reflect.construct` isn't supported.
this.Reflect = undefined;

var constructor;
this.HTMLElement = function() {
// Here, `this.HTMLElement` is this function, not the original HTMLElement
// constructor. `this.constructor` should be this function too, but isn't.
constructor = this.constructor;
};

class CustomElement extends HTMLElement {};
new CustomElement();
var constructor;

expect(constructor).toBe(CustomElement);
class CustomElement extends HTMLElement {};
new CustomElement();

expect(constructor).toBe(CustomElement);
} finally {
// Restore original env
this.Reflect = oldReflect;
this.HTMLElement = oldHTMLElement;
}


0 comments on commit 06e504b

Please sign in to comment.