MCPcopy Create free account
hub / github.com/awslabs/llrt / from_value

Method from_value

modules/llrt_fetch/src/headers.rs:356–447  ·  view source on GitHub ↗
(ctx: &Ctx<'js>, value: Value<'js>, guard: HeadersGuard)

Source from the content-addressed store, hash-verified

354 }
355
356 pub fn from_http_headers(header_map: &HeaderMap, guard: HeadersGuard) -> Result<Self> {
357 let mut headers = Vec::with_capacity(header_map.keys_len());
358 for (n, v) in header_map.iter() {
359 headers.push((
360 n.as_str().into(),
361 String::from_utf8_lossy(v.as_bytes()).into(),
362 ));
363 }
364 Ok(Self { headers, guard })
365 }
366
367 pub fn from_value<'js>(ctx: &Ctx<'js>, value: Value<'js>, guard: HeadersGuard) -> Result<Self> {
368 if value.is_array() {
369 let array = unsafe { value.into_array().unwrap_unchecked() };
370 return Self::from_array(ctx, array, guard);
371 }
372
373 if let Some(obj) = value.as_object() {
374 if obj
375 .get::<_, Value>(Symbol::iterator(ctx.clone()))?
376 .is_function()
377 {
378 let array: Array = BasePrimordials::get(ctx)?
379 .function_array_from
380 .call((value,))?;
381 return Self::from_array(ctx, array, guard);
382 } else {
383 // WebIDL record conversion: keys via Reflect.ownKeys (preserves
384 // Symbols, unlike rquickjs's Atom-based iterator which stringifies
385 // them), then per-key gopd → enumerable check → get. Ordering
386 // matters for Proxy traps (WPT headers-record.any.js).
387 let (get_own_property_desc_fn, own_keys_fn) = {
388 let primordials = BasePrimordials::get(ctx)?;
389 let get_own_property_desc_fn =
390 &primordials.function_get_own_property_descriptor;
391 let own_keys_fn = &primordials.function_reflect_own_keys;
392 (get_own_property_desc_fn.clone(), own_keys_fn.clone())
393 };
394
395 let keys: Array = own_keys_fn.call((obj.clone(),))?;
396
397 let mut headers: Vec<(ImmutableString, ImmutableString)> =
398 Vec::with_capacity(keys.len());
399 for i in 0..keys.len() {
400 let key_val: Value = keys.get(i)?;
401 let desc: Value =
402 get_own_property_desc_fn.call((obj.clone(), key_val.clone()))?;
403 let Some(desc) = desc.as_object() else {
404 continue;
405 };
406 if !desc
407 .get::<_, bool>(PredefinedAtom::Enumerable)
408 .unwrap_or(false)
409 {
410 continue;
411 }
412 if key_val.is_symbol() {
413 return Err(Exception::throw_type(

Callers

nothing calls this directly

Calls 15

getFunction · 0.85
is_http_header_nameFunction · 0.85
coerce_to_stringFunction · 0.85
is_http_header_valueFunction · 0.85
as_objectMethod · 0.80
pushMethod · 0.80
cloneMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected