tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

typescript.js (6441B)


      1 // Copyright 2013 the Octane Benchmark project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 var typescript = new BenchmarkSuite('Typescript', [255011322], [
     29  new Benchmark("Typescript",
     30                false,
     31                true,
     32                5,
     33                runTypescript,
     34                setupTypescript,
     35                tearDownTypescript,
     36                null,
     37                1)
     38 ]);
     39 
     40 
     41 function setupTypescript() {
     42 }
     43 
     44 
     45 function tearDownTypescript() {
     46  compiler_input = null;
     47 }
     48 
     49 
     50 var parseErrors = [];
     51 
     52 
     53 function runTypescript() {
     54  var compiler = createCompiler();
     55  compiler.addUnit(compiler_input, "compiler_input.ts");
     56  parseErrors = [];
     57  compiler.reTypeCheck();
     58  compiler.emit({
     59           createFile: function (fileName) { return outfile; },
     60           fileExists: function (path) { return false; },
     61           directoryExists: function (path) { return false; },
     62           resolvePath: function (path) { return path; }
     63  });
     64  
     65  if (parseErrors.length != 192 && parseErrors.length != 193) {
     66    throw new Error("Parse errors.");
     67  }
     68  compiler = null;
     69 }
     70 
     71 var outfile = {
     72  checksum: -412589664, 
     73  cumulative_checksum: 0,
     74  Write: function (s) { this.Verify(s); },
     75  WriteLine: function (s) { this.Verify(s + "\n"); },
     76  Close: function () {
     77    if (this.checksum != this.cumulative_checksum) {
     78      throw new Error("Wrong checksum.");
     79    }
     80    this.cumulative_checksum = 0;
     81  },
     82  Verify: function (s) {
     83    for(var i = 0; i < s.length; i++) {
     84      var c = s.charCodeAt(i);
     85      this.cumulative_checksum = (this.cumulative_checksum << 1) ^ c;
     86    }
     87  }
     88 };
     89 
     90 
     91 var outerr = {
     92  checksum: 0,
     93  cumulative_checksum: 0,
     94  Write: function (s) { this.Verify(s); },
     95  WriteLine: function (s) { this.Verify(s + "\n"); },
     96  Close: function () {
     97    if (this.checksum != this.cumulative_checksum) {
     98      throw new Error("Wrong checksum.");
     99    }
    100    this.cumulative_checksum = 0;
    101  },
    102  Verify: function (s) {
    103    for(var i = 0; i < s.length; i++) {
    104      var c = s.charCodeAt(i);
    105      this.cumulative_checksum = (this.cumulative_checksum << 1) ^ c;
    106    }
    107  }
    108 };
    109 
    110 
    111 function createCompiler() {
    112  var settings = new TypeScript.CompilationSettings();
    113  settings.codeGenTarget = TypeScript.CodeGenTarget.ES5;
    114  var compiler = new TypeScript.TypeScriptCompiler(
    115      outerr, new TypeScript.NullLogger, settings);
    116  compiler.setErrorCallback(function (start, len, message) { 
    117    parseErrors.push({ start: start, len: len, message: message }); 
    118  });
    119  compiler.parser.errorRecovery = true;
    120  compiler.typeCheck();
    121  return compiler
    122 }
    123 
    124 
    125 // The two files accompanying this benchmark contain a modified version of the
    126 // Typescript compiler. They can be generated using the following instructions
    127 // with the code available at:
    128 //    http://typescript.codeplex.com/SourceControl/changeset/view/258e00903a9e
    129 //
    130 // 1) Copy the compiler from $TYPESCRIPT/bin/tsc.js to typescript-compiler.js
    131 // 2) Remove the call to the batch compiler from the last line of tsc.js
    132 // 3) Add this code after line 7963 (fix for Mozilla Firefox):
    133 //    if (this.currentToken === undefined)
    134 //      this.currentToken = this.scanner.scan();
    135 // 4) Add this code after line 9142 (fix for Mozilla Firefox):
    136 //    if (this.currentToken === undefined) {
    137 //      this.currentToken = this.scanner.scan();
    138 //      continue;
    139 //    }
    140 // 5) Generate the Typescript compiler input using the following command:
    141 //    $ cat $TYPESCRIPT/src/compiler/*.ts | iconv -c -f utf8 -t ascii \
    142 //      | dos2unix > /tmp/compiler_input
    143 // 6) Run the following Python script to generate the reformatted input:
    144 //    $ python script.py > typescript-input.js
    145 //
    146 // #!/usr/bin/env python
    147 // import re;
    148 // def escape_and_format(data, varname):
    149 //   data = data.replace("\\", "\\\\").replace("\"", "\\\"")
    150 //          .replace("\n", "\\n");
    151 //   data = "var " + varname + " = \"" + data + "\""
    152 //   print data; 
    153 // result = open("/tmp/compiler_input", 'r');
    154 // escape_and_format(result.read(), "compiler_input")
    155 //
    156 // The following is the original copyright notice present in the Typescript
    157 // compiler source at the time this benchmark was generated:
    158 //
    159 /* *****************************************************************************
    160 Copyright (c) Microsoft Corporation. All rights reserved. 
    161 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
    162 this file except in compliance with the License. You may obtain a copy of the
    163 License at http://www.apache.org/licenses/LICENSE-2.0  
    164 
    165 THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    166 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
    167 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
    168 MERCHANTABLITY OR NON-INFRINGEMENT. 
    169 
    170 See the Apache Version 2.0 License for specific language governing permissions
    171 and limitations under the License.
    172 ***************************************************************************** */