<commit_before>/**
 * Shumway ships with its own version of the AS3 builtin library, which
 * maintains interface compatibility with the stock builtin library, viz. the
 * same members in the same order.
 *
 * Shumway also uses the [native] metadata tag but interprets them
 * differently. Metadata can _only_ be attached to slots. The asc compiler is
 * laughably bad at parsing metadata tags in light of semicolon insertion, so
 * be sure to semicolon-terminate everything.
 *
 * Using [native] on methods
 * ---------------------------
 *
 * The [native] metadata can be attached to methods. The VM ignores them unless
 * the method is also marked as native:
 *
 *   class C {
 *     ...
 *
 *     [native("fooInJS")]
 *     public native function foo();
 *
 *     ...
 *   }
 *
 * This marks the instance method |foo| as the native function |fooInJS|. Note
 * the string inside [native] is _not_ arbitrary JavaScript.
 *
 * The VM keeps an object of exported natives, |natives|. Whenever something
 * via [native] is looked up, it is only looked up in the |natives|
 * object. The above code looks up |natives.fooInJS|.
 *
 * Implementing native methods
 * ---------------------------
 *
 * Native methods may need to do scope lookups in the scope where it is
 * defined in ActionScript. Because of this, all native methods must be
 * implemented as functions that take a scope and returns the actual native
 * function, so the implementation can close over the scope. For the above
 * example,
 *
 *   natives.fooInJS = function fooInJS(scope) {
 *     return function () {
 *       // actual code here
 *     };
 *   };
 *
 * Using [native] on classes
 * ---------------------------
 *
 * Entire classes can be made native by prefixing the class definition with
 * [native]:
 *
 *   [native(cls="CClass")]
 *   class C {
 *     ...
 *
 *     public native function foo(i)
 *
 *     ...
 *   }
 *
 * The cls= syntax is to maintain parity with how it's done in Tamarin, as we
 * run stock player globals but have custom language-level builtin shims
 * (e.g. for Object, Array, etc).
 *
 * This lets the VM automatically resolve native methods that don't have their
 * own [native].
 *
 * For a native class |CClass|, resolution on a method |m| is done as follows.
 *
 *   If |m| is a...
 *
 *     instance method - |CClass.nativeMethods.m|
 *     static method   - |CClass.nativeStatics.m|
 *     getter          - |CClass.nativeMethods["get m"]|
 *     setter          - |CClass.nativeMethods["set m"]|
 *     static getter   - |CClass.nativeStatics["get m"]|
 *     static setter   - |CClass.nativeStatics["set m"]|
 *
 * Implementing native classes
 * ---------------------------
 *
 * Like native methods, native classes also may need to do scope lookups. It
 * might also need to run the ActionScript instance constructor, so native
 * classes are implemented as functions taking a scope, the instance
 * constructor, and the base class, and returns a |Class| object.
 *
 * Classes in ActionScript may be called like functions. For builtin classes,
 * this often is the same as constructing an instance of that class,
 * viz. |Array(0)| is the same as |new Array(0)|. For user-defined classes,
 * this is usually coercion. The |callable| argument in the |Class|
 * constructor, if non-null, must contain |call| and a |apply| properties,
 * which are functions to be used for calling the class as a function.
 *
 * Convenience callables are provided via |Class.passthroughCallable|, which
 * takes a function |f| and uses it as the callable, and
 * |Class.constructingCallable|, which takes a function |instance| and uses it
 * to construct a new instance when the class is called.
 *
 * IMPORTANT! Inheritance must be done _manually_ by calling |extend|. This
 *            _clobbers_ the old instance prototype!
 *
 * For the above example, we would write:
 *
 *   natives.CClass = function CClass(runtime, scope, instance, baseClass) {
 *     function CInstance() {
 *       // If we wanted to call the AS constructor we would do
 *       // |instance.apply(this, arguments)|
 *     }
 *
 *     // Pass no callable for now, in the future we might do coercion.
 *     var c = new Class("C", CInstance);
 *
 *     // Define the "foo" function.
 *     CInstance.prototype.foo = function foo() {
 *       // code for public native function foo
 *     };
 *
 *     // Export everything in CInstance.prototype.
 *     c.nativeMethods = CInstance.prototype;
 *
 *     return c;
 *   };
 */

const natives = (function () {

  function glue(inner, proxy) {
    inner.p = proxy;
    proxy.d = inner;
    return proxy;
  }

  const C = Domain.passthroughCallable;
  const CC = Domain.constructingCallable;

  /**
   * Object.as
   */
  function ObjectClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("Object", Object, C(Object));

    c.nativeMethods = {
      isPrototypeOf: Object.prototype.isPrototypeOf,
      hasOwnProperty: function (name) {
        name = "public$" + name;
        if (this.hasOwnProperty(name)) {
          return true;
        }
        // Object.getPrototypeOf(this) are traits, not the dynamic prototype.
        return Object.getPrototypeOf(this).hasOwnProperty(name);
      },
      propertyIsEnumerable: function (name) {
        return Object.prototype.propertyIsEnumerable.call(this, "public$" + name);
      }
    };
    c.nativeStatics = {
      _setPropertyIsEnumerable: function _setPropertyIsEnumerable(obj, name, isEnum) {
        var prop = "public$" + name;
        var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
        descriptor.enumerable = false;
        Object.defineProperty(obj, prop, descriptor);
      }
    };

    c.dynamicPrototype = Object.prototype;
    c.defaultValue = null;
    return c;
  }

  /**
   * Class.as
   */
  function ClassClass(runtime, scope, instance, baseClass) {
    var c = runtime.domain.system.Class;
    c.prototype.extendBuiltin.call(c, baseClass);
    return c;
  }

  /**
   * Boolean.as
   */
  function BooleanClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("Boolean", Boolean, C(Boolean));
    c.extendBuiltin(baseClass);
    c.nativeMethods = Boolean.prototype;
    c.coerce = Boolean;
    return c;
  }

  /**
   * Function.as
   */
  function FunctionClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("Function", Function, C(Function));
    c.extendBuiltin(baseClass);

    var m = Function.prototype;
    defineNonEnumerableProperty(m, "get prototype", function () { return this.prototype; });
    defineNonEnumerableProperty(m, "set prototype", function (p) { this.prototype = p; });
    defineNonEnumerableProperty(m, "get length", function () {
      // Check if we're getting the length of a trampoline.
      if (this.hasOwnProperty(VM_LENGTH)) {
        return this[VM_LENGTH];
      }
      return this.length;
    });
    c.nativeMethods = m;
    c.isInstance = function (value) {
      return typeof value === "function";
    };

    return c;
  }

  function MethodClosureClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("MethodClosure", runtime.domain.system.MethodClosure);
    c.extendBuiltin(baseClass);
    return c;
  }

  /**
   * String.as
   */
  function StringClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("String", String, C(String));
    c.extendBuiltin(baseClass);

    var m = String.prototype;
    defineNonEnumerableProperty(m, "get length", function () { return this.length; });
    c.nativeMethods = m;
    c.nativeStatics = String;
    c.isInstance = function (value) {
      return typeof value.valueOf() === "string";
    };

    return c;
  }

  /**
   * Array.as
   */
  function ArrayClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("Array", Array, C(Array));
    c.extendBuiltin(baseClass);

    var m = Array.prototype;
    defineNonEnumerableProperty(m, "get length", function() { return this.length; });
    defineNonEnumerableProperty(m, "set length", function(l) { this.length = l; });
    c.nativeMethods = m;

    return c;
  }

  /**
   * Vector.as
   */

  /**
   * Creates a typed Vector class. It steals the Array object from a new global
   * and overrides its GET/SET ACCESSOR methods to do the appropriate coercions.
   * If the |type| argument is undefined it creates the untyped Vector class.
   */
  function createVectorClass(runtime, type, baseClass) {
    var TypedArray = createNewGlobalObject().Array;

    // Breaks semantics with bounds checking for now.
    if (type) {
      const coerce = type.instance;
      var TAp = TypedArray.prototype;
      TAp.indexGet = function (i) { return this[i]; };
      TAp.indexSet = function (i, v) { this[i] = coerce(v); };
    }

    function TypedVector (length, fixed) {
      var array = new TypedArray(length);
      for (var i = 0; i < length; i++) {
        array[i] = type ? type.defaultValue : undefined;
      }
      return array;
    }
    TypedVector.prototype = TypedArray.prototype;
    var name = type ? "Vector$" + type.classInfo.instanceInfo.name.name : "Vector";
    var c = new runtime.domain.system.Class(name, TypedVector, C(TypedVector));
    var m = TypedArray.prototype;

    defineReadOnlyProperty(TypedArray.prototype, "class", c);

    defineNonEnumerableProperty(m, "get fixed", function () { return false; });
    defineNonEnumerableProperty(m, "set fixed", function (v) { });

    defineNonEnumerableProperty(m, "get length", function () { return this.length; });
    defineNonEnumerableProperty(m, "set length", function setLength(length) {
      // TODO: Fill with zeros if we need to.
      this.length = length;
    });

    c.extendBuiltin(baseClass);
    c.nativeMethods = m;
    c.nativeStatics = {};
    c.vectorType = type;
    c.isInstance = function (value) {
      if (value === null || typeof value !== "object") {
        return false;
      }
      if (!this.instance.vectorType && value.class.vectorType) {
        return true;
      }
      return this.instance.prototype.isPrototypeOf(value);
    };

    return c;
  }

  function VectorClass(runtime, scope, instance) {
    return createVectorClass(runtime, undefined);
  }

  function ObjectVectorClass(runtime, scope, instance, baseClass) {
    return createVectorClass(runtime, runtime.domain.getClass("Object"), baseClass);
  }

  function IntVectorClass(runtime, scope, instance, baseClass) {
    return createVectorClass(runtime, runtime.domain.getClass("int"), baseClass);
  }<commit_msg>Update to: Fixing issues in previous commit: "Verifier: deal with action script typed vectors. (7d11efea652b730ee0e56ee37951e15a38c1ee8f)"<commit_after>/**
 * Shumway ships with its own version of the AS3 builtin library, which
 * maintains interface compatibility with the stock builtin library, viz. the
 * same members in the same order.
 *
 * Shumway also uses the [native] metadata tag but interprets them
 * differently. Metadata can _only_ be attached to slots. The asc compiler is
 * laughably bad at parsing metadata tags in light of semicolon insertion, so
 * be sure to semicolon-terminate everything.
 *
 * Using [native] on methods
 * ---------------------------
 *
 * The [native] metadata can be attached to methods. The VM ignores them unless
 * the method is also marked as native:
 *
 *   class C {
 *     ...
 *
 *     [native("fooInJS")]
 *     public native function foo();
 *
 *     ...
 *   }
 *
 * This marks the instance method |foo| as the native function |fooInJS|. Note
 * the string inside [native] is _not_ arbitrary JavaScript.
 *
 * The VM keeps an object of exported natives, |natives|. Whenever something
 * via [native] is looked up, it is only looked up in the |natives|
 * object. The above code looks up |natives.fooInJS|.
 *
 * Implementing native methods
 * ---------------------------
 *
 * Native methods may need to do scope lookups in the scope where it is
 * defined in ActionScript. Because of this, all native methods must be
 * implemented as functions that take a scope and returns the actual native
 * function, so the implementation can close over the scope. For the above
 * example,
 *
 *   natives.fooInJS = function fooInJS(scope) {
 *     return function () {
 *       // actual code here
 *     };
 *   };
 *
 * Using [native] on classes
 * ---------------------------
 *
 * Entire classes can be made native by prefixing the class definition with
 * [native]:
 *
 *   [native(cls="CClass")]
 *   class C {
 *     ...
 *
 *     public native function foo(i)
 *
 *     ...
 *   }
 *
 * The cls= syntax is to maintain parity with how it's done in Tamarin, as we
 * run stock player globals but have custom language-level builtin shims
 * (e.g. for Object, Array, etc).
 *
 * This lets the VM automatically resolve native methods that don't have their
 * own [native].
 *
 * For a native class |CClass|, resolution on a method |m| is done as follows.
 *
 *   If |m| is a...
 *
 *     instance method - |CClass.nativeMethods.m|
 *     static method   - |CClass.nativeStatics.m|
 *     getter          - |CClass.nativeMethods["get m"]|
 *     setter          - |CClass.nativeMethods["set m"]|
 *     static getter   - |CClass.nativeStatics["get m"]|
 *     static setter   - |CClass.nativeStatics["set m"]|
 *
 * Implementing native classes
 * ---------------------------
 *
 * Like native methods, native classes also may need to do scope lookups. It
 * might also need to run the ActionScript instance constructor, so native
 * classes are implemented as functions taking a scope, the instance
 * constructor, and the base class, and returns a |Class| object.
 *
 * Classes in ActionScript may be called like functions. For builtin classes,
 * this often is the same as constructing an instance of that class,
 * viz. |Array(0)| is the same as |new Array(0)|. For user-defined classes,
 * this is usually coercion. The |callable| argument in the |Class|
 * constructor, if non-null, must contain |call| and a |apply| properties,
 * which are functions to be used for calling the class as a function.
 *
 * Convenience callables are provided via |Class.passthroughCallable|, which
 * takes a function |f| and uses it as the callable, and
 * |Class.constructingCallable|, which takes a function |instance| and uses it
 * to construct a new instance when the class is called.
 *
 * IMPORTANT! Inheritance must be done _manually_ by calling |extend|. This
 *            _clobbers_ the old instance prototype!
 *
 * For the above example, we would write:
 *
 *   natives.CClass = function CClass(runtime, scope, instance, baseClass) {
 *     function CInstance() {
 *       // If we wanted to call the AS constructor we would do
 *       // |instance.apply(this, arguments)|
 *     }
 *
 *     // Pass no callable for now, in the future we might do coercion.
 *     var c = new Class("C", CInstance);
 *
 *     // Define the "foo" function.
 *     CInstance.prototype.foo = function foo() {
 *       // code for public native function foo
 *     };
 *
 *     // Export everything in CInstance.prototype.
 *     c.nativeMethods = CInstance.prototype;
 *
 *     return c;
 *   };
 */

const natives = (function () {

  function glue(inner, proxy) {
    inner.p = proxy;
    proxy.d = inner;
    return proxy;
  }

  const C = Domain.passthroughCallable;
  const CC = Domain.constructingCallable;

  /**
   * Object.as
   */
  function ObjectClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("Object", Object, C(Object));

    c.nativeMethods = {
      isPrototypeOf: Object.prototype.isPrototypeOf,
      hasOwnProperty: function (name) {
        name = "public$" + name;
        if (this.hasOwnProperty(name)) {
          return true;
        }
        // Object.getPrototypeOf(this) are traits, not the dynamic prototype.
        return Object.getPrototypeOf(this).hasOwnProperty(name);
      },
      propertyIsEnumerable: function (name) {
        return Object.prototype.propertyIsEnumerable.call(this, "public$" + name);
      }
    };
    c.nativeStatics = {
      _setPropertyIsEnumerable: function _setPropertyIsEnumerable(obj, name, isEnum) {
        var prop = "public$" + name;
        var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
        descriptor.enumerable = false;
        Object.defineProperty(obj, prop, descriptor);
      }
    };

    c.dynamicPrototype = Object.prototype;
    c.defaultValue = null;
    return c;
  }

  /**
   * Class.as
   */
  function ClassClass(runtime, scope, instance, baseClass) {
    var c = runtime.domain.system.Class;
    c.prototype.extendBuiltin.call(c, baseClass);
    return c;
  }

  /**
   * Boolean.as
   */
  function BooleanClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("Boolean", Boolean, C(Boolean));
    c.extendBuiltin(baseClass);
    c.nativeMethods = Boolean.prototype;
    c.coerce = Boolean;
    return c;
  }

  /**
   * Function.as
   */
  function FunctionClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("Function", Function, C(Function));
    c.extendBuiltin(baseClass);

    var m = Function.prototype;
    defineNonEnumerableProperty(m, "get prototype", function () { return this.prototype; });
    defineNonEnumerableProperty(m, "set prototype", function (p) { this.prototype = p; });
    defineNonEnumerableProperty(m, "get length", function () {
      // Check if we're getting the length of a trampoline.
      if (this.hasOwnProperty(VM_LENGTH)) {
        return this[VM_LENGTH];
      }
      return this.length;
    });
    c.nativeMethods = m;
    c.isInstance = function (value) {
      return typeof value === "function";
    };

    return c;
  }

  function MethodClosureClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("MethodClosure", runtime.domain.system.MethodClosure);
    c.extendBuiltin(baseClass);
    return c;
  }

  /**
   * String.as
   */
  function StringClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("String", String, C(String));
    c.extendBuiltin(baseClass);

    var m = String.prototype;
    defineNonEnumerableProperty(m, "get length", function () { return this.length; });
    c.nativeMethods = m;
    c.nativeStatics = String;
    c.isInstance = function (value) {
      return value !== null && value !== undefined && typeof value.valueOf() === "string";
    };

    return c;
  }

  /**
   * Array.as
   */
  function ArrayClass(runtime, scope, instance, baseClass) {
    var c = new runtime.domain.system.Class("Array", Array, C(Array));
    c.extendBuiltin(baseClass);

    var m = Array.prototype;
    defineNonEnumerableProperty(m, "get length", function() { return this.length; });
    defineNonEnumerableProperty(m, "set length", function(l) { this.length = l; });
    c.nativeMethods = m;

    return c;
  }

  /**
   * Vector.as
   */

  /**
   * Creates a typed Vector class. It steals the Array object from a new global
   * and overrides its GET/SET ACCESSOR methods to do the appropriate coercions.
   * If the |type| argument is undefined it creates the untyped Vector class.
   */
  function createVectorClass(runtime, type, baseClass) {
    var TypedArray = createNewGlobalObject().Array;

    // Breaks semantics with bounds checking for now.
    if (type) {
      const coerce = type.instance;
      var TAp = TypedArray.prototype;
      TAp.indexGet = function (i) { return this[i]; };
      TAp.indexSet = function (i, v) { this[i] = coerce(v); };
    }

    function TypedVector (length, fixed) {
      var array = new TypedArray(length);
      for (var i = 0; i < length; i++) {
        array[i] = type ? type.defaultValue : undefined;
      }
      return array;
    }
    TypedVector.prototype = TypedArray.prototype;
    var name = type ? "Vector$" + type.classInfo.instanceInfo.name.name : "Vector";
    var c = new runtime.domain.system.Class(name, TypedVector, C(TypedVector));
    var m = TypedArray.prototype;

    defineReadOnlyProperty(TypedArray.prototype, "class", c);

    defineNonEnumerableProperty(m, "get fixed", function () { return false; });
    defineNonEnumerableProperty(m, "set fixed", function (v) { });

    defineNonEnumerableProperty(m, "get length", function () { return this.length; });
    defineNonEnumerableProperty(m, "set length", function setLength(length) {
      // TODO: Fill with zeros if we need to.
      this.length = length;
    });

    c.extendBuiltin(baseClass);
    c.nativeMethods = m;
    c.nativeStatics = {};
    c.vectorType = type;
    c.isInstance = function (value) {
      if (value === null || typeof value !== "object") {
        return false;
      }
      if (!this.instance.vectorType && value.class.vectorType) {
        return true;
      }
      return this.instance.prototype.isPrototypeOf(value);
    };

    return c;
  }

  function VectorClass(runtime, scope, instance, baseClass) {
    return createVectorClass(runtime, undefined, baseClass);
  }

  function ObjectVectorClass(runtime, scope, instance, baseClass) {
    return createVectorClass(runtime, runtime.domain.getClass("Object"), baseClass);
  }

  function IntVectorClass(runtime, scope, instance, baseClass) {
    return createVectorClass(runtime, runtime.domain.getClass("int"), baseClass);
  }
{'fraction_non_alphanumeric': 0.1215649743828598, 'fraction_numerical': 0.0014438751746623196, 'mean_word_length': 2.9066593886462884, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2713006', 'n_tokens_mistral': 6250, 'n_tokens_neox': 6142, 'n_words': 2018}