• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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/builtins/builtins_segmenter.h"
17 #include "ecmascript/builtins/builtins_segments.h"
18 #include "ecmascript/builtins/builtins_segment_iterator.h"
19 
20 #include "ecmascript/global_env.h"
21 #include "ecmascript/js_segmenter.h"
22 #include "ecmascript/tests/test_helper.h"
23 
24 using namespace panda::ecmascript;
25 using namespace panda::ecmascript::builtins;
26 namespace panda::test {
27 class BuiltinsSegmenterTest : public BaseTestWithScope<true> {
28 };
29 
JSSegmenterCreateWithLocaleTest(JSThread * thread,JSHandle<JSTaggedValue> & locale)30 static JSTaggedValue JSSegmenterCreateWithLocaleTest(JSThread *thread, JSHandle<JSTaggedValue> &locale)
31 {
32     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
33     JSHandle<JSFunction> newTarget(env->GetSegmenterFunction());
34 
35     auto ecmaRuntimeCallInfo =
36         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 6); // 6 means 1 call args
37     ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue());
38     ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined());
39     ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue());
40 
41     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
42     JSTaggedValue result = BuiltinsSegmenter::SegmenterConstructor(ecmaRuntimeCallInfo);
43     EXPECT_TRUE(result.IsJSSegmenter());
44     TestHelper::TearDownFrame(thread, prev);
45     return result;
46 }
47 
JSSegmenterCreateWithLocaleAndOptionsTest(JSThread * thread,JSHandle<JSTaggedValue> & locale,JSHandle<JSTaggedValue> & granularity)48 static JSTaggedValue JSSegmenterCreateWithLocaleAndOptionsTest(JSThread *thread, JSHandle<JSTaggedValue> &locale,
49                                                                JSHandle<JSTaggedValue> &granularity)
50 {
51     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
52     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
53     JSHandle<JSFunction> newTarget(env->GetSegmenterFunction());
54     JSHandle<JSTaggedValue> objFun = env->GetObjectFunction();
55 
56     JSHandle<JSTaggedValue> granularityKey = thread->GlobalConstants()->GetHandledGranularityString();
57     JSHandle<JSObject> optionsObj = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(objFun), objFun);
58     JSObject::SetProperty(thread, optionsObj, granularityKey, granularity);
59 
60     auto ecmaRuntimeCallInfo =
61         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 8); // 8 means 2 call args
62     ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue());
63     ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined());
64     ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue());
65     ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue());
66 
67     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
68     JSTaggedValue result = BuiltinsSegmenter::SegmenterConstructor(ecmaRuntimeCallInfo);
69     EXPECT_TRUE(result.IsJSSegmenter());
70     TestHelper::TearDownFrame(thread, prev);
71     return result;
72 }
73 
JSSegmentsCreateTest(JSThread * thread,JSHandle<JSTaggedValue> & locale,JSHandle<JSTaggedValue> & granularity,JSHandle<JSTaggedValue> & stringValue)74 static JSTaggedValue JSSegmentsCreateTest(JSThread *thread, JSHandle<JSTaggedValue> &locale,
75                                           JSHandle<JSTaggedValue> &granularity, JSHandle<JSTaggedValue> &stringValue)
76 {
77     JSHandle<JSSegmenter> jsSegmenter =
78         JSHandle<JSSegmenter>(thread, JSSegmenterCreateWithLocaleAndOptionsTest(thread, locale, granularity));
79     auto ecmaRuntimeCallInfo =
80         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);  // 6 means 1 call args
81     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
82     ecmaRuntimeCallInfo->SetThis(jsSegmenter.GetTaggedValue());
83     ecmaRuntimeCallInfo->SetCallArg(0, stringValue.GetTaggedValue());
84 
85     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
86     JSTaggedValue segments = BuiltinsSegmenter::Segment(ecmaRuntimeCallInfo);
87     EXPECT_TRUE(segments.IsJSSegments());
88     TestHelper::TearDownFrame(thread, prev);
89     return segments;
90 }
91 
92 // new  Intl.Segmenter ( [ locales [ , options ] ] )
HWTEST_F_L0(BuiltinsSegmenterTest,SegmenterConstructor)93 HWTEST_F_L0(BuiltinsSegmenterTest, SegmenterConstructor)
94 {
95     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
96     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
97     JSHandle<JSFunction> newTarget(env->GetSegmenterFunction());
98 
99     JSHandle<JSTaggedValue> localesString(factory->NewFromASCII("en-US"));
100     auto ecmaRuntimeCallInfo =
101         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 6); // 6 means 1 call args
102     ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue());
103     ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined());
104     ecmaRuntimeCallInfo->SetCallArg(0, localesString.GetTaggedValue());
105 
106     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
107     JSTaggedValue result = BuiltinsSegmenter::SegmenterConstructor(ecmaRuntimeCallInfo);
108     TestHelper::TearDownFrame(thread, prev);
109 
110     EXPECT_TRUE(result.IsJSSegmenter());
111 }
112 
113 // Intl.Segmenter.prototype.segment ( string )
HWTEST_F_L0(BuiltinsSegmenterTest,segment)114 HWTEST_F_L0(BuiltinsSegmenterTest, segment)
115 {
116     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
117     JSHandle<JSTaggedValue> locale(factory->NewFromASCII("zh-cn"));
118     JSHandle<JSTaggedValue> granularity(factory->NewFromASCII("word"));
119     JSHandle<JSTaggedValue> stringValue(factory->NewFromUtf8("这句话是中文"));
120     JSHandle<JSSegmenter> jsSegmenter =
121         JSHandle<JSSegmenter>(thread, JSSegmenterCreateWithLocaleAndOptionsTest(thread, locale, granularity));
122     auto ecmaRuntimeCallInfo =
123         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);  // 6 means 1 call args
124     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
125     ecmaRuntimeCallInfo->SetThis(jsSegmenter.GetTaggedValue());
126     ecmaRuntimeCallInfo->SetCallArg(0, stringValue.GetTaggedValue());
127 
128     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
129     JSTaggedValue result = BuiltinsSegmenter::Segment(ecmaRuntimeCallInfo);
130     TestHelper::TearDownFrame(thread, prev);
131     EXPECT_TRUE(result.IsJSSegments());
132 }
133 
134 // SupportedLocalesOf("lookup")
HWTEST_F_L0(BuiltinsSegmenterTest,SupportedLocalesOf)135 HWTEST_F_L0(BuiltinsSegmenterTest, SupportedLocalesOf)
136 {
137     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
138     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
139     JSHandle<JSTaggedValue> objFun = env->GetObjectFunction();
140 
141     JSHandle<JSTaggedValue> localeMatcherKey = thread->GlobalConstants()->GetHandledLocaleMatcherString();
142     JSHandle<JSTaggedValue> localeMatcherValue(factory->NewFromASCII("lookup"));
143     JSHandle<JSObject> optionsObj = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(objFun), objFun);
144     JSObject::SetProperty(thread, optionsObj, localeMatcherKey, localeMatcherValue);
145     JSHandle<JSTaggedValue> locale(factory->NewFromASCII("id-u-co-pinyin-de-ID"));
146 
147     auto ecmaRuntimeCallInfo =
148         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); // 8 means 2 call args
149     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
150     ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined());
151     ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue());
152     ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue());
153 
154     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
155     JSTaggedValue resultArr = BuiltinsSegmenter::SupportedLocalesOf(ecmaRuntimeCallInfo);
156     TestHelper::TearDownFrame(thread, prev);
157 
158     JSHandle<JSArray> resultHandle(thread, resultArr);
159     JSHandle<TaggedArray> elements(thread, resultHandle->GetElements(thread));
160     EXPECT_EQ(elements->GetLength(), 1U);
161     JSHandle<EcmaString> handleEcmaStr(thread, elements->Get(thread, 0));
162     EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str());
163 }
164 
165 // Intl.Segmenter.prototype.resolvedOptions
HWTEST_F_L0(BuiltinsSegmenterTest,ResolvedOptions)166 HWTEST_F_L0(BuiltinsSegmenterTest, ResolvedOptions)
167 {
168     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
169     auto globalConst = thread->GlobalConstants();
170     JSHandle<JSTaggedValue> locale(factory->NewFromASCII("de-DE"));
171     JSHandle<JSSegmenter> jsSegmenter =
172         JSHandle<JSSegmenter>(thread, JSSegmenterCreateWithLocaleTest(thread, locale));
173     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
174     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
175     ecmaRuntimeCallInfo->SetThis(jsSegmenter.GetTaggedValue());
176 
177     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
178     JSTaggedValue result = BuiltinsSegmenter::ResolvedOptions(ecmaRuntimeCallInfo);
179     TestHelper::TearDownFrame(thread, prev);
180 
181     JSHandle<JSTaggedValue> resultObj =
182         JSHandle<JSTaggedValue>(thread, JSTaggedValue(static_cast<JSTaggedType>(result.GetRawData())));
183     // judge whether the properties of the object are the same as those of jsdatetimeformat tag
184     JSHandle<JSTaggedValue> localeKey = globalConst->GetHandledLocaleString();
185     EXPECT_EQ(JSTaggedValue::SameValue(thread,
186         JSObject::GetProperty(thread, resultObj, localeKey).GetValue(), locale), true);
187     JSHandle<JSTaggedValue> granularityKey = globalConst->GetHandledGranularityString();
188     JSHandle<JSTaggedValue> defaultGranularityValue(factory->NewFromASCII("grapheme"));
189     EXPECT_EQ(JSTaggedValue::SameValue(thread,
190         JSObject::GetProperty(thread, resultObj, granularityKey).GetValue(), defaultGranularityValue), true);
191 }
192 
SegmentsPrototypeCommon(JSThread * thread,JSHandle<JSTaggedValue> & result,std::vector<JSHandle<JSTaggedValue>> & values)193 void SegmentsPrototypeCommon(JSThread *thread, JSHandle<JSTaggedValue> &result,
194                              std::vector<JSHandle<JSTaggedValue>> &values)
195 {
196     auto globalConst = thread->GlobalConstants();
197     JSHandle<JSTaggedValue> segmentKey = globalConst->GetHandledSegmentString();
198     JSHandle<JSTaggedValue> indexKey = globalConst->GetHandledIndexString();
199     JSHandle<JSTaggedValue> inputKey = globalConst->GetHandledInputString();
200     JSHandle<JSTaggedValue> isWordLikeKey = globalConst->GetHandledIsWordLikeString();
201     JSHandle<JSTaggedValue> segmentValue(JSObject::GetProperty(thread, result, segmentKey).GetValue());
202     JSHandle<JSTaggedValue> indexValue(JSObject::GetProperty(thread, result, indexKey).GetValue());
203     JSHandle<JSTaggedValue> inputValue(JSObject::GetProperty(thread, result, inputKey).GetValue());
204     JSHandle<JSTaggedValue> isWordLikeValue(JSObject::GetProperty(thread, result, isWordLikeKey).GetValue());
205     values.push_back(segmentValue);
206     values.push_back(indexValue);
207     values.push_back(inputValue);
208     values.push_back(isWordLikeValue);
209 }
210 
211 // %SegmentsPrototype%.containing ( index )
HWTEST_F_L0(BuiltinsSegmenterTest,SegmentsPrototypeContaining_001)212 HWTEST_F_L0(BuiltinsSegmenterTest, SegmentsPrototypeContaining_001)
213 {
214     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
215     JSHandle<JSTaggedValue> locale(factory->NewFromASCII("zh-cn"));
216     JSHandle<JSTaggedValue> granularity(factory->NewFromASCII("sentence"));
217     JSHandle<JSTaggedValue> stringValue(factory->NewFromUtf8("这句话是中文。这句还是中文!"));
218     JSHandle<JSTaggedValue> segments(thread, JSSegmentsCreateTest(thread, locale, granularity, stringValue));
219 
220     std::vector<JSTaggedValue> args{ JSTaggedValue(static_cast<double>(3))};
221     auto ecmaRuntimeCallInfo =
222         TestHelper::CreateEcmaRuntimeCallInfo(thread, args, 6, segments.GetTaggedValue());  // 6 means 1 call args
223 
224     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
225     JSHandle<JSTaggedValue> result(thread, BuiltinsSegments::Containing(ecmaRuntimeCallInfo));
226     TestHelper::TearDownFrame(thread, prev);
227     EXPECT_TRUE(result->IsJSObject());
228     std::vector<JSHandle<JSTaggedValue>> outValues;
229     SegmentsPrototypeCommon(thread, result, outValues);
230 
231     EXPECT_STREQ(EcmaStringAccessor(JSHandle<EcmaString>::Cast(outValues[0])).ToCString(thread).c_str(),
232                  "这句话是中文。");
233     EXPECT_EQ(outValues[1]->GetRawData(), JSTaggedValue(0).GetRawData());   // 1:index value
234     EXPECT_STREQ(
235         EcmaStringAccessor(JSHandle<EcmaString>::Cast(outValues[2])).ToCString(thread).c_str(),  // 2: input value
236         "这句话是中文。这句还是中文!");
237     EXPECT_TRUE(outValues[3]->IsUndefined()); // 2: word link value
238 }
239 
HWTEST_F_L0(BuiltinsSegmenterTest,SegmentsPrototypeContaining_002)240 HWTEST_F_L0(BuiltinsSegmenterTest, SegmentsPrototypeContaining_002)
241 {
242     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
243     JSHandle<JSTaggedValue> locale(factory->NewFromASCII("fr"));
244     JSHandle<JSTaggedValue> granularity(factory->NewFromASCII("word"));
245     JSHandle<JSTaggedValue> stringValue(factory->NewFromUtf8("Que ma joie demeure"));
246     JSHandle<JSTaggedValue> segments(thread, JSSegmentsCreateTest(thread, locale, granularity, stringValue));
247 
248     std::vector<JSTaggedValue> args{ JSTaggedValue(static_cast<double>(10))};
249     auto ecmaRuntimeCallInfo =
250         TestHelper::CreateEcmaRuntimeCallInfo(thread, args, 6, segments.GetTaggedValue());  // 6 means 1 call args
251 
252     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
253     JSHandle<JSTaggedValue> result(thread, BuiltinsSegments::Containing(ecmaRuntimeCallInfo));
254     TestHelper::TearDownFrame(thread, prev);
255     EXPECT_TRUE(result->IsJSObject());
256 
257     std::vector<JSHandle<JSTaggedValue>> outValues;
258     SegmentsPrototypeCommon(thread, result, outValues);
259     EXPECT_STREQ(EcmaStringAccessor(JSHandle<EcmaString>::Cast(outValues[0])).ToCString(thread).c_str(),
260                  "joie");
261     EXPECT_EQ(outValues[1]->GetRawData(), JSTaggedValue(7).GetRawData());
262     EXPECT_STREQ(EcmaStringAccessor(JSHandle<EcmaString>::Cast(outValues[2])).ToCString(thread).c_str(),
263                  "Que ma joie demeure");
264     EXPECT_EQ(outValues[3]->GetRawData(), JSTaggedValue::True().GetRawData());
265 }
266 
HWTEST_F_L0(BuiltinsSegmenterTest,SegmentsPrototypeContaining_003)267 HWTEST_F_L0(BuiltinsSegmenterTest, SegmentsPrototypeContaining_003)
268 {
269     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
270     JSHandle<JSTaggedValue> locale(factory->NewFromASCII("fr"));
271     JSHandle<JSTaggedValue> granularity(factory->NewFromASCII("word"));
272     JSHandle<JSTaggedValue> stringValue(factory->NewFromUtf8("Que ma joie demeure"));
273     JSHandle<JSTaggedValue> segments(thread, JSSegmentsCreateTest(thread, locale, granularity, stringValue));
274 
275     std::vector<JSTaggedValue> args{ JSTaggedValue(static_cast<double>(-10))};
276     auto ecmaRuntimeCallInfo =
277         TestHelper::CreateEcmaRuntimeCallInfo(thread, args, 6, segments.GetTaggedValue());  // 6 means 1 call args
278 
279     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
280     JSHandle<JSTaggedValue> result(thread, BuiltinsSegments::Containing(ecmaRuntimeCallInfo));
281     TestHelper::TearDownFrame(thread, prev);
282     EXPECT_TRUE(result->IsUndefined());
283 }
284 
285 // %SegmentsPrototype% [ @@iterator ] ( )
HWTEST_F_L0(BuiltinsSegmenterTest,GetSegmentIterator)286 HWTEST_F_L0(BuiltinsSegmenterTest, GetSegmentIterator)
287 {
288     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
289     JSHandle<JSTaggedValue> locale(factory->NewFromASCII("fr"));
290     JSHandle<JSTaggedValue> granularity(factory->NewFromASCII("word"));
291     JSHandle<JSTaggedValue> stringValue(factory->NewFromUtf8("Que ma joie demeure"));
292     JSHandle<JSTaggedValue> segments(thread, JSSegmentsCreateTest(thread, locale, granularity, stringValue));
293 
294     auto ecmaRuntimeCallInfo =
295         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);  // 4 means 0 call args
296     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
297     ecmaRuntimeCallInfo->SetThis(segments.GetTaggedValue());
298 
299     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
300     JSTaggedValue result = BuiltinsSegments::GetSegmentIterator(ecmaRuntimeCallInfo);
301     TestHelper::TearDownFrame(thread, prev);
302     EXPECT_TRUE(result.IsJSSegmentIterator());
303 }
304 
305 // %SegmentIteratorPrototype%.next ( )
HWTEST_F_L0(BuiltinsSegmenterTest,SegmentIteratorNext)306 HWTEST_F_L0(BuiltinsSegmenterTest, SegmentIteratorNext)
307 {
308     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
309     JSHandle<JSTaggedValue> locale(factory->NewFromASCII("fr"));
310     JSHandle<JSTaggedValue> granularity(factory->NewFromASCII("sentence"));
311     JSHandle<JSTaggedValue> stringValue(factory->NewFromUtf8("Que ma joie demeure."));
312     JSHandle<JSTaggedValue> segments(thread, JSSegmentsCreateTest(thread, locale, granularity, stringValue));
313 
314     auto ecmaRuntimeCallInfo =
315         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);  // 4 means 0 call args
316     ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined());
317     ecmaRuntimeCallInfo->SetThis(segments.GetTaggedValue());
318 
319     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
320     JSHandle<JSTaggedValue> iterator(thread, BuiltinsSegments::GetSegmentIterator(ecmaRuntimeCallInfo));
321     TestHelper::TearDownFrame(thread, prev);
322     EXPECT_TRUE(iterator->IsJSSegmentIterator());
323 
324     auto ecmaRuntimeCallInfo1 =
325         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);  // 4 means 0 call args
326     ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined());
327     ecmaRuntimeCallInfo1->SetThis(iterator.GetTaggedValue());
328 
329     [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1);
330     JSHandle<JSTaggedValue> result1(thread, BuiltinsSegmentIterator::Next(ecmaRuntimeCallInfo1));
331     TestHelper::TearDownFrame(thread, prev1);
332     EXPECT_TRUE(result1->IsJSObject());
333     auto globalConst = thread->GlobalConstants();
334     JSHandle<JSTaggedValue> valueKey = globalConst->GetHandledValueString();
335     JSHandle<JSTaggedValue> doneKey = globalConst->GetHandledDoneString();
336     JSHandle<JSTaggedValue> value1(JSObject::GetProperty(thread, result1, valueKey).GetValue());
337     JSHandle<JSTaggedValue> done1(JSObject::GetProperty(thread, result1, doneKey).GetValue());
338     EXPECT_TRUE(value1->IsJSObject());
339     JSHandle<JSTaggedValue> segmentKey = globalConst->GetHandledSegmentString();
340     JSHandle<JSTaggedValue> segmentValue(JSObject::GetProperty(thread, value1, segmentKey).GetValue());
341     EXPECT_STREQ(EcmaStringAccessor(JSHandle<EcmaString>::Cast(segmentValue)).ToCString(thread).c_str(),
342                  "Que ma joie demeure.");
343     EXPECT_FALSE(done1->ToBoolean());
344 
345     auto ecmaRuntimeCallInfo2 =
346         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);  // 4 means 0 call args
347     ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined());
348     ecmaRuntimeCallInfo2->SetThis(iterator.GetTaggedValue());
349 
350     [[maybe_unused]] auto prev2 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2);
351     JSHandle<JSTaggedValue> result2(thread, BuiltinsSegmentIterator::Next(ecmaRuntimeCallInfo2));
352     TestHelper::TearDownFrame(thread, prev2);
353     EXPECT_TRUE(result2->IsJSObject());
354     JSHandle<JSTaggedValue> value2(JSObject::GetProperty(thread, result2, valueKey).GetValue());
355     JSHandle<JSTaggedValue> done2(JSObject::GetProperty(thread, result2, doneKey).GetValue());
356     EXPECT_TRUE(value2->IsUndefined());
357     EXPECT_TRUE(done2->ToBoolean());
358 }
359 }
360