mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +00:00
LibJS: Do not use the $
special character in file names
The dollar sign is a special character in POSIX shells and in the Ninja build file format. If the file name contains a `$`, something goes wrong in the escaping/unescaping of this symbol, and CMake/GCC/Clang generate invalid dependency files where not all instances of `$` are escaped properly. Because of this, Ninja fails to rebuild `$262Object.cpp` if the headers included by it have changed. Stale `$262Object.cpp.o` files have been the cause of mysterious crashes multiple times which only go away after doing a clean build. Let's prevent these from happening again by removing the `$` from the filename.
This commit is contained in:
parent
2b46e6f664
commit
e64a8751d1
7 changed files with 8 additions and 9 deletions
119
Userland/Libraries/LibJS/Contrib/Test262/262Object.cpp
Normal file
119
Userland/Libraries/LibJS/Contrib/Test262/262Object.cpp
Normal file
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
// NOTE: This file is not named $262Object.cpp because dollar signs in file names cause issues with some build tools.
|
||||
|
||||
#include <AK/TypeCasts.h>
|
||||
#include <LibJS/Bytecode/Interpreter.h>
|
||||
#include <LibJS/Contrib/Test262/262Object.h>
|
||||
#include <LibJS/Contrib/Test262/AgentObject.h>
|
||||
#include <LibJS/Contrib/Test262/GlobalObject.h>
|
||||
#include <LibJS/Contrib/Test262/IsHTMLDDA.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/ArrayBuffer.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Script.h>
|
||||
|
||||
namespace JS::Test262 {
|
||||
|
||||
$262Object::$262Object(Realm& realm)
|
||||
: Object(Object::ConstructWithoutPrototypeTag::Tag, realm)
|
||||
{
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> $262Object::initialize(Realm& realm)
|
||||
{
|
||||
MUST_OR_THROW_OOM(Base::initialize(realm));
|
||||
|
||||
m_agent = MUST_OR_THROW_OOM(vm().heap().allocate<AgentObject>(realm, realm));
|
||||
m_is_htmldda = MUST_OR_THROW_OOM(vm().heap().allocate<IsHTMLDDA>(realm, realm));
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(realm, "clearKeptObjects", clear_kept_objects, 0, attr);
|
||||
define_native_function(realm, "createRealm", create_realm, 0, attr);
|
||||
define_native_function(realm, "detachArrayBuffer", detach_array_buffer, 1, attr);
|
||||
define_native_function(realm, "evalScript", eval_script, 1, attr);
|
||||
|
||||
define_direct_property("agent", m_agent, attr);
|
||||
define_direct_property("gc", realm.global_object().get_without_side_effects("gc"), attr);
|
||||
define_direct_property("global", &realm.global_object(), attr);
|
||||
define_direct_property("IsHTMLDDA", m_is_htmldda, attr);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void $262Object::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_agent);
|
||||
visitor.visit(m_is_htmldda);
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION($262Object::clear_kept_objects)
|
||||
{
|
||||
vm.finish_execution_generation();
|
||||
return js_undefined();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION($262Object::create_realm)
|
||||
{
|
||||
auto realm = MUST_OR_THROW_OOM(Realm::create(vm));
|
||||
auto realm_global_object = vm.heap().allocate_without_realm<GlobalObject>(*realm);
|
||||
VERIFY(realm_global_object);
|
||||
realm->set_global_object(realm_global_object, nullptr);
|
||||
set_default_global_bindings(*realm);
|
||||
MUST_OR_THROW_OOM(realm_global_object->initialize(*realm));
|
||||
return Value(realm_global_object->$262());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION($262Object::detach_array_buffer)
|
||||
{
|
||||
auto array_buffer = vm.argument(0);
|
||||
if (!array_buffer.is_object() || !is<ArrayBuffer>(array_buffer.as_object()))
|
||||
return vm.throw_completion<TypeError>();
|
||||
|
||||
auto& array_buffer_object = static_cast<ArrayBuffer&>(array_buffer.as_object());
|
||||
TRY(JS::detach_array_buffer(vm, array_buffer_object, vm.argument(1)));
|
||||
return js_null();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION($262Object::eval_script)
|
||||
{
|
||||
auto source_text = TRY(vm.argument(0).to_deprecated_string(vm));
|
||||
|
||||
// 1. Let hostDefined be any host-defined values for the provided sourceText (obtained in an implementation dependent manner)
|
||||
|
||||
// 2. Let realm be the current Realm Record.
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 3. Let s be ParseScript(sourceText, realm, hostDefined).
|
||||
auto script_or_error = Script::parse(source_text, realm);
|
||||
|
||||
// 4. If s is a List of errors, then
|
||||
if (script_or_error.is_error()) {
|
||||
// a. Let error be the first element of s.
|
||||
auto& error = script_or_error.error()[0];
|
||||
|
||||
// b. Return Completion { [[Type]]: throw, [[Value]]: error, [[Target]]: empty }.
|
||||
return vm.throw_completion<SyntaxError>(TRY_OR_THROW_OOM(vm, error.to_string()));
|
||||
}
|
||||
|
||||
// 5. Let status be ScriptEvaluation(s).
|
||||
auto status = [&] {
|
||||
if (auto* bytecode_interpreter = vm.bytecode_interpreter_if_exists())
|
||||
return bytecode_interpreter->run(script_or_error.value());
|
||||
else
|
||||
return vm.interpreter().run(script_or_error.value());
|
||||
}();
|
||||
|
||||
// 6. Return Completion(status).
|
||||
return status;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue