| 312 | } |
| 313 | |
| 314 | void BuildJS(v8::Isolate *isolate, const v8::Local<v8::Object> &object, |
| 315 | const url_pattern_result &result) { |
| 316 | auto ctx = isolate->GetCurrentContext(); |
| 317 | |
| 318 | auto len = result.inputs.size(); |
| 319 | auto inputs = v8::Array::New(isolate, len); |
| 320 | for (int i = 0; i < len; i++) { |
| 321 | auto item = result.inputs[i]; |
| 322 | |
| 323 | if (std::holds_alternative<std::string_view>(item)) { |
| 324 | auto view = std::get<std::string_view>(item); |
| 325 | if (view.empty()) { |
| 326 | inputs->Set(ctx, i, v8::String::Empty(isolate)); |
| 327 | } else { |
| 328 | inputs->Set(ctx, i, ArgConverter::ConvertToV8String(isolate, view.data(), |
| 329 | view.size())); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | } |
| 334 | |
| 335 | object->Set( |
| 336 | ctx, ArgConverter::ConvertToV8String(isolate, "inputs"), |
| 337 | inputs |
| 338 | ); |
| 339 | |
| 340 | SetComponent(isolate, object, "protocol", result.protocol); |
| 341 | SetComponent(isolate, object, "hash", result.hash); |
| 342 | SetComponent(isolate, object, "hostname", result.hostname); |
| 343 | SetComponent(isolate, object, "username", result.username); |
| 344 | SetComponent(isolate, object, "password", result.password); |
| 345 | SetComponent(isolate, object, "pathname", result.pathname); |
| 346 | SetComponent(isolate, object, "port", result.port); |
| 347 | SetComponent(isolate, object, "search", result.search); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | void URLPatternImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) { |