mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 02:03:06 -05:00
LibJS: Implement Symbol.hasInstance
This commit is contained in:
parent
dd49ec17a2
commit
b0296735a5
Notes:
sideshowbarker
2024-07-19 04:49:48 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/b0296735a5f Pull-request: https://github.com/SerenityOS/serenity/pull/2770
2 changed files with 13 additions and 0 deletions
|
@ -51,6 +51,7 @@ void FunctionPrototype::initialize(Interpreter& interpreter, GlobalObject& globa
|
|||
define_native_function("bind", bind, 1, attr);
|
||||
define_native_function("call", call, 1, attr);
|
||||
define_native_function("toString", to_string, 0, attr);
|
||||
define_native_function(interpreter.well_known_symbol_has_instance(), symbol_has_instance, 1, 0);
|
||||
define_property("length", Value(0), Attribute::Configurable);
|
||||
define_property("name", js_string(heap(), ""), Attribute::Configurable);
|
||||
}
|
||||
|
@ -167,4 +168,15 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string)
|
|||
return js_string(interpreter, function_source);
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::symbol_has_instance)
|
||||
{
|
||||
auto* this_object = interpreter.this_value(global_object).to_object(interpreter, global_object);
|
||||
if (!this_object)
|
||||
return {};
|
||||
if (!this_object->is_function())
|
||||
return interpreter.throw_exception<TypeError>(ErrorType::NotA, "Function");
|
||||
|
||||
return ordinary_has_instance(interpreter, interpreter.argument(0), this_object);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(bind);
|
||||
JS_DECLARE_NATIVE_FUNCTION(call);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(symbol_has_instance);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue