mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-19 15:43:20 +00:00

Before this change, we were going through the chain of base classes for each IDL interface object and having them set the prototype to their prototype. Instead of doing that, reorder things so that we set the right prototype immediately in Foo::initialize(), and then don't bother in all the base class overrides. This knocks off a ~1% profile item on Speedometer 3.
48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibJS/Runtime/Realm.h>
|
|
#include <LibJS/Runtime/VM.h>
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
#include <LibWeb/Bindings/ModulePrototype.h>
|
|
#include <LibWeb/WebAssembly/Module.h>
|
|
#include <LibWeb/WebAssembly/WebAssembly.h>
|
|
#include <LibWeb/WebIDL/AbstractOperations.h>
|
|
#include <LibWeb/WebIDL/Buffers.h>
|
|
|
|
namespace Web::WebAssembly {
|
|
|
|
GC_DEFINE_ALLOCATOR(Module);
|
|
|
|
WebIDL::ExceptionOr<GC::Ref<Module>> Module::construct_impl(JS::Realm& realm, GC::Root<WebIDL::BufferSource>& bytes)
|
|
{
|
|
auto& vm = realm.vm();
|
|
|
|
auto stable_bytes_or_error = WebIDL::get_buffer_source_copy(bytes->raw_object());
|
|
if (stable_bytes_or_error.is_error()) {
|
|
VERIFY(stable_bytes_or_error.error().code() == ENOMEM);
|
|
return vm.throw_completion<JS::InternalError>(vm.error_message(JS::VM::ErrorMessage::OutOfMemory));
|
|
}
|
|
auto stable_bytes = stable_bytes_or_error.release_value();
|
|
|
|
auto compiled_module = TRY(Detail::compile_a_webassembly_module(vm, move(stable_bytes)));
|
|
return realm.create<Module>(realm, move(compiled_module));
|
|
}
|
|
|
|
Module::Module(JS::Realm& realm, NonnullRefPtr<Detail::CompiledWebAssemblyModule> compiled_module)
|
|
: Bindings::PlatformObject(realm)
|
|
, m_compiled_module(move(compiled_module))
|
|
{
|
|
}
|
|
|
|
void Module::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE_WITH_CUSTOM_NAME(Module, WebAssembly.Module);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
}
|