mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:08:12 +00:00

This will later allow global objects not inheriting from the regular JS::GlobalObject to pull in these functions without having to implement them from scratch. The primary use case here is, again, a wrapper-less HTML::Window in LibWeb :^) Allocating these upfront now allows us to get rid of two hacks: - The GlobalObject assigning Intrinsics private members after finishing its initialization - The GlobalObject defining the parseInt and parseFloat properties of the NumberConstructor object, as they are supposed to be identical with the global functions of the same name
58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibJS/Heap/Heap.h>
|
|
#include <LibJS/Runtime/Environment.h>
|
|
#include <LibJS/Runtime/VM.h>
|
|
|
|
namespace JS {
|
|
|
|
class GlobalObject : public Object {
|
|
JS_OBJECT(GlobalObject, Object);
|
|
|
|
friend class Intrinsics;
|
|
|
|
public:
|
|
explicit GlobalObject(Realm&);
|
|
virtual void initialize(Realm&) override;
|
|
virtual ~GlobalObject() override;
|
|
|
|
private:
|
|
virtual bool is_global_object() const final { return true; }
|
|
|
|
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);
|
|
};
|
|
|
|
template<>
|
|
inline bool Object::fast_is<GlobalObject>() const { return is_global_object(); }
|
|
|
|
template<typename... Args>
|
|
[[nodiscard]] ALWAYS_INLINE ThrowCompletionOr<Value> Value::invoke(VM& vm, PropertyKey const& property_key, Args... args)
|
|
{
|
|
if constexpr (sizeof...(Args) > 0) {
|
|
MarkedVector<Value> arglist { vm.heap() };
|
|
(..., arglist.append(move(args)));
|
|
return invoke_internal(vm, property_key, move(arglist));
|
|
}
|
|
|
|
return invoke_internal(vm, property_key, Optional<MarkedVector<Value>> {});
|
|
}
|
|
|
|
}
|