1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

LibJS: Move Object::invoke to Value::invoke and fix it for primitives

This is a tiny difference and only changes anything for primitives in
strict mode. However this is tested in test262 and can be noticed by
overriding toString of primitive values.

This does now require one to wrap an object in a Value to call invoke
but all code using invoke has been migrated.
This commit is contained in:
davidot 2021-08-09 16:45:43 +02:00 committed by Linus Groh
parent 74e6a70958
commit 151447bdf7
12 changed files with 61 additions and 76 deletions

View file

@ -29,6 +29,7 @@
#include <LibJS/Runtime/RegExpObject.h>
#include <LibJS/Runtime/StringObject.h>
#include <LibJS/Runtime/SymbolObject.h>
#include <LibJS/Runtime/VM.h>
#include <LibJS/Runtime/Value.h>
#include <math.h>
@ -1581,4 +1582,19 @@ TriState abstract_relation(GlobalObject& global_object, bool left_first, Value l
return TriState::False;
}
// 7.3.20 Invoke ( V, P [ , argumentsList ] ), https://tc39.es/ecma262/#sec-invoke
Value Value::invoke_internal(GlobalObject& global_object, JS::PropertyName const& property_name, Optional<MarkedValueList> arguments)
{
auto& vm = global_object.vm();
auto property = get(global_object, property_name);
if (vm.exception())
return {};
if (!property.is_function()) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, property.to_string_without_side_effects());
return {};
}
return vm.call(property.as_function(), *this, move(arguments));
}
}