<commit_before>/*
 * Copyright 2012 The Toolkitchen Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style
 * license that can be found in the LICENSE file.
 */

(function(scope) {

scope = scope || {};

// imports

var CustomDOMElements = scope.CustomDOMElements;
var path = scope.ComponentDocuments.path;
var componentLoader = scope.ComponentDocuments.loader.componentLoader;

// debuggable script injection
//
// this technique allows the component scripts to be
// viewable and debuggable in inspector scripts
// tab (although they are all named "(program)").

var context;

// invoke inScript in inContext scope
var inject = function(inScript, inContext, inName) {
  context = inContext;
  // inject a (debuggable!) script tag
  var	tag = document.createElement("script");
  tag.textContent = "componentScript('" + inName + "', function(){"
    + inScript + "});";
  document.body.appendChild(tag);
};

// global necessary for script injection
window.componentScript = function(inName, inFunc) {
  inFunc.call(context);
};

// Custom DOM Elements SECTION 7.2

HTMLElementElement = function(inElement) {
  this.name = inElement.getAttribute("name");
  this.constructorName = inElement.getAttribute("constructor");
  this.extendsName = inElement.getAttribute("extends") || "div";
  this.template = inElement.querySelector("template");
  this.generatedConstructor = function() {
    return this.instantiate();
  }
  if (!this.name) {
    console.error('name attribute is required.');
    return;
  }
  this.register(inElement);
};

HTMLElementElement.prototype = {
  lifecycle: function(inLifecycle) {
    this.lifecycleImpl = inLifecycle;
  },
  instantiate: function() {
    return CustomDomElements.instantiate(this.prototype, this.template,
      this.lifecycleImpl);
  },
  register: function(element) {
    // fix css paths for inline style elements
    elementParser.adjustTemplateCssPaths(element, this.template);
    // load component stylesheets
    elementParser.sheets(element, this.template);
    // apply @host styles.
    elementParser.applyHostStyles(this.template, this.name);
    //
    // to register a custom element, I need
    //
    //  prototype
    //  lifcycle
    //  template
    //
    // I have template right away
    //
    // I don't get lifecycle or prototype until
    // executing user's code
    //
    // so, execute user's code right away
    //
    // but user may want to cache the reference to generatedConstructor
    // so I have to make a 'real one', but I cannot use the canonical
    // constructor-generation algorithm because I am missing pieces
    //
    // Gambit: make a custom generatedConstructor that binds
    // to an object that is filled in later (instead of
    // a closure)
    //
    // evaluate components scripts
    //
    elementParser.scripts(element, this);
    //
    // now we have the user supplied prototype and lifecycle
    console.log("registering", this.name);
    console.log(this.generatedConstructor.prototype);
    console.log(this.lifecycleImpl);
    //
    // we need to reprocess the prototype (cheating because
    // prototype is not a property defintion object as called for
    // by the spec; it happens to work now due CustomDomElements is
    // implemented to take a regular map)
    //
    this.prototype = CustomDOMElements.generatePrototype(this.extendsName,
      this.generatedConstructor.prototype);
    // TODO(sjmiles): putting name on prototype not in spec
    this.prototype.is = this.name;
    //
    // can't use canonical register method because we've already
    // generated a constructor
    //
    // we almost implement 'definition', except for lifecycleImpl
    //
    var definition = {
      name: this.name,
      prototype: this.prototype,
      template: this.template,
      lifecycle: this.lifecycleImpl
    };
    CustomDOMElements.registry[this.name] = definition;
    CustomDOMElements.upgradeElements(document, definition);
    //
    // optionally install the constructor on the global object
    if (this.constructorName) {<commit_msg>lifecycle cannot be null<commit_after>/*
 * Copyright 2012 The Toolkitchen Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style
 * license that can be found in the LICENSE file.
 */

(function(scope) {

scope = scope || {};

// imports

var CustomDOMElements = scope.CustomDOMElements;
var path = scope.ComponentDocuments.path;
var componentLoader = scope.ComponentDocuments.loader.componentLoader;

// debuggable script injection
//
// this technique allows the component scripts to be
// viewable and debuggable in inspector scripts
// tab (although they are all named "(program)").

var context;

// invoke inScript in inContext scope
var inject = function(inScript, inContext, inName) {
  context = inContext;
  // inject a (debuggable!) script tag
  var	tag = document.createElement("script");
  tag.textContent = "componentScript('" + inName + "', function(){"
    + inScript + "});";
  document.body.appendChild(tag);
};

// global necessary for script injection
window.componentScript = function(inName, inFunc) {
  inFunc.call(context);
};

// Custom DOM Elements SECTION 7.2

HTMLElementElement = function(inElement) {
  this.name = inElement.getAttribute("name");
  this.constructorName = inElement.getAttribute("constructor");
  this.extendsName = inElement.getAttribute("extends") || "div";
  this.template = inElement.querySelector("template");
  this.generatedConstructor = function() {
    return this.instantiate();
  }
  if (!this.name) {
    console.error('name attribute is required.');
    return;
  }
  this.register(inElement);
};

HTMLElementElement.prototype = {
  lifecycle: function(inLifecycle) {
    this.lifecycleImpl = inLifecycle;
  },
  instantiate: function() {
    return CustomDomElements.instantiate(this.prototype, this.template,
      this.lifecycleImpl);
  },
  register: function(element) {
    // fix css paths for inline style elements
    elementParser.adjustTemplateCssPaths(element, this.template);
    // load component stylesheets
    elementParser.sheets(element, this.template);
    // apply @host styles.
    elementParser.applyHostStyles(this.template, this.name);
    //
    // to register a custom element, I need
    //
    //  prototype
    //  lifcycle
    //  template
    //
    // I have template right away
    //
    // I don't get lifecycle or prototype until
    // executing user's code
    //
    // so, execute user's code right away
    //
    // but user may want to cache the reference to generatedConstructor
    // so I have to make a 'real one', but I cannot use the canonical
    // constructor-generation algorithm because I am missing pieces
    //
    // Gambit: make a custom generatedConstructor that binds
    // to an object that is filled in later (instead of
    // a closure)
    //
    // evaluate components scripts
    //
    elementParser.scripts(element, this);
    //
    // now we have the user supplied prototype and lifecycle
    console.log("registering", this.name);
    console.log(this.generatedConstructor.prototype);
    console.log(this.lifecycleImpl);
    //
    // we need to reprocess the prototype (cheating because
    // prototype is not a property defintion object as called for
    // by the spec; it happens to work now due CustomDomElements is
    // implemented to take a regular map)
    //
    this.prototype = CustomDOMElements.generatePrototype(this.extendsName,
      this.generatedConstructor.prototype);
    // TODO(sjmiles): putting name on prototype not in spec
    this.prototype.is = this.name;
    //
    // can't use canonical register method because we've already
    // generated a constructor
    //
    // we almost implement 'definition', except for lifecycleImpl
    //
    var definition = {
      name: this.name,
      prototype: this.prototype,
      template: this.template,
      lifecycle: this.lifecycleImpl || {}
    };
    CustomDOMElements.registry[this.name] = definition;
    CustomDOMElements.upgradeElements(document, definition);
    //
    // optionally install the constructor on the global object
    if (this.constructorName) {
{'fraction_non_alphanumeric': 0.10464690815953165, 'fraction_numerical': 0.0014635931211123307, 'mean_word_length': 3.1330645161290325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1533634', 'n_tokens_mistral': 2251, 'n_tokens_neox': 2206, 'n_words': 708}