mirror of
https://github.com/openai/codex.git
synced 2026-08-23 13:09:46 +00:00
Prune unused code-mode globals (#20542)
Hide Atomics, SharedArrayBuffer, and WebAssembly from the code-mode runtime since the harness does not expose worker support or need those APIs.
This commit is contained in:
@@ -12,11 +12,10 @@ use super::callbacks::yield_control_callback;
|
|||||||
|
|
||||||
pub(super) fn install_globals(scope: &mut v8::PinScope<'_, '_>) -> Result<(), String> {
|
pub(super) fn install_globals(scope: &mut v8::PinScope<'_, '_>) -> Result<(), String> {
|
||||||
let global = scope.get_current_context().global(scope);
|
let global = scope.get_current_context().global(scope);
|
||||||
let console = v8::String::new(scope, "console")
|
delete_global(scope, global, "console")?;
|
||||||
.ok_or_else(|| "failed to allocate global `console`".to_string())?;
|
delete_global(scope, global, "Atomics")?;
|
||||||
if global.delete(scope, console.into()) != Some(true) {
|
delete_global(scope, global, "SharedArrayBuffer")?;
|
||||||
return Err("failed to remove global `console`".to_string());
|
delete_global(scope, global, "WebAssembly")?;
|
||||||
}
|
|
||||||
|
|
||||||
let tools = build_tools_object(scope)?;
|
let tools = build_tools_object(scope)?;
|
||||||
let all_tools = build_all_tools_value(scope)?;
|
let all_tools = build_all_tools_value(scope)?;
|
||||||
@@ -142,3 +141,17 @@ fn set_global<'s>(
|
|||||||
Err(format!("failed to set global `{name}`"))
|
Err(format!("failed to set global `{name}`"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn delete_global<'s>(
|
||||||
|
scope: &mut v8::PinScope<'s, '_>,
|
||||||
|
global: v8::Local<'s, v8::Object>,
|
||||||
|
name: &str,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let key = v8::String::new(scope, name)
|
||||||
|
.ok_or_else(|| format!("failed to allocate global `{name}`"))?;
|
||||||
|
if global.delete(scope, key.into()) == Some(true) {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(format!("failed to remove global `{name}`"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2371,7 +2371,6 @@ text(JSON.stringify(Object.getOwnPropertyNames(globalThis).sort()));
|
|||||||
"Array",
|
"Array",
|
||||||
"ArrayBuffer",
|
"ArrayBuffer",
|
||||||
"AsyncDisposableStack",
|
"AsyncDisposableStack",
|
||||||
"Atomics",
|
|
||||||
"BigInt",
|
"BigInt",
|
||||||
"BigInt64Array",
|
"BigInt64Array",
|
||||||
"BigUint64Array",
|
"BigUint64Array",
|
||||||
@@ -2406,7 +2405,6 @@ text(JSON.stringify(Object.getOwnPropertyNames(globalThis).sort()));
|
|||||||
"Reflect",
|
"Reflect",
|
||||||
"RegExp",
|
"RegExp",
|
||||||
"Set",
|
"Set",
|
||||||
"SharedArrayBuffer",
|
|
||||||
"String",
|
"String",
|
||||||
"SuppressedError",
|
"SuppressedError",
|
||||||
"Symbol",
|
"Symbol",
|
||||||
@@ -2421,7 +2419,6 @@ text(JSON.stringify(Object.getOwnPropertyNames(globalThis).sort()));
|
|||||||
"WeakMap",
|
"WeakMap",
|
||||||
"WeakRef",
|
"WeakRef",
|
||||||
"WeakSet",
|
"WeakSet",
|
||||||
"WebAssembly",
|
|
||||||
"__codexContentItems",
|
"__codexContentItems",
|
||||||
"add_content",
|
"add_content",
|
||||||
"decodeURI",
|
"decodeURI",
|
||||||
|
|||||||
Reference in New Issue
Block a user