mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:17:45 +00:00
LibJS: Move has_constructor() from NativeFunction to FunctionObject
At a later point this will indicate whether some FunctionObject "has a [[Construct]] internal method" (separate from the current FunctionObject call() / construct()), to help with a more spec-compliant implementation of [[Call]] and [[Construct]]. This means that it is no longer relevant to just NativeFunction.
This commit is contained in:
parent
e14f420a44
commit
38157a6093
7 changed files with 16 additions and 11 deletions
|
@ -237,14 +237,16 @@ FunctionObject const& Value::as_function() const
|
|||
// 7.2.4 IsConstructor ( argument ), https://tc39.es/ecma262/#sec-isconstructor
|
||||
bool Value::is_constructor() const
|
||||
{
|
||||
// 1. If Type(argument) is not Object, return false.
|
||||
if (!is_function())
|
||||
return false;
|
||||
if (is<NativeFunction>(as_object()))
|
||||
return static_cast<const NativeFunction&>(as_object()).has_constructor();
|
||||
if (is<BoundFunction>(as_object()))
|
||||
return Value(&static_cast<const BoundFunction&>(as_object()).bound_target_function()).is_constructor();
|
||||
// ECMAScriptFunctionObject
|
||||
return true;
|
||||
|
||||
// 2. If argument has a [[Construct]] internal method, return true.
|
||||
if (as_function().has_constructor())
|
||||
return true;
|
||||
|
||||
// 3. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 7.2.8 IsRegExp ( argument ), https://tc39.es/ecma262/#sec-isregexp
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue