{"size": 1754, "ext": "js", "max_stars_repo_path": "deps/mozjs/src/tests/ecma_6/TypedObject/method_filter.js", "max_stars_repo_name": "ktrzeciaknubisa/jxcore-binary-packaging", "max_stars_repo_stars_event_min_datetime": "2015-02-11T04:34:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:21:47.000Z", "max_issues_repo_path": "deps/mozjs/src/tests/ecma_6/TypedObject/method_filter.js", "max_issues_repo_name": "ktrzeciaknubisa/jxcore-binary-packaging", "max_issues_repo_issues_event_min_datetime": "2015-02-11T17:14:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-13T09:58:39.000Z", "max_forks_repo_path": "deps/mozjs/src/tests/ecma_6/TypedObject/method_filter.js", "max_forks_repo_name": "ktrzeciaknubisa/jxcore-binary-packaging", "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:45:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T05:28:05.000Z"}
{"max_stars_count": 2494, "max_issues_count": 685, "max_forks_count": 442, "avg_line_length": 26.5757575758, "max_line_length": 57, "alphanum_fraction": 0.6698973774}
// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
var BUGNUMBER = 939715;
var summary = 'method instance.filter';

/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/
 */

var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var uint8 = TypedObject.uint8;
var uint16 = TypedObject.uint16;
var uint32 = TypedObject.uint32;
var uint8Clamped = TypedObject.uint8Clamped;
var int8 = TypedObject.int8;
var int16 = TypedObject.int16;
var int32 = TypedObject.int32;
var float32 = TypedObject.float32;
var float64 = TypedObject.float64;

var objectType = TypedObject.objectType;

function filterOddsFromVariable() {
  var length = 100;
  var Uint32s = uint32.array();
  var uint32s = new Uint32s(100);
  for (var i = 0; i < length; i++)
    uint32s[i] = i;

  var odds = uint32s.filter(i => (i % 2) != 0);
  assertEq(true, objectType(odds) == Uint32s);
  assertEq(true, Uint32s.variable);
  assertEq(50, odds.length);
  for (var i = 0, j = 1; j < length; i++, j += 2)
    assertEq(odds[i], j);
}

function filterOddsFromSized() {
  var length = 100;
  var Uint32s = uint32.array(100);
  var uint32s = new Uint32s();
  for (var i = 0; i < length; i++)
    uint32s[i] = i;

  var odds = uint32s.filter(i => (i % 2) != 0);
  assertEq(true, objectType(odds) == Uint32s.unsized);
  assertEq(true, objectType(odds).variable);
  assertEq(50, odds.length);
  for (var i = 0, j = 1; j < length; i++, j += 2)
    assertEq(odds[i], j);
}

function runTests() {
    print(BUGNUMBER + ": " + summary);

    filterOddsFromVariable();
    filterOddsFromSized();

    if (typeof reportCompare === "function")
        reportCompare(true, true);
    print("Tests complete");
}

runTests();
