Skip to content

Instantly share code, notes, and snippets.

@evilpie
Created April 24, 2016 10:48
Show Gist options
  • Save evilpie/d02f4b7c20ca2c393b88c64d7ce76c44 to your computer and use it in GitHub Desktop.
Save evilpie/d02f4b7c20ca2c393b88c64d7ce76c44 to your computer and use it in GitHub Desktop.
  1. Assert: length is an integer Number ≥ 0.
  2. If length is -0, let length be +0.
  3. Let isArray be ? IsArray(originalArray).
  4. If isArray is false, return ? ArrayCreate(length).
  5. Let C be ? Get(originalArray, "constructor").
  6. If IsConstructor(C) is true, then
    1. Let thisRealm be the current Realm Record.
    2. Let realmC be ? GetFunctionRealm(C).
    3. If thisRealm and realmC are not the same Realm Record, then
      1. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, let C be undefined.
  7. If Type(C) is Object, then
    1. Let C be ? Get(C, @@species).
    2. If C is null, let C be undefined.
  8. If C is undefined, return ? ArrayCreate(length).
  9. If IsConstructor(C) is false, throw a TypeError exception.
  10. Return ? Construct(C, « length »).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment