MCPcopy Create free account
hub / github.com/Snapchat/Valdi / jsArrayToValue

Function jsArrayToValue

valdi/src/valdi/runtime/JavaScript/JavaScriptUtils.cpp:492–519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

490}
491
492Value jsArrayToValue(IJavaScriptContext& jsContext,
493 const JSValue& jsValue,
494 const ReferenceInfoBuilder& referenceInfoBuilder,
495 JSExceptionTracker& exceptionTracker) {
496 auto arrayLength = jsArrayGetLength(jsContext, jsValue, exceptionTracker);
497 if (!exceptionTracker) {
498 return Value::undefined();
499 }
500
501 auto array = Valdi::ValueArray::make(arrayLength);
502
503 for (size_t i = 0; i < arrayLength; i++) {
504 auto propertyValue = jsContext.getObjectPropertyForIndex(jsValue, i, exceptionTracker);
505 if (!exceptionTracker) {
506 return Value::undefined();
507 }
508
509 auto convertedValue =
510 jsValueToValue(jsContext, propertyValue.get(), referenceInfoBuilder.withArrayIndex(i), exceptionTracker);
511 if (!exceptionTracker) {
512 return Value::undefined();
513 }
514
515 array->emplace(i, std::move(convertedValue));
516 }
517
518 return Value(array);
519}
520
521STRING_CONST(refKey, "$ref");
522

Callers 1

jsValueToValueFunction · 0.85

Calls 7

jsArrayGetLengthFunction · 0.85
jsValueToValueFunction · 0.85
withArrayIndexMethod · 0.80
getMethod · 0.65
ValueClass · 0.50
emplaceMethod · 0.45

Tested by

no test coverage detected