* Requests or requires the element to be built. The build is done by * invoking BaseElement.buildCallback method. * * Can only be called on a upgraded element. May only be called from * resource.js to ensure an element and its resource are in sync. * * @return {
()
| 508 | * @restricted |
| 509 | */ |
| 510 | buildInternal() { |
| 511 | assertNotTemplate(this); |
| 512 | devAssert(this.implClass_, 'Cannot build unupgraded element'); |
| 513 | if (this.buildingPromise_) { |
| 514 | return this.buildingPromise_; |
| 515 | } |
| 516 | |
| 517 | this.setReadyStateInternal(ReadyState_Enum.BUILDING); |
| 518 | |
| 519 | // Create the instance. |
| 520 | const implPromise = this.createImpl_(); |
| 521 | this.getSizer_(); |
| 522 | |
| 523 | // Wait for consent. |
| 524 | const consentPromise = implPromise.then(() => { |
| 525 | const policyId = this.getConsentPolicy_(); |
| 526 | const purposeConsents = !policyId ? this.getPurposesConsent_() : null; |
| 527 | if (!policyId && !purposeConsents) { |
| 528 | return; |
| 529 | } |
| 530 | // Must have policyId or granularExp w/ purposeConsents |
| 531 | return Services.consentPolicyServiceForDocOrNull(this) |
| 532 | .then((policy) => { |
| 533 | if (!policy) { |
| 534 | return true; |
| 535 | } |
| 536 | return policyId |
| 537 | ? policy.whenPolicyUnblock(policyId) |
| 538 | : policy.whenPurposesUnblock(purposeConsents); |
| 539 | }) |
| 540 | .then((shouldUnblock) => { |
| 541 | if (!shouldUnblock) { |
| 542 | throw blockedByConsentError(); |
| 543 | } |
| 544 | }); |
| 545 | }); |
| 546 | |
| 547 | // Build callback. |
| 548 | const buildPromise = consentPromise.then(() => |
| 549 | devAssert(this.impl_).buildCallback() |
| 550 | ); |
| 551 | |
| 552 | // Build the element. |
| 553 | return (this.buildingPromise_ = buildPromise.then( |
| 554 | () => { |
| 555 | this.built_ = true; |
| 556 | this.classList.add('i-amphtml-built'); |
| 557 | this.classList.remove('i-amphtml-notbuilt', 'amp-notbuilt'); |
| 558 | this.signals_.signal(CommonSignals_Enum.BUILT); |
| 559 | |
| 560 | if (this.R1()) { |
| 561 | this.setReadyStateInternal( |
| 562 | this.readyState_ != ReadyState_Enum.BUILDING |
| 563 | ? this.readyState_ |
| 564 | : ReadyState_Enum.MOUNTING |
| 565 | ); |
| 566 | } else { |
| 567 | this.setReadyStateInternal(ReadyState_Enum.LOADING); |
no test coverage detected