@@ -326,7 +326,7 @@ export class AbstractAmpContext {
326326 /**
327327 * Parse the metadata attributes from the name and add them to
328328 * the class instance.
329- * @param {!Object| string } data
329+ * @param {string } data
330330 * @private
331331 */
332332 setupMetadata_ ( data ) {
@@ -346,6 +346,17 @@ export class AbstractAmpContext {
346346 delete this . data [ '_context' ] ;
347347 }
348348
349+ this . setupMetadataFromContext_ ( context ) ;
350+
351+ this . embedType_ = dataObject . type || null ;
352+ }
353+
354+ /**
355+ * Set the metadata attributes from the "context" instance directly.
356+ * @param {!Object } context
357+ * @private
358+ */
359+ setupMetadataFromContext_ ( context ) {
349360 this . canary = context . canary ;
350361 this . canonicalUrl = context . canonicalUrl ;
351362 this . clientId = context . clientId ;
@@ -367,8 +378,6 @@ export class AbstractAmpContext {
367378 this . sourceUrl = context . sourceUrl ;
368379 this . startTime = context . startTime ;
369380 this . tagName = context . tagName ;
370-
371- this . embedType_ = dataObject . type || null ;
372381 }
373382
374383 /**
@@ -403,8 +412,11 @@ export class AbstractAmpContext {
403412 } else if ( this . win_ . AMP_CONTEXT_DATA ) {
404413 if ( typeof this . win_ . AMP_CONTEXT_DATA == 'string' ) {
405414 this . sentinel = this . win_ . AMP_CONTEXT_DATA ;
415+ // If AMP_CONTEXT_DATA is an Object, Assume that it is the Context Object
416+ // and not inside the attributes._context which is the structure
417+ // parsed from "name" on other instances.
406418 } else if ( isObject ( this . win_ . AMP_CONTEXT_DATA ) ) {
407- this . setupMetadata_ ( this . win_ . AMP_CONTEXT_DATA ) ;
419+ this . setupMetadataFromContext_ ( this . win_ . AMP_CONTEXT_DATA ) ;
408420 }
409421 } else {
410422 this . setupMetadata_ ( this . win_ . name ) ;
0 commit comments