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

Method ExtendMethodCallback

test-app/runtime/src/main/cpp/MetadataNode.cpp:1571–1706  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1569}
1570
1571void MetadataNode::ExtendMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
1572 tns::instrumentation::Frame frame;
1573 try {
1574 if (info.IsConstructCall()) {
1575 string exMsg("Can't call 'extend' as constructor");
1576 throw NativeScriptException(exMsg);
1577 }
1578
1579 SET_PROFILER_FRAME();
1580
1581 Local<Object> implementationObject;
1582 Local<String> extendName;
1583 string extendLocation;
1584
1585 auto hasDot = false;
1586 auto isTypeScriptExtend = false;
1587 auto isolate = info.GetIsolate();
1588 if (info.Length() == 2) {
1589 if (info[0].IsEmpty() || !info[0]->IsString()) {
1590 stringstream ss;
1591 ss << "Invalid extend() call. No name for extend specified at location: " << extendLocation.c_str();
1592 string exceptionMessage = ss.str();
1593
1594 throw NativeScriptException(exceptionMessage);
1595 }
1596 if (info[1].IsEmpty() || !info[1]->IsObject()) {
1597 stringstream ss;
1598 ss << "Invalid extend() call. Named extend should be called with second object parameter containing overridden methods at location: " << extendLocation.c_str();
1599 string exceptionMessage = ss.str();
1600
1601 throw NativeScriptException(exceptionMessage);
1602 }
1603 string strName = ArgConverter::ConvertToString(info[0].As<String>());
1604 hasDot = strName.find('.') != string::npos;
1605 } else if (info.Length() == 3) {
1606 auto context = isolate->GetCurrentContext();
1607 if (info[2]->IsBoolean() && info[2]->BooleanValue(isolate)) {
1608 isTypeScriptExtend = true;
1609 }
1610 }
1611
1612 if (hasDot) {
1613 extendName = info[0].As<String>();
1614 implementationObject = info[1].As<Object>();
1615 } else {
1616 auto isValidExtendLocation = GetExtendLocation(isolate, extendLocation, isTypeScriptExtend);
1617 auto validArgs = ValidateExtendArguments(info, isValidExtendLocation, extendLocation, extendName, implementationObject, isTypeScriptExtend);
1618
1619 if (!validArgs) {
1620 return;
1621 }
1622 }
1623
1624 auto node = reinterpret_cast<MetadataNode*>(info.Data().As<External>()->Value());
1625
1626 DEBUG_WRITE("ExtendsCallMethodHandler: called with %s", ArgConverter::ConvertToString(extendName).c_str());
1627
1628 string extendNameAndLocation = extendLocation + ArgConverter::ConvertToString(extendName);

Callers

nothing calls this directly

Calls 15

NewFunction · 0.85
IsConstructCallMethod · 0.80
IsStringMethod · 0.80
BooleanValueMethod · 0.80
GetNodeTypeMethod · 0.80
GetReturnValueMethod · 0.80
ToLocalCheckedMethod · 0.80
GetFunctionMethod · 0.80
GetPrototypeMethod · 0.80
emplaceMethod · 0.80
checkMethod · 0.80

Tested by

no test coverage detected