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

Commit 20d9c5b

Browse files
committed
Merge pull request #339 from sorvell/master
Update support for CustomElements to use document.registerElement
2 parents 496f0a7 + 16f97d5 commit 20d9c5b

2 files changed

Lines changed: 41 additions & 40 deletions

File tree

src/wrappers/Document.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@
106106
}
107107
});
108108

109-
if (document.register) {
110-
var originalRegister = document.register;
111-
Document.prototype.register = function(tagName, object) {
109+
if (document.registerElement) {
110+
var originalRegisterElement = document.registerElement;
111+
Document.prototype.registerElement = function(tagName, object) {
112112
var prototype = object.prototype;
113113

114114
// If we already used the object as a prototype for another custom
@@ -152,8 +152,8 @@
152152
// and not from the spec since the spec is out of date.
153153
[
154154
'createdCallback',
155-
'enteredViewCallback',
156-
'leftViewCallback',
155+
'attachedCallback',
156+
'detachedCallback',
157157
'attributeChangedCallback',
158158
].forEach(function(name) {
159159
var f = prototype[name];
@@ -190,14 +190,15 @@
190190
scope.nativePrototypeTable.set(prototype, newPrototype);
191191

192192
// registration is synchronous so do it last
193-
var nativeConstructor = originalRegister.call(unwrap(this), tagName, p);
193+
var nativeConstructor = originalRegisterElement.call(unwrap(this),
194+
tagName, p);
194195
return CustomElementConstructor;
195196
};
196197

197198
forwardMethodsToWrapper([
198199
window.HTMLDocument || window.Document, // Gecko adds these to HTMLDocument
199200
], [
200-
'register',
201+
'registerElement',
201202
]);
202203
}
203204

test/js/Document.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,16 @@ htmlSuite('Document', function() {
296296
assert.isTrue(document.contains(document.querySelector('html')));
297297
});
298298

299-
test('document.register', function() {
300-
if (!document.register)
299+
test('document.registerElement', function() {
300+
if (!document.registerElement)
301301
return;
302302

303303
var aPrototype = Object.create(HTMLElement.prototype);
304304
aPrototype.getName = function() {
305305
return 'a';
306306
};
307307

308-
var A = document.register('x-a', {prototype: aPrototype});
308+
var A = document.registerElement('x-a', {prototype: aPrototype});
309309

310310
var a1 = document.createElement('x-a');
311311
assert.equal('x-a', a1.localName);
@@ -328,7 +328,7 @@ htmlSuite('Document', function() {
328328
return 'b';
329329
};
330330

331-
var B = document.register('x-b', {prototype: bPrototype});
331+
var B = document.registerElement('x-b', {prototype: bPrototype});
332332

333333
var b1 = document.createElement('x-b');
334334
assert.equal('x-b', b1.localName);
@@ -347,16 +347,16 @@ htmlSuite('Document', function() {
347347
assert.equal(b2.getName(), 'b');
348348
});
349349

350-
test('document.register type extension', function() {
351-
if (!document.register)
350+
test('document.registerElement type extension', function() {
351+
if (!document.registerElement)
352352
return;
353353

354354
var aPrototype = Object.create(HTMLSpanElement.prototype);
355355
aPrototype.getName = function() {
356356
return 'a';
357357
};
358358

359-
var A = document.register('x-a-span',
359+
var A = document.registerElement('x-a-span',
360360
{prototype: aPrototype, extends: 'span'});
361361

362362
var a1 = document.createElement('span', 'x-a-span');
@@ -376,8 +376,8 @@ htmlSuite('Document', function() {
376376
assert.equal(a2.getName(), 'a');
377377
});
378378

379-
test('document.register deeper', function() {
380-
if (!document.register)
379+
test('document.registerElement deeper', function() {
380+
if (!document.registerElement)
381381
return;
382382

383383
function C() {}
@@ -395,7 +395,7 @@ htmlSuite('Document', function() {
395395
__proto__: B.prototype
396396
};
397397

398-
A = document.register('x-a5', A);
398+
A = document.registerElement('x-a5', A);
399399

400400
var a1 = document.createElement('x-a5');
401401
assert.equal('x-a5', a1.localName);
@@ -414,8 +414,8 @@ htmlSuite('Document', function() {
414414
HTMLElement.prototype);
415415
});
416416

417-
test('document.register createdCallback', function() {
418-
if (!document.register)
417+
test('document.registerElement createdCallback', function() {
418+
if (!document.registerElement)
419419
return;
420420

421421
var self;
@@ -432,15 +432,15 @@ htmlSuite('Document', function() {
432432
}
433433
};
434434

435-
A = document.register('x-a2', A);
435+
A = document.registerElement('x-a2', A);
436436

437437
var a = new A;
438438
assert.equal(createdCalls, 1);
439439
assert.equal(self, a);
440440
});
441441

442-
test('document.register createdCallback upgrade', function() {
443-
if (!document.register)
442+
test('document.registerElement createdCallback upgrade', function() {
443+
if (!document.registerElement)
444444
return;
445445

446446
div = document.body.appendChild(document.createElement('div'));
@@ -456,43 +456,43 @@ htmlSuite('Document', function() {
456456
isCustom: true
457457
};
458458

459-
A = document.register('x-a2-1', A);
459+
A = document.registerElement('x-a2-1', A);
460460
});
461461

462-
test('document.register enteredViewCallback, leftViewCallback',
462+
test('document.registerElement attachedCallback, detachedCallback',
463463
function() {
464-
if (!document.register)
464+
if (!document.registerElement)
465465
return;
466466

467-
var enteredViewCalls = 0;
468-
var leftViewCalls = 0;
467+
var attachedCalls = 0;
468+
var detachedCalls = 0;
469469

470470
function A() {}
471471
A.prototype = {
472472
__proto__: HTMLElement.prototype,
473-
enteredViewCallback: function() {
474-
enteredViewCalls++;
473+
attachedCallback: function() {
474+
attachedCalls++;
475475
assert.instanceOf(this, A);
476476
assert.equal(a, this);
477477
},
478-
leftViewCallback: function() {
479-
leftViewCalls++;
478+
detachedCallback: function() {
479+
detachedCalls++;
480480
assert.instanceOf(this, A);
481481
assert.equal(a, this);
482482
}
483483
};
484484

485-
A = document.register('x-a3', A);
485+
A = document.registerElement('x-a3', A);
486486

487487
var a = new A;
488488
document.body.appendChild(a);
489-
assert.equal(enteredViewCalls, 1);
489+
assert.equal(attachedCalls, 1);
490490
document.body.removeChild(a);
491-
assert.equal(leftViewCalls, 1);
491+
assert.equal(detachedCalls, 1);
492492
});
493493

494-
test('document.register attributeChangedCallback', function() {
495-
if (!document.register)
494+
test('document.registerElement attributeChangedCallback', function() {
495+
if (!document.registerElement)
496496
return;
497497

498498
var attributeChangedCalls = 0;
@@ -521,7 +521,7 @@ htmlSuite('Document', function() {
521521
}
522522
};
523523

524-
A = document.register('x-a4', A);
524+
A = document.registerElement('x-a4', A);
525525

526526
var a = new A;
527527
assert.equal(attributeChangedCalls, 0);
@@ -533,8 +533,8 @@ htmlSuite('Document', function() {
533533
assert.equal(attributeChangedCalls, 3);
534534
});
535535

536-
test('document.register get reference, upgrade, rewrap', function() {
537-
if (!document.register)
536+
test('document.registerElement get reference, upgrade, rewrap', function() {
537+
if (!document.registerElement)
538538
return;
539539

540540
div = document.body.appendChild(document.createElement('div'));
@@ -548,7 +548,7 @@ htmlSuite('Document', function() {
548548
isCustom: true
549549
};
550550

551-
A = document.register('x-a6', A);
551+
A = document.registerElement('x-a6', A);
552552
// re-wrap after registration to update wrapper
553553
ShadowDOMPolyfill.rewrap(ShadowDOMPolyfill.unwrap(div.firstChild));
554554
assert.isTrue(div.firstChild.isCustom);

0 commit comments

Comments
 (0)