oxc-project/oxc · error · napi::Error
ObjectExpected
ObjectExpected
Error message
Expected a RegExp object
What it means
N-API conversion error from JsRegExp::from_napi_value: the incoming JS value was checked with instanceof against the global RegExp constructor and failed, so the value cannot be treated as a RegExp by the binding.
Source
Thrown at crates/oxc_napi/src/js_reg_exp.rs:48
"RegExp"
}
fn value_type() -> napi::ValueType {
napi::ValueType::Object
}
}
impl ValidateNapiValue for JsRegExp {}
impl FromNapiValue for JsRegExp {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> napi::Result<Self> {
let object = Object::from_raw(env, napi_val);
let env = Env::from(env);
let global = env.get_global()?;
let constructor = global.get_named_property::<Function<Unknown, ()>>("RegExp")?;
if !object.instanceof(constructor)? {
return Err(Error::new(Status::ObjectExpected, "Expected a RegExp object"));
}
Ok(Self {
source: object.get_named_property::<String>("source")?,
flags: object.get_named_property::<String>("flags")?,
last_index: object.get_named_property::<u32>("lastIndex").unwrap_or_default(),
})
}
}
impl ToNapiValue for JsRegExp {
unsafe fn to_napi_value(env: sys::napi_env, value: Self) -> napi::Result<sys::napi_value> {
let global = Env::from(env).get_global()?;
let constructor =
global.get_named_property::<Function<FnArgs<(String, String)>, Unknown>>("RegExp")?;
let object = constructor.new_instance(FnArgs::from((value.source, value.flags)))?;
let mut object = Object::from_raw(env, object.raw());
if value.last_index != 0 {View on GitHub (pinned to e1e7af627c)
Solutions
- Pass a RegExp literal (e.g. /abc/) or new RegExp(...) from JS
- Check value instanceof RegExp on the JS side before calling the binding
- Accept a string|RegExp union in the API and construct a RegExp internally
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/oxc_napi/src/js_reg_exp.rs:48 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/788b33bdfd451695.
Report an issue: GitHub.