• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ecmascript/js_api/js_api_plain_array.h"
17 #include "ecmascript/containers/containers_private.h"
18 #include "ecmascript/ecma_string.h"
19 #include "ecmascript/ecma_vm.h"
20 #include "ecmascript/global_env.h"
21 #include "ecmascript/js_api/js_api_plain_array_iterator.h"
22 #include "ecmascript/js_function.h"
23 #include "ecmascript/js_handle.h"
24 #include "ecmascript/js_iterator.h"
25 #include "ecmascript/js_object-inl.h"
26 #include "ecmascript/js_tagged_value.h"
27 #include "ecmascript/object_factory.h"
28 #include "ecmascript/tests/ecma_test_common.h"
29 
30 using namespace panda;
31 
32 using namespace panda::ecmascript;
33 
34 namespace panda::test {
35 class JSAPIPlainArrayIteratorTest : public BaseTestWithScope<false> {
36 protected:
CreatePlainArray()37     JSAPIPlainArray *CreatePlainArray()
38     {
39         return EcmaContainerCommon::CreatePlainArray(thread);
40     }
41 };
42 
43 /**
44  * @tc.name: Next
45  * @tc.desc: test special return of Next, including throw exception
46  * @tc.type: FUNC
47  * @tc.require:
48  */
HWTEST_F_L0(JSAPIPlainArrayIteratorTest,SpecailReturnOfNextCreatePlainArrayIterator)49 HWTEST_F_L0(JSAPIPlainArrayIteratorTest, SpecailReturnOfNextCreatePlainArrayIterator)
50 {
51     JSHandle<JSAPIPlainArray> jsPlainArray(thread, CreatePlainArray());
52     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
53     JSHandle<JSAPIPlainArrayIterator> plainArrayIterator = factory->NewJSAPIPlainArrayIterator(
54         jsPlainArray, IterationKind::KEY);
55     plainArrayIterator->SetIteratedPlainArray(thread, JSTaggedValue::Undefined());
56 
57     // test Next exception
58     {
59         auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
60         ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
61         ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined());
62 
63         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
64         JSTaggedValue result = JSAPIPlainArrayIterator::Next(ecmaRuntimeCallInfo);
65         TestHelper::TearDownFrame(thread, prev);
66         EXPECT_EQ(result, JSTaggedValue::Exception());
67         EXPECT_EXCEPTION();
68     }
69 }
70 } // namespace panda::test
71