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

Method loadModule

valdi/src/valdi/runtime/JavaScript/Modules/FileSystemFactory.cpp:18–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18Value FileSystemFactory::loadModule() {
19 Value out;
20
21 auto strongThis = shared_from_this();
22
23 out.setMapValue(
24 "removeSync",
25 Value(makeShared<ValueFunctionWithCallable>([strongThis](const ValueFunctionCallContext& callContext) -> Value {
26 auto pathNameResult = callContext.getParameterAsString(0);
27
28 if (!callContext.getExceptionTracker()) {
29 return Value::undefined();
30 }
31
32 Path const path = Path(pathNameResult.toStringView());
33
34 bool const result = DiskUtils::remove(path);
35 if (!result) {
36 callContext.getExceptionTracker().onError(fmt::format("Could not remove path: '{}'", pathNameResult));
37 return Value::undefined();
38 }
39
40 return Value(result);
41 })));
42
43 out.setMapValue(
44 "createDirectorySync",
45 Value(makeShared<ValueFunctionWithCallable>([strongThis](const ValueFunctionCallContext& callContext) -> Value {
46 auto pathName = callContext.getParameterAsString(0);
47
48 if (!callContext.getExceptionTracker()) {
49 return Value::undefined();
50 }
51
52 auto createIntermediates = callContext.getParameterAsBool(1);
53 if (!callContext.getExceptionTracker()) {
54 callContext.getExceptionTracker().onError(
55 fmt::format("Please set createIntermediates for: '{}'", pathName));
56 return Value::undefined();
57 }
58
59 Path const path = Path(pathName.toStringView());
60
61 bool const result = DiskUtils::makeDirectory(path, createIntermediates);
62 if (!result) {
63 callContext.getExceptionTracker().onError(
64 fmt::format("Could not create directory at path: '{}'", pathName));
65 return Value::undefined();
66 }
67
68 return Value(result);
69 })));
70
71 out.setMapValue(
72 "readFileSync",
73 Value(makeShared<ValueFunctionWithCallable>([strongThis](const ValueFunctionCallContext& callContext) -> Value {
74 auto pathToFile = callContext.getParameterAsString(0);
75

Callers

nothing calls this directly

Calls 15

loadFunction · 0.85
isDirectoryFunction · 0.85
storeFunction · 0.85
currentWorkingDirectoryFunction · 0.85
getParameterMethod · 0.80
getMapValueMethod · 0.80
asStringViewMethod · 0.80
isTypedArrayMethod · 0.80
getInternedStringMethod · 0.80
onErrorMethod · 0.65
toStringMethod · 0.65
ValueClass · 0.50

Tested by

no test coverage detected