| 101 | } |
| 102 | |
| 103 | fn arraybuffer_inspect<'js>(ctx: Ctx<'js>, this: This<Object<'js>>) -> Result<Object<'js>> { |
| 104 | let primordials = BasePrimordials::get(&ctx)?; |
| 105 | let obj = Object::new(ctx.clone())?; |
| 106 | |
| 107 | let byte_length: usize = this.get("byteLength")?; |
| 108 | let uint8_view: Object = primordials |
| 109 | .constructor_uint8array |
| 110 | .construct((this.0.clone(),))?; |
| 111 | |
| 112 | let mut bytes = String::from("<"); |
| 113 | for i in 0..byte_length.min(8) { |
| 114 | if i > 0 { |
| 115 | bytes.push(' '); |
| 116 | } |
| 117 | let byte: u8 = uint8_view.get(i as u32)?; |
| 118 | bytes.push_str(&format!("{:02x}", byte)); |
| 119 | } |
| 120 | bytes.push('>'); |
| 121 | |
| 122 | obj.set("uint8Contents", bytes)?; |
| 123 | obj.set("byteLength", byte_length)?; |
| 124 | Ok(obj) |
| 125 | } |