Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #307 from arv/black-list-property-names
Browse files Browse the repository at this point in the history
Add way to blacklist certain instance properties
  • Loading branch information
Steve Orvell committed Nov 18, 2013
2 parents 8fb30dc + 0fc629e commit abdd777
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,39 @@ window.ShadowDOMPolyfill = {};
function() { return this.impl[name].apply(this.impl, arguments); };
}

function installProperty(source, target, allowMethod) {
getOwnPropertyNames(source).forEach(function(name) {
function getDescriptor(source, name) {
try {
return Object.getOwnPropertyDescriptor(source, name);
} catch (ex) {
// JSC and V8 both use data properties instead of accessors which can
// cause getting the property desciptor to throw an exception.
// https://bugs.webkit.org/show_bug.cgi?id=49739
return dummyDescriptor;
}
}

function installProperty(source, target, allowMethod, opt_blacklist) {
var names = getOwnPropertyNames(source);
for (var i = 0; i < names.length; i++) {
var name = names[i];
if (name === 'polymerBlackList_')
continue;

if (name in target)
return;
continue;

if (source.polymerBlackList_ && source.polymerBlackList_[name])
continue;

if (isFirefox) {
// Tickle Firefox's old bindings.
source.__lookupGetter__(name);
}
var descriptor;
try {
descriptor = getOwnPropertyDescriptor(source, name);
} catch (ex) {
// JSC and V8 both use data properties instead of accessors which can
// cause getting the property desciptor to throw an exception.
// https://bugs.webkit.org/show_bug.cgi?id=49739
descriptor = dummyDescriptor;
}
var descriptor = getDescriptor(source, name);
var getter, setter;
if (allowMethod && typeof descriptor.value === 'function') {
target[name] = getMethod(name);
return;
continue;
}

var isEvent = isEventHandlerName(name);
Expand All @@ -172,7 +183,7 @@ window.ShadowDOMPolyfill = {};
configurable: descriptor.configurable,
enumerable: descriptor.enumerable
});
});
}
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/wrappers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
};

var OriginalEvent = window.Event;
OriginalEvent.prototype.polymerBlackList_ = {returnValue: true};

/**
* Creates a new Event wrapper or wraps an existin native Event object.
Expand Down Expand Up @@ -563,6 +564,19 @@
configureEventConstructor('FocusEvent', {relatedTarget: null}, 'UIEvent');
}

function BeforeUnloadEvent(impl) {
Event.call(this);
}
BeforeUnloadEvent.prototype = Object.create(Event.prototype);
mixin(BeforeUnloadEvent.prototype, {
get returnValue() {
return this.impl.returnValue;
},
set returnValue(v) {
this.impl.returnValue = v;
}
});

function isValidListener(fun) {
if (typeof fun === 'function')
return true;
Expand Down Expand Up @@ -736,6 +750,7 @@
scope.muteMutationEvents = muteMutationEvents;
scope.unmuteMutationEvents = unmuteMutationEvents;
scope.wrapEventTargetMethods = wrapEventTargetMethods;
scope.wrappers.BeforeUnloadEvent = BeforeUnloadEvent;
scope.wrappers.CustomEvent = CustomEvent;
scope.wrappers.Event = Event;
scope.wrappers.EventTarget = EventTarget;
Expand Down
5 changes: 5 additions & 0 deletions test/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -1328,4 +1328,9 @@ test('retarget order (multiple shadow roots)', function() {
assert.equal(count, 1);
});

test('returnValue', function() {
var e = new Event('x');
assert.isFalse('returnValue' in e);
});

});

0 comments on commit abdd777

Please sign in to comment.