Merge branch 'master' into fixes-70

Conflicts:
	src/ShadowDOM/wrappers/DOMTokenList.js
This commit is contained in:
Toru Nagashima
2014-12-18 13:59:38 +09:00
19 changed files with 76 additions and 67 deletions

View File

@@ -13,7 +13,7 @@
var useNative = scope.useNative;
var initializeModules = scope.initializeModules;
var isIE = /Trident/.test(navigator.userAgent);
var isIE11OrOlder = /Trident/.test(navigator.userAgent);
// If native, setup stub api and bail.
// NOTE: we fire `WebComponentsReady` under native for api compatibility
@@ -87,9 +87,9 @@ function bootstrap() {
});
}
// CustomEvent shim for IE
// NOTE: we explicitly test for IE since Safari has an type `object` CustomEvent
if (isIE && (typeof window.CustomEvent !== 'function')) {
// CustomEvent shim for IE <= 11
// NOTE: we explicitly test for IE since Safari has a type `object` CustomEvent
if (isIE11OrOlder && (typeof window.CustomEvent !== 'function')) {
window.CustomEvent = function(inType, params) {
params = params || {};
var e = document.createEvent('CustomEvent');

View File

@@ -84,7 +84,11 @@ Loader.prototype = {
fetch: function(url, elt) {
flags.load && console.log('fetch', url, elt);
if (url.match(/^data:/)) {
if (!url) {
setTimeout(function() {
this.receive(url, elt, {error: 'href must be specified'}, null);
}.bind(this), 0);
} else if (url.match(/^data:/)) {
// Handle Data URI Scheme
var pieces = url.split(',');
var header = pieces[0];

View File

@@ -70,7 +70,7 @@ Object.defineProperty(rootDocument, '_currentScript', currentScriptDescriptor);
the polyfill and native implementation.
*/
var isIE = /Trident/.test(navigator.userAgent);
var isIE = /Trident|Edge/.test(navigator.userAgent);
// call a callback when all HTMLImports in the document at call time
// (or at least document ready) have loaded.
@@ -214,9 +214,9 @@ if (useNative) {
whenReady(function() {
HTMLImports.ready = true;
HTMLImports.readyTime = new Date().getTime();
rootDocument.dispatchEvent(
new CustomEvent('HTMLImportsLoaded', {bubbles: true})
);
var evt = rootDocument.createEvent("CustomEvent");
evt.initCustomEvent("HTMLImportsLoaded", true, true, {});
rootDocument.dispatchEvent(evt);
});
// exports

View File

@@ -22,7 +22,7 @@ var importer = scope.importer;
var dynamic = {
// process (load/parse) any nodes added to imported documents.
added: function(nodes) {
var owner, parsed;
var owner, parsed, loading;
for (var i=0, l=nodes.length, n; (i<l) && (n=nodes[i]); i++) {
if (!owner) {
owner = n.ownerDocument;

View File

@@ -129,7 +129,8 @@ function makeDocument(resource, url) {
base.setAttribute('href', url);
// add baseURI support to browsers (IE) that lack it.
if (!doc.baseURI) {
doc.baseURI = url;
// Use defineProperty since Safari throws an exception when using assignment.
Object.defineProperty(doc, 'baseURI', {value:url});
}
// ensure UTF-8 charset
var meta = doc.createElement('meta');

View File

@@ -12,7 +12,7 @@ HTMLImports.addModule(function(scope) {
/*
xhr processor.
*/
xhr = {
var xhr = {
async: true,
ok: function(request) {

View File

@@ -20,7 +20,7 @@
//
// For a thorough discussion on this, see:
// http://codeforhire.com/2013/09/21/setimmediate-and-messagechannel-broken-on-internet-explorer-10/
if (/Trident/.test(navigator.userAgent)) {
if (/Trident|Edge/.test(navigator.userAgent)) {
// Sadly, this bug also affects postMessage and MessageQueues.
//
// We would like to use the onreadystatechange hack for IE <= 10, but it is

View File

@@ -8,65 +8,60 @@
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// NOTE: Set the 'ownerElement_' property on a DOMTokenList to make invalidation
// happen. This is pretty hacky but we only have to do it in one place
// (Element.js) currently so it seems like the least bad option.
(function(scope) {
'use strict';
var setWrapper = scope.setWrapper;
var unsafeUnwrap = scope.unsafeUnwrap;
var enqueueMutation = scope.enqueueMutation;
function invalidateClass(el) {
scope.invalidateRendererBasedOnAttribute(el, 'class');
function getClass (el) {
return unsafeUnwrap(el).getAttribute('class');
}
function enqueueClassAttributeChange(element, oldValue) {
enqueueMutation(element, 'attributes', {
function enqueueClassAttributeChange(el, oldValue) {
enqueueMutation(el, 'attributes', {
name: 'class',
namespace: null,
oldValue: oldValue
});
}
function changeClass(tokenList, method, args) {
var oldValue = unsafeUnwrap(tokenList.ownerElement_).getAttribute('class');
var retv = method.apply(unsafeUnwrap(tokenList), args);
function invalidateClass(el) {
scope.invalidateRendererBasedOnAttribute(el, 'class');
}
if (unsafeUnwrap(tokenList.ownerElement_).getAttribute('class') !== oldValue) {
enqueueClassAttributeChange(tokenList.ownerElement_, oldValue);
invalidateClass(tokenList.ownerElement_);
function changeClass(tokenList, method, args) {
var ownerElement = tokenList.ownerElement_;
if (ownerElement == null) {
return method.apply(tokenList, args);
}
var oldValue = getClass(ownerElement);
var retv = method.apply(tokenList, args);
if (getClass(ownerElement) !== oldValue) {
enqueueClassAttributeChange(ownerElement, oldValue);
invalidateClass(ownerElement);
}
return retv;
}
function DOMTokenList(impl, ownerElement) {
setWrapper(impl, this);
this.ownerElement_ = ownerElement;
}
DOMTokenList.prototype = {
constructor: DOMTokenList,
get length() {
return unsafeUnwrap(this).length;
},
item: function(index) {
return unsafeUnwrap(this).item(index);
},
contains: function(token) {
return unsafeUnwrap(this).contains(token);
},
add: function() {
changeClass(this, unsafeUnwrap(this).add, arguments);
},
remove: function() {
changeClass(this, unsafeUnwrap(this).remove, arguments);
},
toggle: function() {
return changeClass(this, unsafeUnwrap(this).toggle, arguments);
},
toString: function() {
return unsafeUnwrap(this).toString();
}
var oldAdd = DOMTokenList.prototype.add;
DOMTokenList.prototype.add = function() {
changeClass(this, oldAdd, arguments);
};
var oldRemove = DOMTokenList.prototype.remove;
DOMTokenList.prototype.remove = function() {
changeClass(this, oldRemove, arguments);
};
var oldToggle = DOMTokenList.prototype.toggle;
DOMTokenList.prototype.toggle = function() {
return changeClass(this, oldToggle, arguments);
};
scope.wrappers.DOMTokenList = DOMTokenList;
})(window.ShadowDOMPolyfill);

View File

@@ -14,7 +14,6 @@
var ChildNodeInterface = scope.ChildNodeInterface;
var GetElementsByInterface = scope.GetElementsByInterface;
var Node = scope.wrappers.Node;
var DOMTokenList = scope.wrappers.DOMTokenList;
var ParentNodeInterface = scope.ParentNodeInterface;
var SelectorsInterface = scope.SelectorsInterface;
var addWrapNodeListMethod = scope.addWrapNodeListMethod;
@@ -106,8 +105,9 @@
get classList() {
var list = classListTable.get(this);
if (!list) {
classListTable.set(this,
list = new DOMTokenList(unsafeUnwrap(this).classList, this));
list = unsafeUnwrap(this).classList;
list.ownerElement_ = this;
classListTable.set(this, list);
}
return list;
},

View File

@@ -348,7 +348,7 @@
var originalRemoveChild = OriginalNode.prototype.removeChild;
var originalReplaceChild = OriginalNode.prototype.replaceChild;
var isIe = /Trident/.test(navigator.userAgent);
var isIe = /Trident|Edge/.test(navigator.userAgent);
var removeChildOriginalHelper = isIe ?
function(parent, child) {

View File

@@ -19,7 +19,6 @@ window.WebComponents = window.WebComponents || {};
var script = document.querySelector('script[src*="' + file + '"]');
// Flags. Convert url arguments to flags
var flags = {};
if (!flags.noOpts) {
// from url
location.search.slice(1).split('&').forEach(function(o) {

View File

@@ -26,7 +26,7 @@ function isFormControl(element)
* Clone the input node, insert it into a div, and then read back the outerHTML, which is now stripped of the XML *
* Namespace element
*/
var isIE = navigator.userAgent.indexOf('Trident') > -1;
var isIE = /Trident|Edge/.test(navigator.userAgent);
function assertOuterHTML(element, expected) {
var outerHTML = element.outerHTML;
if (isIE) {

View File

@@ -36,6 +36,7 @@
<link rel="import" href="imports/load-1.html" onload="importLoaded(event)">
<link rel="import" href="imports/load-2.html" onload="importLoaded(event)">
<link rel="import" id="willError" href="imports/404.html" onerror="importError(event)">
<link rel="import" id="nohref" onerror="importError(event)">
</head>
<body>
<div id="test1" class="red">Test</div>
@@ -43,7 +44,7 @@
<div id="test3" class="image"></div>
<script>
document.addEventListener('HTMLImportsLoaded', function() {
chai.assert.equal(loadEvents, 3, 'expected # of load events');
chai.assert.equal(loadEvents, 4, 'expected # of load events');
var test1 = getComputedStyle(document.querySelector('#test1')).backgroundColor;
chai.assert.equal(test1, 'rgb(255, 0, 0)');
var test2 = getComputedStyle(document.querySelector('#test2')).backgroundColor;

View File

@@ -27,7 +27,7 @@ function runTest() {
// current spec is target should be window for beforeunload, but is overridden
// to be document for unload. Both events are dispatched on window:
// http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#unloading-documents
var expectedTarget = /Trident/.test(navigator.userAgent) ? win : doc;
var expectedTarget = /Trident|Edge/.test(navigator.userAgent) ? win : doc;
var beforeunloadCalled = 0;
window.addEventListener('beforeunload', function(e) {

View File

@@ -58,7 +58,6 @@ suite('DOMTokenList', function() {
test('contains', function() {
var div = document.createElement('div');
var classList = div.classList;
assert.isFalse(classList.contains());
assert.isFalse(classList.contains('a'));
div.className = 'a';
assert.isTrue(classList.contains('a'));
@@ -110,4 +109,13 @@ suite('DOMTokenList', function() {
div.className = 'b a';
assert.equal(classList.toString(), 'b a');
});
test('index', function() {
var div = document.createElement('div');
var classList = div.classList;
classList.add('a');
classList.add('b');
assert.equal(classList[0], 'a');
assert.equal(classList[1], 'b');
});
});

View File

@@ -56,7 +56,8 @@ suite('HTMLContentElement', function() {
df.appendChild(document.createTextNode(' '));
root.appendChild(df);
assertArrayEqual(content.getDistributedNodes().length, 3);
assert.equal(content.getDistributedNodes().length, 7);
assertArrayEqual(content.getDistributedNodes(), host.childNodes);
});
test('getDistributedNodes add content deep inside tree', function() {

View File

@@ -111,7 +111,7 @@ suite('SVGElementInstance', function() {
assert.equal('line', instanceRoot.lastChild.correspondingElement.localName);
// IE always returns new wrappers for all the accessors.
if (/Trident/.test(navigator.userAgent))
if (/Trident|Edge/.test(navigator.userAgent))
return;
assert.equal(instanceRoot.firstChild, instanceRoot.lastChild);

View File

@@ -107,7 +107,7 @@ suite('Selection', function() {
});
test('extend', function() {
// IE does not have extend.
// IE legacy document modes do not have extend.
if (/Trident/.test(navigator.userAgent))
return;
@@ -159,7 +159,7 @@ suite('Selection', function() {
});
test('containsNode', function() {
// IE does not have containsNode.
// IE legacy document modes do not have containsNode.
if (/Trident/.test(navigator.userAgent))
return;

View File

@@ -1170,7 +1170,7 @@ test('retarget order (multiple shadow roots)', function() {
// defaultPrevented is broken in IE.
// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
if (!/Trident/.test(navigator.userAgent))
if (!/Trident|Edge/.test(navigator.userAgent))
assert.isTrue(event.defaultPrevented);
});