Commit graph

11 commits

Author SHA1 Message Date
davidot
9d05ca7b20 LibJS: Don't assume a this argument for function.prototype.bind
Assuming we had at least one argument meant that the ...arg count would
underflow causing the bound function to have length 0 instead of the
given length when binding with no arguments.
2022-08-17 23:56:24 +01:00
Linus Groh
849495915b LibJS: Make Function.prototype a callable function object
20.2.3 Properties of the Function Prototype Object
https://tc39.es/ecma262/#sec-properties-of-the-function-prototype-object

The Function prototype object:
- is itself a built-in function object.
2022-08-14 00:44:27 +01:00
Linus Groh
e657e88ed6 LibJS: Add [[InitialName]] and use it in Function.prototype.toString() 2022-02-20 23:21:40 +00:00
Luke Wilde
1bfbc0b6af LibJS: Don't coerce this value to an object in Function.prototype.call 2022-02-10 08:45:03 +00:00
Luke Wilde
12231068bd LibJS: Don't coerce this value to an object in Function.prototype.apply 2022-02-10 08:45:03 +00:00
Linus Groh
898ad7c682 LibJS: Implement Function.prototype.bind() according to the spec :^) 2022-02-09 23:31:34 +00:00
Linus Groh
7d521b7c7c LibJS: Implement Function.prototype.toString() according to the spec
That's an old yak :^)
No, past me, AST nodes do not need to learn to stringify themselves.
This is now massively simplified by using the [[SourceText]] internal
slot.

Also updates a bunch of tests that are incorrect due to the old
implementation not being spec compliant, and add plenty more.
2022-01-19 20:33:08 +00:00
Linus Groh
e8519156bc LibJS: Implement create_dynamic_function() according to the spec
The three major changes are:

- Parsing parameters, the function body, and then the full assembled
  function source all separately. This is required by the spec, as
  function parameters and body must be valid each on their own, which
  cannot be guaranteed if we only ever parse the full function.
- Returning an ECMAScriptFunctionObject instead of a FunctionExpression
  that needs to be evaluated separately. This vastly simplifies the
  {Async,AsyncGenerator,Generator,}Function constructor implementations.
  Drop '_node' from the function name accordingly.
- The prototype is now determined via GetPrototypeFromConstructor and
  passed to OrdinaryFunctionCreate.
2022-01-16 01:54:48 +01:00
Timothy Flynn
76589d6728 LibJS: Change wording of ErrorType::NotA to be independent of context
Currently, we have NotA and NotAn, to be used dependent on whether the
following word begins with a vowel or not. To avoid this, change the
wording on NotA to be independent of this context.
2021-09-12 00:16:39 +02:00
Linus Groh
202f855055 LibJS: Change non-ScriptFunction source string to "[native code]"
https://tc39.es/ecma262/#sec-function.prototype.tostring - this is how
the spec wants us to do it. :^)

Also change the function name behaviour to only provide a name for
NativeFunctions, which matches other engines - presumably to not expose
Proxy objects, and to prevent "function bound foo() { [native code] }".
2021-03-14 19:22:16 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00