mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:52:44 +00:00 
			
		
		
		
	 ffad902c07
			
		
	
	
		ffad902c07
		
	
	
	
	
		
			
			Unlike ensure_web_prototype<T>(), the cached version doesn't require the prototype type to be fully formed, so we can use it without including the FooPrototype.h header. It's also a bit less verbose. :^)
		
			
				
	
	
		
			41 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2022, the SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibJS/Runtime/GlobalObject.h>
 | |
| #include <LibWeb/Bindings/NavigatorConstructor.h>
 | |
| #include <LibWeb/Bindings/NavigatorPrototype.h>
 | |
| #include <LibWeb/HTML/Window.h>
 | |
| 
 | |
| namespace Web::Bindings {
 | |
| 
 | |
| NavigatorConstructor::NavigatorConstructor(JS::Realm& realm)
 | |
|     : NativeFunction(*realm.intrinsics().function_prototype())
 | |
| {
 | |
| }
 | |
| 
 | |
| NavigatorConstructor::~NavigatorConstructor() = default;
 | |
| 
 | |
| JS::ThrowCompletionOr<JS::Value> NavigatorConstructor::call()
 | |
| {
 | |
|     return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Navigator");
 | |
| }
 | |
| 
 | |
| JS::ThrowCompletionOr<JS::Object*> NavigatorConstructor::construct(FunctionObject&)
 | |
| {
 | |
|     return vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "Navigator");
 | |
| }
 | |
| 
 | |
| void NavigatorConstructor::initialize(JS::Realm& realm)
 | |
| {
 | |
|     auto& vm = this->vm();
 | |
|     auto& window = verify_cast<HTML::Window>(realm.global_object());
 | |
| 
 | |
|     NativeFunction::initialize(realm);
 | |
|     define_direct_property(vm.names.prototype, &window.cached_web_prototype("Navigator"), 0);
 | |
|     define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
 | |
| }
 | |
| 
 | |
| }
 |