|
1 | 1 | //-------------------------------------------------------------------------------------------------------
|
2 | 2 | // Copyright (C) Microsoft. All rights reserved.
|
| 3 | +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. |
3 | 4 | // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
|
4 | 5 | //-------------------------------------------------------------------------------------------------------
|
5 | 6 | #include "stdafx.h"
|
@@ -2259,7 +2260,70 @@ namespace JsRTApiTest
|
2259 | 2260 | TEST_CASE("ApiTest_ModuleSuccessTest", "[ApiTest]")
|
2260 | 2261 | {
|
2261 | 2262 | JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, ModuleSuccessTest);
|
| 2263 | + } |
| 2264 | + |
| 2265 | + void JsIsCallableTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime) |
| 2266 | + { |
| 2267 | + JsValueRef callables, callable, index, nonCallables, nonCallable; |
| 2268 | + bool check; |
| 2269 | + |
| 2270 | + REQUIRE(JsRunScript(_u("[function(){},function*(){},async function(){},async function*(){},_=>_,async _=>_]"), |
| 2271 | + JS_SOURCE_CONTEXT_NONE, _u(""), &callables) == JsNoError); |
| 2272 | + |
| 2273 | + for (int i = 0; i < 6; i++) |
| 2274 | + { |
| 2275 | + REQUIRE(JsIntToNumber(i, &index) == JsNoError); |
| 2276 | + REQUIRE(JsGetIndexedProperty(callables, index, &callable) == JsNoError); |
| 2277 | + REQUIRE(JsIsCallable(callable, &check) == JsNoError); |
| 2278 | + CHECK(check); |
| 2279 | + } |
| 2280 | + |
| 2281 | + |
| 2282 | + REQUIRE(JsRunScript(_u("[class{},Math,Reflect,{}]"), JS_SOURCE_CONTEXT_NONE, _u(""), &nonCallables) == JsNoError); |
| 2283 | + |
| 2284 | + for (int i = 0; i < 4; i++) |
| 2285 | + { |
| 2286 | + REQUIRE(JsIntToNumber(i, &index) == JsNoError); |
| 2287 | + REQUIRE(JsGetIndexedProperty(nonCallables, index, &nonCallable) == JsNoError); |
| 2288 | + REQUIRE(JsIsCallable(nonCallable, &check) == JsNoError); |
| 2289 | + CHECK(!check); |
| 2290 | + } |
| 2291 | + } |
| 2292 | + |
| 2293 | + TEST_CASE("ApiTest_JsIsCallableTest", "[ApiTest]") { |
| 2294 | + JsRTApiTest::RunWithAttributes(JsIsCallableTest); |
| 2295 | + } |
| 2296 | + |
| 2297 | + void JsIsConstructorTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime) |
| 2298 | + { |
| 2299 | + JsValueRef constructables, constructable, index, nonConstructables, nonConstructable; |
| 2300 | + bool check; |
| 2301 | + |
| 2302 | + REQUIRE(JsRunScript(_u("[class{},function(){}]"), JS_SOURCE_CONTEXT_NONE, _u(""), &constructables) == JsNoError); |
| 2303 | + |
| 2304 | + for (int i = 0; i < 2; i++) |
| 2305 | + { |
| 2306 | + REQUIRE(JsIntToNumber(i, &index) == JsNoError); |
| 2307 | + REQUIRE(JsGetIndexedProperty(constructables, index, &constructable) == JsNoError); |
| 2308 | + REQUIRE(JsIsConstructor(constructable, &check) == JsNoError); |
| 2309 | + CHECK(check); |
| 2310 | + } |
| 2311 | + |
| 2312 | + |
| 2313 | + REQUIRE(JsRunScript(_u("[Math,Reflect,{},function*(){},async function(){},async function*(){},_=>_,async _=>_]"), |
| 2314 | + JS_SOURCE_CONTEXT_NONE, _u(""), &nonConstructables) == JsNoError); |
| 2315 | + |
| 2316 | + for (int i = 0; i < 8; i++) |
| 2317 | + { |
| 2318 | + REQUIRE(JsIntToNumber(i, &index) == JsNoError); |
| 2319 | + REQUIRE(JsGetIndexedProperty(nonConstructables, index, &nonConstructable) == JsNoError); |
| 2320 | + REQUIRE(JsIsConstructor(nonConstructable, &check) == JsNoError); |
| 2321 | + CHECK(!check); |
| 2322 | + } |
| 2323 | + } |
2262 | 2324 |
|
| 2325 | + TEST_CASE("ApiTest_JsIsConstructorTest", "[ApiTest]") { |
| 2326 | + JsRTApiTest::RunWithAttributes(JsIsConstructorTest); |
2263 | 2327 | }
|
2264 | 2328 |
|
2265 | 2329 | void SetModuleHostInfoTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
|
|
0 commit comments