Skip to content
Permalink
Browse files

[MERGE #6012 @MikeHolman] Add JsIsCallable API

Merge pull request #6012 from MikeHolman:callable
  • Loading branch information...
MikeHolman committed Mar 12, 2019
2 parents 178f652 + 11b3456 commit 3a9a3d5a535cd23ba708e1fffabebc9963389135
Showing with 31 additions and 6 deletions.
  1. +16 −0 lib/Jsrt/ChakraCore.h
  2. +14 −6 lib/Jsrt/Core/JsrtCore.cpp
  3. +1 −0 lib/Jsrt/JsrtCommonExports.inc
@@ -1202,6 +1202,22 @@ JsGetErrorPrototype(_Out_ JsValueRef * result);
CHAKRA_API
JsGetIteratorPrototype(_Out_ JsValueRef * result);

/// <summary>
/// Returns a value that indicates whether an object is callable.
/// </summary>
/// <remarks>
/// Requires an active script context.
/// </remarks>
/// <param name="object">The object to test.</param>
/// <param name="isConstructor">If the object is callable, <c>true</c>, <c>false</c> otherwise.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsIsCallable(
_In_ JsValueRef object,
_Out_ bool *isCallable);

/// <summary>
/// Returns a value that indicates whether an object is a constructor.
/// </summary>
@@ -1392,17 +1392,25 @@ CHAKRA_API JsAllocRawData(_In_ JsRuntimeHandle runtimeHandle, _In_ size_t sizeIn
});
}

CHAKRA_API JsIsCallable(_In_ JsValueRef object, _Out_ bool *isCallable)
{
return ContextAPINoScriptWrapper_NoRecord([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
VALIDATE_INCOMING_OBJECT(object, scriptContext);
PARAM_NOT_NULL(isCallable);

*isCallable = Js::JavascriptConversion::IsCallable(object);

return JsNoError;
});
}

CHAKRA_API JsIsConstructor(_In_ JsValueRef object, _Out_ bool *isConstructor)
{
return ContextAPIWrapper<JSRT_MAYBE_TRUE>([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode {
PERFORM_JSRT_TTD_RECORD_ACTION_NOT_IMPLEMENTED(scriptContext);
return ContextAPINoScriptWrapper_NoRecord([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
VALIDATE_INCOMING_OBJECT(object, scriptContext);
PARAM_NOT_NULL(isConstructor);

Js::RecyclableObject * instance = Js::VarTo<Js::RecyclableObject>(object);
AssertMsg(scriptContext->GetThreadContext()->IsScriptActive(), "Caller is expected to be under ContextAPIWrapper!");

*isConstructor = Js::JavascriptOperators::IsConstructor(instance);
*isConstructor = Js::JavascriptOperators::IsConstructor(object);

return JsNoError;
});
@@ -136,6 +136,7 @@
JsGetWeakReferenceValue
JsHasOwnProperty
JsHasOwnItem
JsIsCallable
JsIsConstructor
JsObjectDefineProperty
JsObjectDefinePropertyFull

0 comments on commit 3a9a3d5

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.