github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/v8/test/test_inject_inst_counter_source.js (about)

     1  'use strict';
     2  
     3  var module = {};
     4  
     5  var _instruction_counter = 123;
     6  
     7  function* countAppleSales() {
     8      var saleList = [3, 7, 5];
     9      for (var i = 0; i < saleList.length; i++) {
    10          yield saleList[i];
    11      }
    12  }
    13  var appleStore = countAppleSales(); // Generator { }
    14  console.log(appleStore.next()); // { value: 3, done: false }
    15  console.log(appleStore.next()); // { value: 7, done: false }
    16  console.log(appleStore.next()); // { value: 5, done: false }
    17  console.log(appleStore.next()); // { value: undefined, done: true }
    18  
    19  var doStatement = function () {
    20      var i = 0;
    21      do {
    22          i++;
    23      } while (i < 15);
    24  
    25      do
    26          i++;
    27      while (i < 25);
    28  
    29      while (i < 100) {
    30          i++;
    31          if (i < 50) {
    32              break;
    33          }
    34      }
    35  };
    36  
    37  var forStatement = function () {
    38      for (var i = 0; i < 12; i++) {
    39          if (i % 3 == 0) {
    40              continue;
    41          }
    42          if (i == 10) {
    43              break;
    44          }
    45      }
    46  };
    47  
    48  var arrayFunction = function () {
    49      let foo = (s) => {
    50          console.log('a ' + 123);
    51      };
    52  };
    53  
    54  var SampleContract = function () {
    55      LocalContractStorage.defineProperties(this, {
    56          name: null,
    57          count: null
    58      });
    59      LocalContractStorage.defineMapProperty(this, "allocation" + 123);
    60      this.a = 0;
    61      let foo = (s) => s + 1;
    62      new.target;
    63      var elvisLives = Math.PI > 4 ? foo() : 'Nope';
    64  };
    65  SampleContract.prototype = {
    66      init: function (name, count, allocation) {
    67          this.name = name;
    68          this.count = count;
    69          this.zz[0] = 123;
    70          allocation.forEach(function (item) {
    71              this.allocation.put(item.name, item.count);
    72          }, this);
    73      },
    74      dump: function () {
    75          console.log('dump: this.name = ' + this.name);
    76          console.log('dump: this.count = ' + this.count);
    77          return this.a;
    78      },
    79      incr: function () {
    80          this.a++;
    81          var z = this.a;
    82          console.log(this.dump());
    83          return this.a;
    84      },
    85      verify: function (expectedName, expectedCount, expectedAllocation) {
    86          if (!Object.is(this.name, expectedName))
    87              throw new Error("name is not the same, expecting " + expectedName + ", actual is " + this.name + ".");
    88          else
    89              var elvisLives = Math.PI > 4 ? foo() : 'Nope';
    90  
    91          if (!Object.is(this.count, expectedCount)) {
    92              throw new Error("count is not the same, expecting " + expectedCount + ", actual is " + this.count + ".");
    93          } else {
    94              console.log('ok.');
    95          }
    96          expectedAllocation.forEach(function (expectedItem) {
    97              var count = this.allocation.get(expectedItem.name);
    98              if (!Object.is(count, expectedItem.count)) {
    99                  throw new Error("count of " + expectedItem.name + " is not the same, expecting " + expectedItem.count + ", actual is " + count + ".");
   100              }
   101          }, this);
   102      },
   103      test_switch: function () {
   104          var day = "";
   105          switch (new Date().getDay()) {
   106              case 0:
   107                  day = "Sunday";
   108                  break;
   109              case 1:
   110                  day = "Monday";
   111                  break;
   112              case 2:
   113                  day = "Tuesday";
   114                  break;
   115              case 3:
   116                  day = "Wednesday";
   117                  break;
   118              case 4:
   119                  day = "Thursday";
   120                  break;
   121              case 5:
   122                  day = "Friday";
   123                  break;
   124              case 6:
   125                  day = "Saturday";
   126              default:
   127                  throw new Error("N/A");
   128          }
   129          console.log('day is ' + day);
   130      },
   131      test_for: function () {
   132          for (var i = 0; i < 123; i++) {
   133              var z = i;
   134              alert(z);
   135          }
   136          for (var i = 0; i < 123; i++)
   137              alert(i);
   138      },
   139  };
   140  
   141  module.exports = SampleContract;