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

Method newFunction

valdi/src/valdi/quickjs/QuickJSJavaScriptContext.cpp:375–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373 auto guard = _threadAccessChecker.guard();
374 JSAtom atom = JS_NewAtomLen(_context, str.data(), str.size());
375 return Valdi::JSPropertyNameRef(this, toValdiJSPropertyName(atom), true);
376}
377
378Valdi::StringBox QuickJSJavaScriptContext::propertyNameToString(const Valdi::JSPropertyName& propertyName) {
379 auto guard = _threadAccessChecker.guard();
380 const auto* cString = JS_AtomToCString(_context, fromValdiJSPropertyName(propertyName));
381 if (cString == nullptr) {
382 return Valdi::StringBox();
383 }
384
385 auto convertedString = Valdi::StringCache::makeStringFromCLiteral(cString);
386
387 JS_FreeCString(_context, cString);
388
389 return convertedString;
390}
391
392Valdi::JSValueRef QuickJSJavaScriptContext::newObject(Valdi::JSExceptionTracker& exceptionTracker) {
393 auto guard = _threadAccessChecker.guard();
394 return checkCallAndGetValue(exceptionTracker, JS_NewObject(_context));
395}
396
397Valdi::JSValueRef QuickJSJavaScriptContext::newFunction(const Valdi::Ref<Valdi::JSFunction>& callable,
398 Valdi::JSExceptionTracker& exceptionTracker) {
399 auto guard = _threadAccessChecker.guard();
400 // TODO(simon): Use functionName
401
402 auto functionObject =
403 checkCallAndGetValue(exceptionTracker, JS_NewObjectProtoClass(_context, _functionPrototype, _functionClassID));
404 if (!exceptionTracker) {
405 return Valdi::JSValueRef();
406 }
407
408 setObjectCallable(fromValdiJSValue(functionObject.get()), callable);
409

Callers

nothing calls this directly

Calls 8

setObjectCallableFunction · 0.85
JS_DupValueFunction · 0.85
guardMethod · 0.80
fromValdiJSValueFunction · 0.70
getMethod · 0.65
isEmptyMethod · 0.45
getNameMethod · 0.45
toStringViewMethod · 0.45

Tested by

no test coverage detected