Truly independent web browser
LibJS: Use the safe executable conversions in the interpreter
Andreas Kling7c357897c115
diff --git a/Libraries/LibJS/Rust/src/interpreter/run.rs b/Libraries/LibJS/Rust/src/interpreter/run.rsindex 1cb27596703..6e81309d5f1 100644--- a/Libraries/LibJS/Rust/src/interpreter/run.rs+++ b/Libraries/LibJS/Rust/src/interpreter/run.rs@@ -77,8 +77,9 @@ impl Vm {self.register_executable_with_debugger(executable);}- // SAFETY: The caller passes a live context and a live executable.- let (context_ref, executable_ref) = unsafe { (context.as_ref(), executable.as_non_null().as_ref()) };+ // SAFETY: The caller passes a live context.+ let context_ref = unsafe { context.as_ref() };+ let executable_ref: &Executable = &executable;let run_executable_depth = self.run_executable_depth().get();let is_outermost_bytecode_execution = run_executable_depth == 0;@@ -87,10 +88,7 @@ impl Vm {// NOTE: This is how we "push" a new execution context onto the VM's// execution context stack.let previous_running_execution_context = self.head.running_execution_context.replace(context.as_ptr());- // SAFETY: An Executable starts with its head.- context_ref- .executable- .set(Some(unsafe { Gc::from_non_null(executable.as_non_null().cast()) }));+ context_ref.executable.set(Some(Executable::head(executable)));assert!(executable_ref.head.registers_and_locals_and_constants_count.get()@@ -608,8 +606,7 @@ impl Vm {// SAFETY: The running context is live until it is deallocated below.let context = unsafe { context_pointer.as_ref() };let executable = context.executable.get().expect("a running frame has an executable");- // SAFETY: Executables start with their head.- let executable = unsafe { executable.as_non_null().cast::<Executable>().as_ref() };+ let executable = Executable::from_head(executable);if let Some(handler) = executable.exception_handlers_for_offset(program_counter) {context.register(register::EXCEPTION).set(exception);context.program_counter.set(handler.handler_offset);diff --git a/Libraries/LibJS/Rust/src/interpreter/slow_paths/bindings.rs b/Libraries/LibJS/Rust/src/interpreter/slow_paths/bindings.rsindex c263b26af84..6b8fe2083ad 100644--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/bindings.rs+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/bindings.rs@@ -239,8 +239,7 @@ fn current_executable(vm: &Vm) -> Gc<Executable> {.executable.get().expect("a running frame has an executable");- // SAFETY: An executable starts with its head, which is all the frame points to.- unsafe { Gc::from_non_null(executable.as_non_null().cast()) }+ Executable::from_head(executable)}/// VM::get_identifier(), copied out of the executable's identifier table.diff --git a/Libraries/LibJS/Rust/src/interpreter/vm.rs b/Libraries/LibJS/Rust/src/interpreter/vm.rsindex f8a877af493..8d274c3b3aa 100644--- a/Libraries/LibJS/Rust/src/interpreter/vm.rs+++ b/Libraries/LibJS/Rust/src/interpreter/vm.rs@@ -1405,8 +1405,7 @@ impl Vm {.executable.get().expect("the running execution context runs an executable");- // SAFETY: An Executable starts with its head.- unsafe { Gc::from_non_null(executable.as_non_null().cast()) }+ Executable::from_head(executable)}pub fn host_ensure_can_add_private_element(&self) -> HostEnsureCanAddPrivateElement {diff --git a/Libraries/LibJS/Rust/src/runtime/value.rs b/Libraries/LibJS/Rust/src/runtime/value.rsindex 8cc0e51f145..33349db3a00 100644--- a/Libraries/LibJS/Rust/src/runtime/value.rs+++ b/Libraries/LibJS/Rust/src/runtime/value.rs@@ -1848,8 +1848,6 @@ pub fn r#in(vm: &Vm, lhs: Value, rhs: Value) -> ThrowCompletionOr<Value> {/// Whether a function is the native function the realm installs as %Function.prototype%[@@hasInstance]. Only/// NativeFunction gives a function a builtin, so the builtin alone identifies it.fn is_ordinary_has_instance_builtin(function: Gc<FunctionObject>) -> bool {- // SAFETY: A Gc points to a live cell, and every function object starts with its FunctionObject.- let function = unsafe { function.as_non_null().as_ref() };function.has_builtin.get() && Builtin::from_u8(function.builtin.get()) == Some(Builtin::OrdinaryHasInstance)}