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 Jan 1, 2020
1 parent 3a7f89f commit 139e2a1
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 139e2a1

Please sign in to comment.