Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built-in function %ThrowTypeError% is incorrectly recognized as a constructor #903

Closed
gibson042 opened this issue Apr 27, 2022 · 1 comment
Labels
confirmed issue reported has been reproduced fixed - please verify Issue has been fixed. Please verify and close.

Comments

@gibson042
Copy link

Environment: XS 11.6.0 32 4

Description

Steps to Reproduce

(function() {
  "use strict";

  const constructibles = [];
  if (isConstructible(Object.getOwnPropertyDescriptor(Function.prototype, "caller").get)) {
    constructibles.push(`Function.prototype "caller" getter`);
  }
  if (isConstructible(Object.getOwnPropertyDescriptor(Function.prototype, "arguments").get)) {
    constructibles.push(`Function.prototype "arguments" getter`);
  }
  if (isConstructible(Object.getOwnPropertyDescriptor(arguments, "callee").get)) {
    constructibles.push(`arguments "callee" getter`);
  }

  return constructibles;

  function isConstructible(fn) {
    try {
      Reflect.construct(function(){}, [], fn);
      return true;
    } catch (err) {
      return false;
    }
  }
})();

// => [`Function.prototype "caller" getter`, `Function.prototype "arguments" getter`, `arguments "callee" getter`]

Expected behavior
Output should be an empty array.

Other information
Per https://tc39.es/ecma262/#sec-built-in-function-objects , "Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function." There is no such specification at https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-%throwtypeerror% , so the %ThrowTypeError% built-in function should not have a [[Construct]] method and attempts to construct with it such as in the above code should fail with a TypeError exception per https://tc39.es/ecma262/multipage/reflection.html#sec-reflect.construct .

@phoddie phoddie added the confirmed issue reported has been reproduced label Apr 27, 2022
@phoddie
Copy link
Collaborator

phoddie commented Apr 27, 2022

Thank you for the report. This one has an easy fix (don't set XS_CAN_CONSTRUCT_FLAG on %ThrowTypeError%. That will be in our next SDK update.

mkellner pushed a commit that referenced this issue May 2, 2022
@phoddie phoddie added the fixed - please verify Issue has been fixed. Please verify and close. label May 3, 2022
@phoddie phoddie closed this as completed May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed issue reported has been reproduced fixed - please verify Issue has been fixed. Please verify and close.
Projects
None yet
Development

No branches or pull requests

2 participants