1 /*
2 * Copyright (c) 2022-2024 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/async_generator_helper.h"
17 #include "ecmascript/builtins/builtins_promise.h"
18 #include "ecmascript/interpreter/interpreter.h"
19 #include "ecmascript/js_async_generator_object.h"
20
21 namespace panda::ecmascript {
22 using BuiltinsPromise = builtins::BuiltinsPromise;
Next(JSThread * thread,const JSHandle<GeneratorContext> & genContext,JSTaggedValue value)23 JSTaggedValue AsyncGeneratorHelper::Next(JSThread *thread, const JSHandle<GeneratorContext> &genContext,
24 JSTaggedValue value)
25 {
26 JSHandle<JSAsyncGeneratorObject> genObject(thread, genContext->GetGeneratorObject());
27 genObject->SetResumeResult(thread, value);
28 genObject->SetResumeMode(AsyncGeneratorResumeMode::NEXT);
29
30 EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext);
31 return JSTaggedValue::Undefined();
32 }
33
Throw(JSThread * thread,const JSHandle<GeneratorContext> & genContext,const JSHandle<CompletionRecord> completionRecord)34 JSTaggedValue AsyncGeneratorHelper::Throw(JSThread *thread, const JSHandle<GeneratorContext> &genContext,
35 const JSHandle<CompletionRecord> completionRecord)
36 {
37 JSHandle<JSAsyncGeneratorObject> genObject(thread, genContext->GetGeneratorObject());
38 genObject->SetResumeResult(thread, completionRecord->GetValue());
39 genObject->SetResumeMode(AsyncGeneratorResumeMode::THROW);
40
41 EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext);
42 return JSTaggedValue::Undefined();
43 }
44
Return(JSThread * thread,const JSHandle<GeneratorContext> & genContext,const JSHandle<CompletionRecord> completionRecord)45 JSTaggedValue AsyncGeneratorHelper::Return(JSThread *thread, const JSHandle<GeneratorContext> &genContext,
46 const JSHandle<CompletionRecord> completionRecord)
47 {
48 JSHandle<JSAsyncGeneratorObject> genObject(thread, genContext->GetGeneratorObject());
49 genObject->SetResumeResult(thread, completionRecord->GetValue());
50 genObject->SetResumeMode(AsyncGeneratorResumeMode::RETURN);
51
52 EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext);
53 return JSTaggedValue::Undefined();
54 }
55 } // namespace panda::ecmascript
56