| 879 | |
| 880 | Valdi::JSValueRef QuickJSJavaScriptContext::getObjectPropertyForIndex(const Valdi::JSValue& object, |
| 881 | size_t index, |
| 882 | Valdi::JSExceptionTracker& exceptionTracker) { |
| 883 | auto guard = _threadAccessChecker.guard(); |
| 884 | return checkCallAndGetValue(exceptionTracker, |
| 885 | JS_GetPropertyUint32(_context, fromValdiJSValue(object), static_cast<uint32_t>(index))); |
| 886 | } |
| 887 | |
| 888 | JSValue QuickJSJavaScriptContext::getConstructorFromObject(const Valdi::JSValue& object, |
| 889 | const std::string_view& propertyName, |
| 890 | Valdi::JSExceptionTracker& exceptionTracker) { |
| 891 | auto value = getObjectProperty(object, propertyName, exceptionTracker); |
| 892 | if (!exceptionTracker) { |
| 893 | return JS_UNDEFINED; |
| 894 | } |
| 895 | auto jsValue = fromValdiJSValue(value.get()); |
| 896 | |
| 897 | if (JS_IsConstructor(_context, jsValue) == 0) { |
| 898 | exceptionTracker.onError(Valdi::Error(STRING_FORMAT("{} is not a constructor", propertyName))); |
| 899 | return JS_UNDEFINED; |
| 900 | } |
| 901 | |
| 902 | value.unsafeReleaseValue(); |
| 903 | |
| 904 | return jsValue; |
| 905 | } |
| 906 | |
| 907 | bool QuickJSJavaScriptContext::hasObjectProperty(const Valdi::JSValue& object, |
| 908 | const Valdi::JSPropertyName& propertyName) { |
| 909 | auto guard = _threadAccessChecker.guard(); |
| 910 | return JS_HasProperty(_context, fromValdiJSValue(object), fromValdiJSPropertyName(propertyName)) != 0; |
| 911 | } |
| 912 | |
| 913 | void QuickJSJavaScriptContext::setObjectProperty(const Valdi::JSValue& object, |
| 914 | const std::string_view& propertyName, |
| 915 | const Valdi::JSValue& propertyValue, |
| 916 | bool enumerable, |
| 917 | Valdi::JSExceptionTracker& exceptionTracker) { |
| 918 | auto guard = _threadAccessChecker.guard(); |
| 919 | // JS_SetProperty() automatically releases the given value. |
| 920 | auto retainedJsValue = JS_DupValue(_context, fromValdiJSValue(propertyValue)); |
| 921 | |
| 922 | if (VALDI_LIKELY(enumerable)) { |
nothing calls this directly
no test coverage detected