| 153 | } |
| 154 | |
| 155 | void URLSearchParamsImpl::ForEach(const v8::FunctionCallbackInfo<v8::Value> &args) { |
| 156 | URLSearchParamsImpl *ptr = GetPointer(args.This()); |
| 157 | auto isolate = args.GetIsolate(); |
| 158 | auto context = isolate->GetCurrentContext(); |
| 159 | if (ptr == nullptr) { |
| 160 | return; |
| 161 | } |
| 162 | auto callback = args[0].As<v8::Function>(); |
| 163 | auto searchParams = args.This(); |
| 164 | // Use thisArg if provided, otherwise undefined |
| 165 | auto thisArg = args.Length() > 1 ? args[1] : v8::Undefined(isolate).As<v8::Value>(); |
| 166 | // Use get_entries() to correctly handle duplicate keys |
| 167 | auto entries = ptr->GetURLSearchParams()->get_entries(); |
| 168 | while (entries.has_next()) { |
| 169 | auto entry = entries.next(); |
| 170 | if (entry) { |
| 171 | auto& [key, value] = entry.value(); |
| 172 | // Per spec, forEach callback receives (value, key, searchParams) |
| 173 | v8::Local<v8::Value> callbackArgs[] = { |
| 174 | ArgConverter::ConvertToV8String(isolate, value.data()), |
| 175 | ArgConverter::ConvertToV8String(isolate, key.data()), |
| 176 | searchParams, |
| 177 | }; |
| 178 | v8::Local<v8::Value> result; |
| 179 | if (!callback->Call(context, thisArg, 3, callbackArgs).ToLocal(&result)) { |
| 180 | // If the callback throws an exception, stop iteration |
| 181 | return; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void URLSearchParamsImpl::Get(const v8::FunctionCallbackInfo<v8::Value> &args) { |
| 188 | URLSearchParamsImpl *ptr = GetPointer(args.This()); |
nothing calls this directly
no test coverage detected