mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +00:00 
			
		
		
		
	 1e01a85cdf
			
		
	
	
		1e01a85cdf
		
	
	
	
	
		
			
			This commit upstreams most of the C++ bits of the LibJS test262 runner at https://github.com/linusg/libjs-test262/, specifically everything but the main.cpp file serving as the actual executable. Since all of these are just regular JS objects, I opted to put them in LibJS itself, in a new Contrib/ directory like many other projects have one. Other code that can end up there in the future is the runtime for esvu, which might even share some functionality with test262's $262 object. The code has been copied verbatim, and only a small number of changes have been made: - Putting everything into the JS::Test262 namespace - Removing now redundant JS namespace prefixes - Updating includes to use absolute <LibJS/...> paths - Updating the SPDX-License-Identifier comments from MIT to BSD-2-Clause I gained permission to change the license and upstream these changes from all the major contributors to this code: Ali, Andrew, David, Idan. The removal of the code from the source repository is here: https://github.com/linusg/libjs-test262/pull/54 This is only the first step, the goal is to eventually upstream the actual libjs-test262-runner executable and supporting Python scripts into SerenityOS as well.
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <AK/Format.h>
 | |
| #include <LibJS/Contrib/Test262/$262Object.h>
 | |
| #include <LibJS/Contrib/Test262/AgentObject.h>
 | |
| #include <LibJS/Contrib/Test262/GlobalObject.h>
 | |
| #include <LibJS/Heap/Cell.h>
 | |
| #include <LibJS/Runtime/GlobalObject.h>
 | |
| #include <LibJS/Runtime/VM.h>
 | |
| 
 | |
| namespace JS::Test262 {
 | |
| 
 | |
| void GlobalObject::initialize_global_object()
 | |
| {
 | |
|     Base::initialize_global_object();
 | |
| 
 | |
|     m_$262 = vm().heap().allocate<$262Object>(*this, *this);
 | |
| 
 | |
|     // https://github.com/tc39/test262/blob/master/INTERPRETING.md#host-defined-functions
 | |
|     u8 attr = Attribute::Writable | Attribute::Configurable;
 | |
|     define_native_function("print", print, 1, attr);
 | |
|     define_direct_property("$262", m_$262, attr);
 | |
| }
 | |
| 
 | |
| void GlobalObject::visit_edges(Cell::Visitor& visitor)
 | |
| {
 | |
|     Base::visit_edges(visitor);
 | |
|     visitor.visit(m_$262);
 | |
| }
 | |
| 
 | |
| JS_DEFINE_NATIVE_FUNCTION(GlobalObject::print)
 | |
| {
 | |
|     auto string = TRY(vm.argument(0).to_string(global_object));
 | |
|     outln("{}", string);
 | |
|     return js_undefined();
 | |
| }
 | |
| 
 | |
| }
 |