Example #1
0
export function coalesce(records: ProtoRecord[]): ProtoRecord[] {
  var res: List<ProtoRecord> = [];
  var indexMap: Map<number, number> = new Map<number, number>();

  for (var i = 0; i < records.length; ++i) {
    var r = records[i];
    var record = _replaceIndices(r, res.length + 1, indexMap);
    var matchingRecord = _findMatching(record, res);

    if (isPresent(matchingRecord) && record.lastInBinding) {
      res.push(_selfRecord(record, matchingRecord.selfIndex, res.length + 1));
      indexMap.set(r.selfIndex, matchingRecord.selfIndex);
      matchingRecord.referencedBySelf = true;

    } else if (isPresent(matchingRecord) && !record.lastInBinding) {
      if (record.argumentToPureFunction) {
        matchingRecord.argumentToPureFunction = true;
      }

      indexMap.set(r.selfIndex, matchingRecord.selfIndex);

    } else {
      res.push(record);
      indexMap.set(r.selfIndex, record.selfIndex);
    }
  }

  return res;
}
 _addRecord(type, name, funcOrValue, args, fixedArgs, context) {
   var selfIndex = this._records.length + 1;
   if (context instanceof DirectiveIndex) {
     this._records.push(new ProtoRecord(type, name, funcOrValue, args, fixedArgs, -1, context,
                                        selfIndex, this._bindingRecord, this._expressionAsString,
                                        false, false));
   } else {
     this._records.push(new ProtoRecord(type, name, funcOrValue, args, fixedArgs, context, null,
                                        selfIndex, this._bindingRecord, this._expressionAsString,
                                        false, false));
   }
   return selfIndex;
 }
Example #3
0
 _printDescription(sampleDescription) {
   this._print(`BENCHMARK ${sampleDescription.id}`);
   this._print('Description:');
   var props = ConsoleReporter._sortedProps(sampleDescription.description);
   props.forEach((prop) => { this._print(`- ${prop}: ${sampleDescription.description[prop]}`); });
   this._print('Metrics:');
   this._metricNames.forEach((metricName) => {
     this._print(`- ${metricName}: ${sampleDescription.metrics[metricName]}`);
   });
   this._print('');
   this._printStringRow(this._metricNames);
   this._printStringRow(this._metricNames.map((_) => ''), '-');
 }
Example #4
0
 go(url: string) {
   url = this.normalizeAbsolutely(url);
   if (this._path == url) {
     return;
   }
   this._path = url;
   this.urlChanges.push(url);
 }
function ifChangedGuardTemplate(changeNames: List<any>, body: string): string {
  var cond = changeNames.join(" || ");
  return `
if (${cond}) {
  ${body}
}
`;
}
 getLocalNames(records: List<ProtoRecord>): List<string> {
   var index = 0;
   var names = records.map((r) => {
     var sanitizedName = r.name.replace(new RegExp("\\W", "g"), '');
     return `${sanitizedName}${index++}`
   });
   return ["context"].concat(names);
 }
Example #7
0
  whenStable(callback: Function) {
    this._callbacks.push(callback);

    if (this._pendingCount === 0) {
      this._runCallbacks();
    }
    // TODO(juliemr) - hook into the zone api.
  }
 _getNonNullPipeNames(): List<string> {
   var pipes = [];
   this.records.forEach((r) => {
     if (r.isPipeRecord()) {
       pipes.push(this._pipeNames[r.selfIndex]);
     }
   });
   return pipes;
 }
  generate(): Function {
    var classDefinition = `
      var ${this.typeName} = function ${this.typeName}(dispatcher, pipeRegistry, protos, directiveRecords) {
        ${ABSTRACT_CHANGE_DETECTOR}.call(this);
        ${DISPATCHER_ACCESSOR} = dispatcher;
        ${PIPE_REGISTRY_ACCESSOR} = pipeRegistry;
        ${PROTOS_ACCESSOR} = protos;
        ${DIRECTIVES_ACCESSOR} = directiveRecords;
        ${LOCALS_ACCESSOR} = null;
        ${this._genFieldDefinitions()}
      }

      ${this.typeName}.prototype = Object.create(${ABSTRACT_CHANGE_DETECTOR}.prototype);

      ${this.typeName}.prototype.detectChangesInRecords = function(throwOnChange) {
        ${this._genLocalDefinitions()}
        ${this._genChangeDefinitions()}
        var ${IS_CHANGED_LOCAL} = false;
        var ${CURRENT_PROTO};
        var ${CHANGES_LOCAL} = null;

        context = ${CONTEXT_ACCESSOR};

        ${this.records.map((r) => this._genRecord(r)).join("\n")}
      }

      ${this.typeName}.prototype.callOnAllChangesDone = function() {
        ${this._genCallOnAllChangesDoneBody()}
      }

      ${this.typeName}.prototype.hydrate = function(context, locals, directives) {
        ${MODE_ACCESSOR} = "${ChangeDetectionUtil.changeDetectionMode(this.changeDetectionStrategy)}";
        ${CONTEXT_ACCESSOR} = context;
        ${LOCALS_ACCESSOR} = locals;
        ${this._genHydrateDirectives()}
        ${this._genHydrateDetectors()}
      }

      ${this.typeName}.prototype.dehydrate = function() {
        ${this._genPipeOnDestroy()}
        ${this._genFieldDefinitions()}
        ${LOCALS_ACCESSOR} = null;
      }

      ${this.typeName}.prototype.hydrated = function() {
        return ${CONTEXT_ACCESSOR} !== ${UTIL}.uninitialized();
      }

      return function(dispatcher, pipeRegistry) {
        return new ${this.typeName}(dispatcher, pipeRegistry, protos, directiveRecords);
      }
    `;

    return new Function('AbstractChangeDetector', 'ChangeDetectionUtil', 'protos',
                        'directiveRecords', classDefinition)(
        AbstractChangeDetector, ChangeDetectionUtil, this.records, this.directiveRecords);
  }
 getNonNullPipeNames(): List<string> {
   var pipes = [];
   this.records.forEach((r) => {
     if (r.mode === RECORD_TYPE_PIPE || r.mode === RECORD_TYPE_BINDING_PIPE) {
       pipes.push(this.pipeNames[r.selfIndex]);
     }
   });
   return pipes;
 }
 _appendRecords(b: BindingRecord, variableNames: List<string>) {
   if (b.isDirectiveLifecycle()) {
     this.records.push(new ProtoRecord(RecordType.DIRECTIVE_LIFECYCLE, b.lifecycleEvent, null, [],
                                       [], -1, null, this.records.length + 1, b, null, false,
                                       false));
   } else {
     _ConvertAstIntoProtoRecords.append(this.records, b, variableNames);
   }
 }
Example #12
0
 readPerfLog(): Promise<any> {
   this._commandLog.push('readPerfLog');
   if (this._perfLogs.length > 0) {
     var next = this._perfLogs[0];
     ListWrapper.removeAt(this._perfLogs, 0);
     return PromiseWrapper.resolve(next);
   } else {
     return PromiseWrapper.resolve([]);
   }
 }
  _processStyleElement(current: CompileElement, control: CompileControl) {
    var stylePromise = this._shadowDomStrategy.processStyleElement(
        this._template.componentId, this._template.templateAbsUrl, current.element);
    if (isPresent(stylePromise) && isPromise(stylePromise)) {
      this._subTaskPromises.push(stylePromise);
    }

    // Style elements should not be further processed by the compiler, as they can not contain
    // bindings. Skipping further compiler steps allow speeding up the compilation process.
    control.ignoreCurrentElement();
  }
Example #14
0
export function coalesce(records: List<ProtoRecord>): List<ProtoRecord> {
  var res: List<ProtoRecord> = [];
  var indexMap: Map<number, number> = MapWrapper.create();

  for (var i = 0; i < records.length; ++i) {
    var r = records[i];
    var record = _replaceIndices(r, res.length + 1, indexMap);
    var matchingRecord = _findMatching(record, res);

    if (isPresent(matchingRecord) && record.lastInBinding) {
      res.push(_selfRecord(record, matchingRecord.selfIndex, res.length + 1));
      MapWrapper.set(indexMap, r.selfIndex, matchingRecord.selfIndex);

    } else if (isPresent(matchingRecord) && !record.lastInBinding) {
      MapWrapper.set(indexMap, r.selfIndex, matchingRecord.selfIndex);

    } else {
      res.push(record);
      MapWrapper.set(indexMap, r.selfIndex, record.selfIndex);
    }
  }

  return res;
}
Example #15
0
 reportSample(completeSample: List<MeasureValues>,
              validSample: List<MeasureValues>): Promise<any> {
   this._printStringRow(this._metricNames.map((_) => ''), '=');
   this._printStringRow(ListWrapper.map(this._metricNames, (metricName) => {
     var sample =
         ListWrapper.map(validSample, (measureValues) => measureValues.values[metricName]);
     var mean = Statistic.calculateMean(sample);
     var cv = Statistic.calculateCoefficientOfVariation(sample, mean);
     var formattedMean = ConsoleReporter._formatNum(mean)
                             // Note: Don't use the unicode character for +- as it might cause
                             // hickups for consoles...
                             return NumberWrapper.isNaN(cv) ?
                             formattedMean :
                             `${formattedMean}+-${Math.floor(cv)}%`;
   }));
   return PromiseWrapper.resolve(null);
 }
Example #16
0
 constructor() {
   var appSize = getIntParameter('appSize');
   this.iterationCount = getIntParameter('iterationCount');
   this.scrollIncrement = getIntParameter('scrollIncrement');
   appSize = appSize > 1 ? appSize - 1 : 0;  // draw at least one table
   this.scrollAreas = [];
   for (var i = 0; i < appSize; i++) {
     this.scrollAreas.push(i);
   }
   bindAction('#run-btn', () => { this.runBenchmark(); });
   bindAction('#reset-btn', () => {
     this._getScrollDiv().scrollTop = 0;
     var existingMarker = this._locateFinishedMarker();
     if (isPresent(existingMarker)) {
       DOM.removeChild(document.body, existingMarker);
     }
   });
 }
  generate(): Function {
    var classDefinition = `
      var ${this._typeName} = function ${this._typeName}(dispatcher) {
        ${ABSTRACT_CHANGE_DETECTOR}.call(
            this, ${JSON.stringify(this.id)}, dispatcher, ${this.records.length},
            ${this._typeName}.gen_propertyBindingTargets, ${this._typeName}.gen_directiveIndices,
            ${codify(this.changeDetectionStrategy)});
        this.dehydrateDirectives(false);
      }

      ${this._typeName}.prototype = Object.create(${ABSTRACT_CHANGE_DETECTOR}.prototype);

      ${this._typeName}.prototype.detectChangesInRecordsInternal = function(throwOnChange) {
        ${this._names.genInitLocals()}
        var ${IS_CHANGED_LOCAL} = false;
        var ${CHANGES_LOCAL} = null;

        ${this.records.map((r) => this._genRecord(r)).join("\n")}

        ${this._names.getAlreadyCheckedName()} = true;
      }

      ${this._maybeGenHandleEventInternal()}

      ${this._genCheckNoChanges()}

      ${this._maybeGenCallOnAllChangesDone()}

      ${this._maybeGenHydrateDirectives()}

      ${this._maybeGenDehydrateDirectives()}

      ${this._genPropertyBindingTargets()};

      ${this._genDirectiveIndices()};

      return function(dispatcher) {
        return new ${this._typeName}(dispatcher);
      }
    `;
    return new Function(ABSTRACT_CHANGE_DETECTOR, UTIL, classDefinition)(AbstractChangeDetector,
                                                                         ChangeDetectionUtil);
  }
  generate(): Function {
    var classDefinition = `
      var ${this._typeName} = function ${this._typeName}(dispatcher, protos, directiveRecords) {
        ${ABSTRACT_CHANGE_DETECTOR}.call(
            this, ${JSON.stringify(this.id)}, dispatcher, protos, directiveRecords,
            "${ChangeDetectionUtil.changeDetectionMode(this.changeDetectionStrategy)}");
        this.dehydrateDirectives(false);
      }

      ${this._typeName}.prototype = Object.create(${ABSTRACT_CHANGE_DETECTOR}.prototype);

      ${this._typeName}.prototype.detectChangesInRecordsInternal = function(throwOnChange) {
        ${this._names.genInitLocals()}
        var ${IS_CHANGED_LOCAL} = false;
        var ${CHANGES_LOCAL} = null;

        ${this.records.map((r) => this._genRecord(r)).join("\n")}

        ${this._names.getAlreadyCheckedName()} = true;
      }

      ${this._maybeGenHandleEventInternal()}

      ${this._genCheckNoChanges()}

      ${this._maybeGenCallOnAllChangesDone()}

      ${this._maybeGenHydrateDirectives()}

      ${this._maybeGenDehydrateDirectives()}

      return function(dispatcher) {
        return new ${this._typeName}(dispatcher, protos, directiveRecords);
      }
    `;
    return new Function('AbstractChangeDetector', 'ChangeDetectionUtil', 'protos',
                        'directiveRecords', classDefinition)(
        AbstractChangeDetector, ChangeDetectionUtil, this.records, this.directiveRecords);
  }
  _genReferenceCheck(r: ProtoRecord): string {
    var oldValue = this._fieldNames[r.selfIndex];
    var newValue = this._localNames[r.selfIndex];

    var protoIndex = r.selfIndex - 1;
    var check = `
      ${CURRENT_PROTO} = ${PROTOS_ACCESSOR}[${protoIndex}];
      ${this._genUpdateCurrentValue(r)}
      if (${newValue} !== ${oldValue}) {
        ${this._changeNames[r.selfIndex]} = true;
        ${this._genUpdateDirectiveOrElement(r)}
        ${this._genAddToChanges(r)}
        ${oldValue} = ${newValue};
      }
    `;

    if (r.isPureFunction()) {
      var condition = `${this._changeNames.join(" || ")}`;
      return `if (${condition}) { ${check} }`;
    } else {
      return check;
    }
  }
function pipeOnDestroyTemplate(pipeNames: List<any>) {
  return pipeNames.map((p) => `${p}.onDestroy()`).join("\n");
}
 genDetectChangesBody(): string {
   var rec = this.records.map((r) => this.genRecord(r)).join("\n");
   return detectChangesBodyTemplate(this.genLocalDefinitions(), this.genChangeDefinitions(), rec);
 }
 getDetectorFieldNames(): List<string> {
   return this.directiveRecords.filter(r => r.isOnPushChangeDetection())
       .map((d) => this.getDetector(d.directiveIndex));
 }
 getDirectiveFieldNames(): List<string> {
   return this.directiveRecords.map((d) => this.getDirective(d.directiveIndex));
 }
 getPipeNames(localNames: List<string>): List<string> {
   return localNames.map((n) => `this.${n}_pipe`);
 }
 getFieldNames(localNames: List<string>): List<string> {
   return localNames.map((n) => `this.${n}`);
 }
 getChangeNames(localNames: List<string>): List<string> {
   return localNames.map((n) => `change_${n}`);
 }
function fieldDefinitionsTemplate(names: List<any>): string {
  return names.map((n) => `${n} = ${UTIL}.uninitialized();`).join("\n");
}
function changeDefinitionsTemplate(names: List<any>): string {
  return names.map((n) => `var ${n} = false;`).join("\n");
}
function localDefinitionsTemplate(names: List<any>): string {
  return names.map((n) => `var ${n};`).join("\n");
}
Example #30
0
export function asNativeElements(arr: List<DebugElement>): List<any> {
  return arr.map((debugEl) => debugEl.nativeElement);
}