diff --git a/ecmascript/napi/test/jsnapi_sample.cpp b/ecmascript/napi/test/jsnapi_sample.cpp index e173266df6820ac3f77f770e4591fed51e538f0b..1036cab3441da4bf4dae07968e87025f7cf8867e 100644 --- a/ecmascript/napi/test/jsnapi_sample.cpp +++ b/ecmascript/napi/test/jsnapi_sample.cpp @@ -841,6 +841,26 @@ HWTEST_F_L0(JSNApiSampleTest, sample_demo4_function_test_1) GTEST_LOG_(INFO) << "sample_demo4_function_test_1 =========================================="; } +/* demo4 无参无返回值的函数的调用。 ts: + * function FuncTest(): void { + * console.log("func test log ..."); + * } + * FuncTest(); + */ +HWTEST_F_L0(JSNApiSampleTest, sample_demo4_function_test_1_with_context) +{ + LocalScope scope(vm_); + + Local context = JSNApiHelper::ToLocal(JSHandle(thread_->GetGlobalEnv())); + Local funcTest = FunctionRef::New(vm_, context, + [](JsiRuntimeCallInfo *runtimeInfo) -> Local { + EcmaVM *vm = runtimeInfo->GetVM(); + LocalScope scope(vm); + return JSValueRef::Undefined(vm); + }); + ASSERT_TRUE(funcTest->IsFunction(vm_)); +} + /* demo4 有参有返回值的函数的调用。 ts: * function Add(x: number, y: number): number { * return x + y; @@ -2230,6 +2250,28 @@ HWTEST_F_L0(JSNApiSampleTest, sample_BufferWithBuffer_New_GetBuffer) GTEST_LOG_(INFO) << "sample_bufferWithBuffer_getBuffer : " << bufferObj->GetBuffer(vm_); } +HWTEST_F_L0(JSNApiSampleTest, sample_BufferWithBuffer_New_GetBuffer_With_Context) +{ + static bool isFree = false; + struct Data { + int32_t length; + }; + const int32_t length = 5; // buffer length = 5 + Data *data = new Data(); + data->length = length; + NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void { + delete[] reinterpret_cast(buffer); + Data *currentData = reinterpret_cast(data); + delete currentData; + isFree = true; + }; + LocalScope scope(vm_); + uint8_t *buffer = new uint8_t[length](); + Local context = JSNApiHelper::ToLocal(JSHandle(thread_->GetGlobalEnv())); + Local bufferObj = BufferRef::New(vm_, context, buffer, length, deleter, data); + ASSERT_TRUE(bufferObj->IsBuffer(vm_)); +} + /* domo8 异步操作。 ts: * new Promise(function (resolve, reject) { * var a = 0; diff --git a/ecmascript/napi/test/jsnapi_second_tests.cpp b/ecmascript/napi/test/jsnapi_second_tests.cpp index 3e2e589e2ab0791ff69c12201bc193601db03d4a..aaa0a076184931f806ab5c6fb31df65c74bc7fbb 100644 --- a/ecmascript/napi/test/jsnapi_second_tests.cpp +++ b/ecmascript/napi/test/jsnapi_second_tests.cpp @@ -2075,4 +2075,38 @@ HWTEST_F_L0(JSNApiTests, NewConcurrentClassFunctionWithNameCase1) } } } + +/** + * @tc.number: ffi_interface_api_141 + * @tc.name: IsBuffer + * @tc.desc: Construct a BufferRef function to determine whether it is a Buffer + * @tc.type: FUNC + * @tc.require: parameter + */ +HWTEST_F_L0(JSNApiTests, IsBufferWithContext) +{ + LocalScope scope(vm_); + const int32_t length = 15; + Local context = JSNApiHelper::ToLocal(JSHandle(thread_->GetGlobalEnv())); + Local buffer = BufferRef::New(vm_, context, length); + ASSERT_TRUE(buffer->IsBuffer(vm_)); +} + +/** + * @tc.number: ffi_interface_api_142 + * @tc.name: NewClassFunction + * @tc.desc:Check if the function created through the NewClassFunction method meets the specifications of the class + * constructor, and obtain and verify the properties of the function. + * @tc.type: FUNC + * @tc.require: parameter + */ +HWTEST_F_L0(JSNApiTests, NewClassFunctionWithContext) +{ + LocalScope scope(vm_); + Local context = JSNApiHelper::ToLocal(JSHandle(thread_->GetGlobalEnv())); + Local cls = FunctionRef::NewClassFunction(vm_, context, FunctionCallback, nullptr, nullptr); + + JSHandle obj = JSNApiHelper::ToJSHandle(Local(cls)); + ASSERT_TRUE(obj->IsClassConstructor()); +} } // namespace panda::test