MCPcopy Create free account
hub / github.com/NativeScript/android / Ctor

Method Ctor

test-app/runtime/src/main/cpp/URLPatternImpl.cpp:351–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349
350
351void URLPatternImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
352 auto isolate = args.GetIsolate();
353
354 if(args.Length() == 0){
355 auto thiz = args.This();
356 auto init = ada::url_pattern_init{};
357 auto url_pattern = ada::parse_url_pattern<v8_regex_provider>(std::move(init));
358 if (!url_pattern) {
359 isolate->ThrowException(
360 v8::Exception::TypeError(
361 ArgConverter::ConvertToV8String(isolate,
362 "Failed to construct URLPattern")));
363 return;
364 }
365
366 auto patternImpl = new URLPatternImpl(std::move(*url_pattern));
367
368 thiz->SetAlignedPointerInInternalField(0, patternImpl);
369
370 patternImpl->BindFinalizer(isolate, thiz);
371
372 args.GetReturnValue().Set(thiz);
373
374 return;
375 }
376
377 auto baseOrOptions = args[1];
378 auto opts = args[2];
379 auto context = isolate->GetCurrentContext();
380
381 std::optional<ada::url_pattern_init> init{};
382 std::optional<std::string> input{};
383 std::optional<std::string> base_url{};
384 std::optional<ada::url_pattern_options> options{};
385
386 if (args[0]->IsString()) {
387 auto inputValue = ArgConverter::ConvertToString(
388 args[0]->ToString(context).ToLocalChecked());
389
390 input = inputValue;
391 } else if (args[0]->IsObject()) {
392 auto parsed = ParseInput(isolate, args[0]);
393 if (parsed) {
394 init = std::move(*parsed);
395 }
396 } else {
397 isolate->ThrowException(
398 v8::Exception::TypeError(ArgConverter::ConvertToV8String(isolate,
399 "Input must be an object or a string")));
400 return;
401 }
402
403 if (!baseOrOptions.IsEmpty()) {
404 if (baseOrOptions->IsString()) {
405 auto baseValue = ArgConverter::ConvertToString(
406 baseOrOptions->ToString(context).ToLocalChecked());
407 base_url = baseValue;
408 } else if (baseOrOptions->IsObject()) {

Callers

nothing calls this directly

Calls 15

ThisMethod · 0.80
GetReturnValueMethod · 0.80
IsStringMethod · 0.80
ToLocalCheckedMethod · 0.80
ToLocalMethod · 0.80
BooleanValueMethod · 0.80
valueMethod · 0.80
GetIsolateMethod · 0.45
LengthMethod · 0.45
BindFinalizerMethod · 0.45
SetMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected