2020-04-06 09:09:01 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2022-05-05 18:43:51 +00:00
|
|
|
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
2020-04-06 09:09:01 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-06 09:09:01 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-12 19:11:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-05-02 18:43:44 +00:00
|
|
|
#include <LibJS/Heap/Heap.h>
|
2021-07-01 10:24:46 +00:00
|
|
|
#include <LibJS/Runtime/Environment.h>
|
2020-09-27 18:18:30 +00:00
|
|
|
#include <LibJS/Runtime/VM.h>
|
2020-03-12 19:11:35 +00:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2021-06-22 15:16:08 +00:00
|
|
|
class GlobalObject : public Object {
|
|
|
|
JS_OBJECT(GlobalObject, Object);
|
2023-11-19 08:45:05 +00:00
|
|
|
JS_DECLARE_ALLOCATOR(GlobalObject);
|
2020-06-21 13:14:02 +00:00
|
|
|
|
2022-08-28 16:09:31 +00:00
|
|
|
friend class Intrinsics;
|
|
|
|
|
2020-03-12 19:11:35 +00:00
|
|
|
public:
|
2023-08-07 06:41:28 +00:00
|
|
|
virtual void initialize(Realm&) override;
|
2020-03-12 19:11:35 +00:00
|
|
|
virtual ~GlobalObject() override;
|
|
|
|
|
2022-08-28 21:51:28 +00:00
|
|
|
protected:
|
|
|
|
explicit GlobalObject(Realm&);
|
|
|
|
|
2020-03-12 19:11:35 +00:00
|
|
|
private:
|
2021-03-19 10:28:44 +00:00
|
|
|
virtual bool is_global_object() const final { return true; }
|
|
|
|
|
2021-10-29 21:04:01 +00:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(gc);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(is_nan);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(is_finite);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(parse_float);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(parse_int);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(eval);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(encode_uri);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(decode_uri);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(encode_uri_component);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(decode_uri_component);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(escape);
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(unescape);
|
2020-03-12 19:11:35 +00:00
|
|
|
};
|
|
|
|
|
2022-08-28 16:33:01 +00:00
|
|
|
Object& set_default_global_bindings(Realm&);
|
|
|
|
|
2021-03-19 10:28:44 +00:00
|
|
|
template<>
|
|
|
|
inline bool Object::fast_is<GlobalObject>() const { return is_global_object(); }
|
|
|
|
|
2021-08-09 14:45:43 +00:00
|
|
|
template<typename... Args>
|
2022-08-21 13:00:56 +00:00
|
|
|
[[nodiscard]] ALWAYS_INLINE ThrowCompletionOr<Value> Value::invoke(VM& vm, PropertyKey const& property_key, Args... args)
|
2021-08-09 14:45:43 +00:00
|
|
|
{
|
|
|
|
if constexpr (sizeof...(Args) > 0) {
|
2022-08-21 13:00:56 +00:00
|
|
|
MarkedVector<Value> arglist { vm.heap() };
|
2021-08-09 14:45:43 +00:00
|
|
|
(..., arglist.append(move(args)));
|
2022-08-21 13:00:56 +00:00
|
|
|
return invoke_internal(vm, property_key, move(arglist));
|
2021-08-09 14:45:43 +00:00
|
|
|
}
|
|
|
|
|
2022-08-21 13:00:56 +00:00
|
|
|
return invoke_internal(vm, property_key, Optional<MarkedVector<Value>> {});
|
2021-08-09 14:45:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 19:11:35 +00:00
|
|
|
}
|