Repository: servo/servo
File: components/script/dom/globalscope.rs (Rust)

Code before:

    fn is_external(&self) -> bool {
        self.external
    }
}

#[expect(unsafe_code)]
fn compile_script(
    cx: SafeJSContext,
    text: &str,
    filename: &str,
    line_number: u32,
    introduction_type: Option<&'static CStr>,
) -> *mut JSScript {
    let mut options = unsafe { CompileOptionsWrapper::new_raw(*cx, filename, line_number) };
    if let Some(introduction_type) = introduction_type {
        options.set_introduction_type(introduction_type);
    }

    debug!("Compiling script");
    unsafe { Compile1(*cx, options.ptr, &mut transform_str_to_source_text(text)) }
}

#[expect(unsafe_code)]
fn evaluate_script(
    cx: SafeJSContext,
    compiled_script: NonNull<JSScript>,
    url: ServoUrl,
    fetch_options: ScriptFetchOptions,
    rval: MutableHandleValue,
) -> bool {
    rooted!(in(*cx) let record = compiled_script.as_ptr());
    rooted!(in(*cx) let mut script_private = UndefinedValue());

    unsafe { JS_GetScriptPrivate(*record, script_private.handle_mut()) };

    // When `ScriptPrivate` for the compiled script is undefined,
    // we need to set it so that it can be used in dynamic import context.
    if script_private.is_undefined() {
        debug!("Set script private for {}", url);
        let module_script_data = Rc::new(ModuleScript::new(
            url,
            fetch_options,
            // We can't initialize an module owner here because
            // the executing context of script might be different
            // from the dynamic import script's executing context.
            None,
        ));

        unsafe {
            SetScriptPrivate(

Review comment (suggestion):
```suggestion
/// <https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation>
#[expect(unsafe_code)]
```

Code after:
    }

    fn is_external(&self) -> bool {
        self.external
    }
}

#[expect(unsafe_code)]
fn compile_script(
    cx: SafeJSContext,
    text: &str,
    filename: &str,
    line_number: u32,
    introduction_type: Option<&'static CStr>,
) -> *mut JSScript {
    let mut options = unsafe { CompileOptionsWrapper::new_raw(*cx, filename, line_number) };
    if let Some(introduction_type) = introduction_type {
        options.set_introduction_type(introduction_type);
    }

    debug!("Compiling script");
    unsafe { Compile1(*cx, options.ptr, &mut transform_str_to_source_text(text)) }
}

/// <https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation>
#[expect(unsafe_code)]
fn evaluate_script(
    cx: SafeJSContext,
    compiled_script: NonNull<JSScript>,
    url: ServoUrl,
    fetch_options: ScriptFetchOptions,
    rval: MutableHandleValue,
) -> bool {
    rooted!(in(*cx) let record = compiled_script.as_ptr());
    rooted!(in(*cx) let mut script_private = UndefinedValue());

    unsafe { JS_GetScriptPrivate(*record, script_private.handle_mut()) };

    // When `ScriptPrivate` for the compiled script is undefined,
    // we need to set it so that it can be used in dynamic import context.
    if script_private.is_undefined() {
        debug!("Set script private for {}", url);
        let module_script_data = Rc::new(ModuleScript::new(
            url,
            fetch_options,
            // We can't initialize an module owner here because
            // the executing context of script might be different
            // from the dynamic import script's executing context.
            None,
        ));