Skip to content

Commit

Permalink
Switch bulk Object.defineProperties to seperate Object.defineProperty…
Browse files Browse the repository at this point in the history
… calls, to make IE happy; with Object.defineProperties, event.target always returning null even directly after setting it to a non-null value
  • Loading branch information
jonoward committed Jun 18, 2015
1 parent 79a80f0 commit 8de489c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/media/eme_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ shaka.media.EmeManager.prototype.onSessionMessage_ = function(event) {
shaka.log.info('onSessionMessage_', event);
shaka.asserts.assert(this.drmScheme_);
this.requestLicense_(
event.target || event.customTarget,
event.target,
/** @type {!shaka.player.DrmSchemeInfo} */ (this.drmScheme_),
event.message);
};
Expand Down
27 changes: 18 additions & 9 deletions lib/util/fake_event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,28 @@ shaka.util.FakeEventTarget.prototype.removeEventListener =
*/
shaka.util.FakeEventTarget.prototype.dispatchEvent = function(event) {
// Overwrite the Event's properties. Assignment doesn't work in most
// browsers. Object.defineProperties seems to work, although some browsers
// browsers. Object.defineProperty seems to work, although some browsers
// need the original properties deleted first.
delete event.srcElement;
delete event.target;
delete event.currentTarget;
Object.defineProperties(event, {
'srcElement': { 'value': null, 'writable': true },
// target may be set many times if an event is re-dispatched.
'target': { 'value': this, 'writable': true },
// Dupe of target prop, as browsers like IE do not allow this to be redefined, even if CustomEvent is deleted from window.
'customTarget': { 'value': this, 'writable': true },
// currentTarget will be set many times by recursiveDispatch_().
'currentTarget': { 'value': null, 'writable': true }

var srcElement_ = null;
Object.defineProperty(event, "srcElement", {
get: function () { return srcElement_; },
set: function (value) { srcElement_ = value; }
});

var target_ = this;
Object.defineProperty(event, "target", {
get: function () { return target_; },
set: function (value) { target_ = value; }
});

var currentTarget_ = null;
Object.defineProperty(event, "currentTarget", {
get: function () { return currentTarget_; },
set: function (value) { currentTarget_ = value; }
});

return this.recursiveDispatch_(event);
Expand Down

0 comments on commit 8de489c

Please sign in to comment.