| 895 | |
| 896 | return hermes::vm::Callable::call(handle, *_runtime); |
| 897 | } |
| 898 | |
| 899 | JSValueRef HermesJavaScriptContext::callObjectAsFunction(const JSValue& object, JSFunctionCallContext& callContext) { |
| 900 | hermes::vm::GCScope gcScope(*_runtime); |
| 901 | const auto* hermesValue = toPinnedHermesValue(object); |
| 902 | |
| 903 | if (!hermes::vm::vmisa<hermes::vm::Callable>(*hermesValue)) { |
| 904 | callContext.getExceptionTracker().onError("Value is not a function"); |
| 905 | return newUndefined(); |
| 906 | } |
| 907 | |
| 908 | auto handle = hermes::vm::Handle<hermes::vm::Callable>::vmcast(hermesValue); |
| 909 | |
| 910 | auto thisValue = toHermesValue(callContext.getThisValue()); |
| 911 | hermes::vm::ScopedNativeCallFrame callFrame(*_runtime, |
| 912 | static_cast<uint32_t>(callContext.getParameterSize()), |
| 913 | handle.getHermesValue(), |
| 914 | hermes::vm::HermesValue::encodeUndefinedValue(), |
| 915 | thisValue.isUndefined() ? _runtime->getGlobal().getHermesValue() : |
| 916 | thisValue); |
| 917 | |
| 918 | auto callResult = doCall(callFrame, handle, callContext); |
| 919 | |
| 920 | if (!checkException(callResult.getStatus(), callContext.getExceptionTracker())) { |
| 921 | return newUndefined(); |
| 922 | } |
| 923 | |
| 924 | return toJSValueRef(callResult->get()); |
| 925 | } |
| 926 | |
| 927 | JSValueRef HermesJavaScriptContext::callObjectAsConstructor(const JSValue& object, JSFunctionCallContext& callContext) { |
| 928 | hermes::vm::GCScope gcScope(*_runtime); |
| 929 | const auto* hermesValue = toPinnedHermesValue(object); |
| 930 | |