Skip to content

Commit 3a9a3d5

Browse files
committed
[MERGE #6012 @MikeHolman] Add JsIsCallable API
Merge pull request #6012 from MikeHolman:callable
2 parents 178f652 + 11b3456 commit 3a9a3d5

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

lib/Jsrt/ChakraCore.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,22 @@ JsGetErrorPrototype(_Out_ JsValueRef * result);
12021202
CHAKRA_API
12031203
JsGetIteratorPrototype(_Out_ JsValueRef * result);
12041204

1205+
/// <summary>
1206+
/// Returns a value that indicates whether an object is callable.
1207+
/// </summary>
1208+
/// <remarks>
1209+
/// Requires an active script context.
1210+
/// </remarks>
1211+
/// <param name="object">The object to test.</param>
1212+
/// <param name="isConstructor">If the object is callable, <c>true</c>, <c>false</c> otherwise.</param>
1213+
/// <returns>
1214+
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
1215+
/// </returns>
1216+
CHAKRA_API
1217+
JsIsCallable(
1218+
_In_ JsValueRef object,
1219+
_Out_ bool *isCallable);
1220+
12051221
/// <summary>
12061222
/// Returns a value that indicates whether an object is a constructor.
12071223
/// </summary>

lib/Jsrt/Core/JsrtCore.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,17 +1392,25 @@ CHAKRA_API JsAllocRawData(_In_ JsRuntimeHandle runtimeHandle, _In_ size_t sizeIn
13921392
});
13931393
}
13941394

1395+
CHAKRA_API JsIsCallable(_In_ JsValueRef object, _Out_ bool *isCallable)
1396+
{
1397+
return ContextAPINoScriptWrapper_NoRecord([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
1398+
VALIDATE_INCOMING_OBJECT(object, scriptContext);
1399+
PARAM_NOT_NULL(isCallable);
1400+
1401+
*isCallable = Js::JavascriptConversion::IsCallable(object);
1402+
1403+
return JsNoError;
1404+
});
1405+
}
1406+
13951407
CHAKRA_API JsIsConstructor(_In_ JsValueRef object, _Out_ bool *isConstructor)
13961408
{
1397-
return ContextAPIWrapper<JSRT_MAYBE_TRUE>([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode {
1398-
PERFORM_JSRT_TTD_RECORD_ACTION_NOT_IMPLEMENTED(scriptContext);
1409+
return ContextAPINoScriptWrapper_NoRecord([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
13991410
VALIDATE_INCOMING_OBJECT(object, scriptContext);
14001411
PARAM_NOT_NULL(isConstructor);
14011412

1402-
Js::RecyclableObject * instance = Js::VarTo<Js::RecyclableObject>(object);
1403-
AssertMsg(scriptContext->GetThreadContext()->IsScriptActive(), "Caller is expected to be under ContextAPIWrapper!");
1404-
1405-
*isConstructor = Js::JavascriptOperators::IsConstructor(instance);
1413+
*isConstructor = Js::JavascriptOperators::IsConstructor(object);
14061414

14071415
return JsNoError;
14081416
});

lib/Jsrt/JsrtCommonExports.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
JsGetWeakReferenceValue
137137
JsHasOwnProperty
138138
JsHasOwnItem
139+
JsIsCallable
139140
JsIsConstructor
140141
JsObjectDefineProperty
141142
JsObjectDefinePropertyFull

0 commit comments

Comments
 (0)